Stairway to XML: Level 1 - Introduction to XML

  • H Laforest

    SSC Rookie

    Points: 33

    Well written, straight to the point..

    Thanks...

    Will buy anything, if ever, written by this guy..

  • faqr

    Newbie

    Points: 7

    Thank you

    I'm learning something new. today 🙂

  • John Mitchell-245523

    SSC Guru

    Points: 148258

    Thanks SQLBalls, Jon and ACinKC. That makes it a little clearer. I guess as a beginner I'll understand more as I read more and more of the articles to come.

    John

  • ingvar 47353

    Newbie

    Points: 5

    Attributes versus Elements can easily turn into almost religious discussions.

    But one fundamental difference is the ability for an element to contain other elements. An attribute can't contain another attribute.

    And an element is repeteable inside it's parent. So in this sample you have several person in the people element. But you can only have one id="" per person.

    <Person>

    <Phone type="cell">01234567</Phone>

    <Phone type="home">3456789</Phone>

    etc

    </Person>

    Won't work with attributes.

    <Person phone_mobile="01234567" phone_home="3456789"/>

    Makes it hard to extend for new types of phone-numbers.

    Johan

  • Stephen Hirsch

    SSCommitted

    Points: 1822

    XML started off from SGML as a way to develop authoring languages. For some reason, XML languages are used as databases mostly today. Why that occurred is a long and pointless religious discussion.

    The bottom line is, if you are going to use an XML file as a database, there really is no reason to design a schema that uses elements. Just because you can do something doesn't mean you should.

  • Stan Kulp-439977

    SSCrazy Eights

    Points: 9943

    XML attributes are a legacy from other markup languages. Attributes work well in transformation languages such as HTML or XSL because their tags are actually more akin to commands. Nesting command switches in child elements would make no sense. Placing them inside the tag as attributes makes complete sense. XML, however, is just a container language. It's elements either hold data or they hold other elements that hold data somewhere down the tree. There are no command switches in XML. Arbitrarily placing some data values in elements and other data values in attributes is schizophrenic.

    To be clear, the following two XML statements are equivalent.

    <PARENT>

    <CHILD_01>VALUE_01</CHILD_01>

    <CHILD_02>VALUE_02</CHILD_02>

    </PARENT>

    <PARENT CHILD_01=VALUE_01>

    <CHILD_02>VALUE_02</CHILD_02>

    </PARENT>

    The second style of XML statement (where data that could have been added as a symmetric element has been arbitrarily added as an assymetric attribute) should be avoided.

    When you must deal with XML files that contain attributes, there is a simple solution; convert the attributes to elements.

    The following XSLT stylesheet, courtesy of O'Reilly's CD bookshelfs, does just that for any XML document.

    <?xml version="1.0"?>

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

    <xsl:output method="xml"/>

    <xsl:template match="*">

    <xsl:element name="{name()}">

    <xsl:for-each select="@*">

    <xsl:element name="{name()}">

    <xsl:value-of select="."/>

    </xsl:element>

    </xsl:for-each>

    <xsl:apply-templates select="*|text()"/>

    </xsl:element>

    </xsl:template>

    </xsl:stylesheet>

  • Hardy21

    SSCrazy Eights

    Points: 9708

    Very nice article for beginner.

    Thanks

  • jharvey6 76850

    SSC Enthusiast

    Points: 112

    I have a question which may not be easily answered. But my question is; why does the XML parser throw and error when a Tag has a quote " wthin it instead of the entity equivalent " when a normal quote is allowed in an attribute assignment. (id-"1234")

  • theboyholty

    Ten Centuries

    Points: 1050

    Articles / tutorials on SQL XML are rarely pitched at an appropriate level, but this article was a really good start and I'm looking forward to reading the rest of the series.

  • Thomas Abraham

    SSChampion

    Points: 10761

    Just piling own with my own Thank You. I already knew most of this from osmosis. But, it really helps to have it laid out in an organized manner.

    [font="Verdana"]Please don't go. The drones need you. They look up to you.[/font]
    Connect to me on LinkedIn

  • SQL2219

    Valued Member

    Points: 69

    Rob:

    This is the best introductory article on XML I have ever seen.

  • DamianC

    SSCertifiable

    Points: 7767

    Excellent introduction Rob

    - Damian

  • webrunner

    One Orange Chip

    Points: 29863

    Thanks for this great introductory article! I look forward to the rest of the Stairway.

    Note, I learned this about the beginning question mark for XML documents:

    It's a prolog – see 'The XML Prolog' in XML Syntax Rules at w3schools.com.


    https://stackoverflow.com/questions/39119165/xml-what-does-that-question-mark-mean

    and

    This line is called the XML prolog:
    <?xml version="1.0" encoding="UTF-8"?>
    ...
    Note: The XML prolog does not have a closing tag! This is not an error. The prolog is not a part of the XML document.


    https://www.w3schools.com/xml/xml_syntax.asp

    -------------------
    A SQL query walks into a bar and sees two tables. He walks up to them and says Can I join you?
    Ref.: http://tkyte.blogspot.com/2009/02/sql-joke.html

Viewing 13 posts - 16 through 28 (of 28 total)

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