Jump to content
Sign in to follow this  
RikP

Understanding XML namespaces

Recommended Posts

Hello, I am having difficulty understanding how namespaces work.  To my understanding, the namespace URI is added to an xml document with a qualifier so you can contextualize the content (i.e. differentiate two complex elements with the name "table" that may have different elements and attributes).  I understand that the URI is not looked up, but rather to give the namespace a global unique identifier.  This is where my confusion begins.  Take for instance the following xml:

<?xml version="1.0"?>

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

<xsl:template match="/">
  <html>
  <body>
    <h2>My CD Collection</h2>
    <table border="1">
      <tr bgcolor="#9acd32">
        <th>Title</th>
        <th>Artist</th>
      </tr>
      <xsl:for-each select="catalog/cd">
        <tr>
          <td><xsl:value-of select="title"/></td>
          <td><xsl:value-of select="artist"/></td>
        </tr>
      </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>

</xsl:stylesheet>

</xs:schema>

to my understanding, the elements or attributes prefixed with xsl (xsl:template, xsl:for-each, etc.), the XML parser recognizes to be part of the "http://www.w3.org/1999/XSL/Transform" namespace.  My question is, if the URI is not used to lookup content, how does it check that the elements provided are all (valid) in the xsl prefixed namespace, or does it?  What I do not understand is the following from the XSL Transformation Page, it states the following 

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

To get access to the XSLT elements, attributes and features we must declare the XSLT namespace at the top of the document.

How do we have "access" to elements, attributes, and features if no lookup is done?

For instance, if I added the following element to the xml file:

<xsl:foo>Made up element</xsl:foo>

what happens? I know that foo is not a defined element inside of the xsl namespace, but how does a XML parser know that? 

 

How does the parser know what elements should/could be inside the prefixed namespace?  

 

Thanks in advance!

Edited by RikP
spelling, format

Share this post


Link to post
Share on other sites

I assume that if something understands XSLT, then that definition is built-in to whatever software you're using, and it just checks the namespace identifier to make sure that it's actually XSLT that you're trying to use.  Support for that would be built-in to the software though, it's not going to pull up that human-readable web page and try to get some kind of definition out of it, that URL is for people to read.  This is an example of a DTD which defines a particular schema:

https://www.w3.org/2001/rddl/rddl-xhtml.dtd

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×