Stairway to XML: Level 1 - Introduction to XML

  • Well written, straight to the point..

    Thanks...

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

  • Thank you

    I'm learning something new. today 🙂

  • 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

  • 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

  • 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.

  • 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>

  • Very nice article for beginner.

    Thanks

  • 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")

  • 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.

  • 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

  • Rob:

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

  • Excellent introduction Rob

    - Damian

  • 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 asks, "Can I join you?"
    Ref.: http://tkyte.blogspot.com/2009/02/sql-joke.html

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

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