OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Re: Client recognition of XML Namespace prefixes

[ Lists Home | Date Index | Thread Index ]
  • From: "Clark C. Evans" <cce@clarkevans.com>
  • To: Will Bradley <willbr@microsoft.com>
  • Date: Tue, 05 Dec 2000 21:29:18 -0500 (EST)

>   <tree xmlns:dog="http://dogs.com/some/schema"
>         xmlns:people="http://people.com/some/schema">
>     <dog:name>Fido</dog:name>
>
> When a client application recieves this xml block, and wants to interpret
> it, can it, and should it, make assumptions about the namespace prefix?

The namespace prefix is informational, and thus a
program may make use of the prefix.  However, I would
not make any assumptions about it.  See below.

> How do you find the tag you want within a hierarchy, without knowing what
> prefix its namespace happens to be using.  It seems that there is no way to
> be absolutely sure that if I search for "/root//dog:name", another app would
> not have gone and switched the namespace prefix to "Dog", in which case my
> search would fail due to case sensitivity, but the XML Validator would NOT
> fail, because the grammar is still valid.

The stylesheet below should produce the expected result,
printing out a line for each dog's name found.

<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:foo="http://dogs.com/some/schema" > 
  <xsl:template match="/" >
    <xsl:for-each select="//foo:name" >
      I found a dog, named <xsl:value-of select="." />!
    </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>
  

Note that "foo" is used for the prefix here. XPath expressions
do not match literally on the prefix, internally it is turned
into a QName pair { "http://dogs.com/some/schema", "name" }
and this pair is what is matched.   I don't know DOM 
well enough to describe how it would work for you.
There must be _some_ namespace binding context for
XPath to operate however...

Note that, in XSLT, the prefix is informational, since it 
is used by the XSLT processor to figure-out the appropriate
QNames to look for.  I hope this explains the statement
above... that one can use the prefix, however, this is 
different from making assumptions about it.

Best,

Clark

P.S.  There is an XSL list at mulberrytech.com which may 
be more appropriate for additional XSL questions.







 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS