Stairway to XML: Level 1 - Introduction to XML

  • Comments posted to this topic are about the item Stairway to XML: Level 1 - Introduction to XML

  • XML isn't a language, it's a meta-language:

    http://www.sqlservercentral.com/articles/Miscellaneous/whatisxml/2473

  • <?xml version="1.0" encoding="UTF-8"?>

    <!-- My Comments -->

    <Assessment> " Excellent Job! "</Assessment>

  • This was a fantastic article. Very well laid out and easy to understand. Thanks!

  • Thanks for the beginner's guide, Rob - very much needed in my case! I have one question on this. Are elements and attributes functionally equivalent? For example, does this:

    <People>

    <Person id="1234">

    <FirstName>John</FirstName>

    <LastName>Doe</LastName>

    </Person>

    <Person id="5678">

    <FirstName>Jane</FirstName>

    <LastName>Doe</LastName>

    </Person>

    </People>

    do the same as this?

    <People>

    <Person>

    <id>1234</id>

    <FirstName>John</FirstName>

    <LastName>Doe</LastName>

    </Person>

    <Person>

    <id>5678</id>

    <FirstName>Jane</FirstName>

    <LastName>Doe</LastName>

    </Person>

    </People>

    Thanks

    John

    Edit: changed closing tags for id so they had a "/" in.

  • Hello, thanks for the article, I'm looking forward for the whole serie, seems interesting.

  • Thanks for that, Robert.

    However much I read up about XML, I always gain from reading more, and I always find some gems in your writing on XML

    From a fan.

    Best wishes,
    Phil Factor

  • Very Nice Article, a great introduction to covering the concept and touching all the bases!

  • Great Article.

    I am also interested in John Mitchel's question...

    "Are elements and attributes functionally equivalent? "

    tia,

    Bob

  • (my XML is rusty and I need to brush up, so excuse the lack of detail in the reply).

    At this level it appears that way, but when you get into how to parse and read an XML file then you get the data in a slightly seperate way from an Attribute vs an Element.

    For us SQL folk if you look at the XML of an execution plan, and start getting into X query you'll see that we have to parse a little differently for each.

    In an XML document you can set up XML Indexes in SQL. There are only two types Primary XML Indexes and Secondary (both require a Clustered Index on the base table).

    As an element you wouldn't be able to build an XML index on the ID column, as an attribute you could. There's probably a lot of "It depends" in here as well, again I'm rusty and we probably have some other folks that could explain this a little better.

  • Bob McClellan-320407 (9/20/2012)


    Great Article.

    I am also interested in John Mitchel's question...

    "Are elements and attributes functionally equivalent? "

    tia,

    Bob

    John/Bob, while not an expert, I would have to say no, they are not functionally equivalent. One is creating a descriptor of an element, the other creates an entirely new node and puts a value within that node. This may not be the best example of why they need to be different, but it changes how you go looking, and if a developer was using this data in order to construct web pages, could impact the structure of the page.

    IF OBJECT_ID('tempdb..#xml_temp') IS NOT NULL BEGIN DROP TABLE #xml_temp END

    create table #xml_temp (

    xml_col xml

    )

    insert into #xml_temp values('<People>

    <Person id="1234">

    <FirstName>John</FirstName>

    <LastName>Doe</LastName>

    </Person>

    <Person id="5678">

    <FirstName>Jane</FirstName>

    <LastName>Doe</LastName>

    </Person>

    </People>')

    insert into #xml_temp values('<People>

    <Person>

    <id>1234</id>

    <FirstName>John</FirstName>

    <LastName>Doe</LastName>

    </Person>

    <Person>

    <id>5678</id>

    <FirstName>Jane</FirstName>

    <LastName>Doe</LastName>

    </Person>

    </People>')

    --With query() function

    select xml_col.query('data(/People/Person/@id)') AS attribute from #xml_temp

    select xml_col.query('data(/People/Person/id)') AS nodeValue from #xml_temp

    ---------------------------------------------------------
    How best to post your question[/url]
    How to post performance problems[/url]
    Tally Table:What it is and how it replaces a loop[/url]

    "stewsterl 80804 (10/16/2009)I guess when you stop and try to understand the solution provided you not only learn, but save yourself some headaches when you need to make any slight changes."

  • SQLBalls (9/20/2012)


    (my XML is rusty and I need to brush up, so excuse the lack of detail in the reply).

    At this level it appears that way, but when you get into how to parse and read an XML file then you get the data in a slightly seperate way from an Attribute vs an Element.

    For us SQL folk if you look at the XML of an execution plan, and start getting into X query you'll see that we have to parse a little differently for each.

    In an XML document you can set up XML Indexes in SQL. There are only two types Primary XML Indexes and Secondary (both require a Clustered Index on the base table).

    As an element you wouldn't be able to build an XML index on the ID column, as an attribute you could. There's probably a lot of "It depends" in here as well, again I'm rusty and we probably have some other folks that could explain this a little better.

    good point

    ---------------------------------------------------------
    How best to post your question[/url]
    How to post performance problems[/url]
    Tally Table:What it is and how it replaces a loop[/url]

    "stewsterl 80804 (10/16/2009)I guess when you stop and try to understand the solution provided you not only learn, but save yourself some headaches when you need to make any slight changes."

  • jcrawf02 (9/20/2012)


    Bob McClellan-320407 (9/20/2012)


    Great Article.

    I am also interested in John Mitchel's question...

    "Are elements and attributes functionally equivalent? "

    tia,

    Bob

    John/Bob, while not an expert, I would have to say no, they are not functionally equivalent. One is creating a descriptor of an element, the other creates an entirely new node and puts a value within that node. This may not be the best example of why they need to be different, but it changes how you go looking, and if a developer was using this data in order to construct web pages, could impact the structure of the page.

    IF OBJECT_ID('tempdb..#xml_temp') IS NOT NULL BEGIN DROP TABLE #xml_temp END

    create table #xml_temp (

    xml_col xml

    )

    insert into #xml_temp values('<People>

    <Person id="1234">

    <FirstName>John</FirstName>

    <LastName>Doe</LastName>

    </Person>

    <Person id="5678">

    <FirstName>Jane</FirstName>

    <LastName>Doe</LastName>

    </Person>

    </People>')

    insert into #xml_temp values('<People>

    <Person>

    <id>1234</id>

    <FirstName>John</FirstName>

    <LastName>Doe</LastName>

    </Person>

    <Person>

    <id>5678</id>

    <FirstName>Jane</FirstName>

    <LastName>Doe</LastName>

    </Person>

    </People>')

    --With query() function

    select xml_col.query('data(/People/Person/@id)') AS attribute from #xml_temp

    select xml_col.query('data(/People/Person/id)') AS nodeValue from #xml_temp

    Perfect example Jon! Thanks for the code to play around with

  • Atrributes are data which are important to the parser, while elements are important to the reader. Think of attributes as information about the data in the XML structure, while elements are the data. So if I just read data out of a source, I might have:

    <Customers>

    <Customer CustID="1234"> <!-- This is the identifier for the Customer record I'm describing -->

    <FirstName>Fred</FirstName>

    <LastName>Flintstone</LastName>

    <Address1>...

    </Customer>

    </Customers>

    In the same way CustID might be the PK for my SQL Customer(s) ( 🙂 ) table, and I don't necessarily show it to my users, the attribute is most commonly used in XML documents.

    On the other hand, if I'm passing data to a data sink and want to specify all of the data that the recipient is to process, I might code it like this:

    <Customers>

    <Customer>

    <CustID>1234</CustID> <!-- This is the identifier for the Customer record I'm sending -->

    <FirstName>Fred</FirstName>

    <LastName>Flintstone</LastName>

    <Address1>...

    </Customer>

    </Customers>

    It depends on how I've negotiated with my sender/recipient partners. So the answer is, It Depends...;-)

  • The best basic intro to XML I've seen. Thank you for making it so understandable.

Viewing 15 posts - 1 through 15 (of 27 total)

You must be logged in to reply to this topic. Login to reply