[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Quiz: how many namespaces are in scope?

  • From: Evan Lenz <evan@evanlenz.net>
  • To: "Costello, Roger L." <costello@mitre.org>
  • Date: Mon, 30 Aug 2010 11:39:46 -0700

Re:  Quiz: how many namespaces are in scope?
Hi Roger,

The only thing I'd change is that it is not illegal to declare the xml 
namespace, provided you use the correct namespace URI. "It MAY, but need 
not, be declared, and MUST NOT be bound to any other namespace name." [1]

In my XPath/XSLT training classes, I like to ask this quiz question: How 
many namespace nodes are in this document? People are usually surprised 
when they hear the answer is (for this case) 21.

Evan

-- 
Evan Lenz
Lenz Consulting Group, Inc.
http://lenzconsulting.com
+1 (360) 297-0087


[1] http://www.w3.org/TR/xml-names/#xmlReserved

Costello, Roger L. wrote:
> Hi Folks,
>
> Consider this XML document:
>
> <?xml version="1.0"?>
> <N1:NumberList xmlns:N1="http://www.example1.org"
>                xmlns:N2=" http://www.example2.org ">
>         <Number>23</Number>
>         <Number>41</Number>
>         <Number>70</Number>
>         <Number>103</Number>
>         <Number>99</Number>
>         <Number>6</Number>
> </N1:NumberList>
>
> For the first child element: 
>
>         <Number>23</Number>
>
> what namespaces are in scope?
>
> I created an XSLT template to output the <Number> element's in-scope namespaces:
>
> -------------------------------------------
> <xsl:template match="*">
>        <xsl:for-each select="namespace::*">
>            <xsl:value-of select="."/></p>
>        </xsl:for-each>
> </xsl:template>
> -------------------------------------------
>
> Here is the output:
>
>       http://www.w3.org/XML/1998/namespace
>  
>       http://www.example1.org
>  
>       http://www.example2.org
>
> There are three (3) in-scope namespaces.
>
> Lesson Learned: Implicit on the root element of every XML document is this namespace declaration:
>
>       <root xmlns:xml="http://www.w3.org/XML/1998/namespace">
>
> NOTE: it is illegal to explicitly declare the xml namespace. The xml namespace is built into every XML application.
>
> Since the xml namespace is implicitly declared in every XML document, you can immediately use the xml:lang attribute and the xml:space attribute, e.g.,
>
> <movie>
> 	<title>The Laughing Cow</title>
> 	<title xml:lang="fr">La Vache Qui Rit</title>
> </movie>
>
> Here is an XSLT template to output the in-scope namespaces and their prefixes:
>
> -------------------------------------------
> <xsl:template match="*">
>         <xsl:for-each select="namespace::*">
>             Namespace in scope = <xsl:value-of select="."/>
>             Namespace prefix = <xsl:value-of select="name(.)"/>          
>         </xsl:for-each>
> </xsl:template>
> -------------------------------------------
>
> Here is the output:
>
>       Namespace in scope = http://www.w3.org/XML/1998/namespace
>       Namespace prefix = xml 
>
>       Namespace in scope = http://www.example1.org
>       Namespace prefix = N1
>
>       Namespace in scope = http://www.example2.org
>       Namespace prefix = N2
>
> QUESTIONS
>
> 1. Have I correctly analyzed the situation (regarding in-scope namespaces)?
>
> 2. What else would you add?
>
> /Roger
>
> _______________________________________________________________________
>
> XML-DEV is a publicly archived, unmoderated list hosted by OASIS
> to support XML implementation and development. To minimize
> spam in the archives, you must subscribe before posting.
>
> [Un]Subscribe/change address: http://www.oasis-open.org/mlmanage/
> Or unsubscribe: xml-dev-unsubscribe@lists.xml.org
> subscribe: xml-dev-subscribe@lists.xml.org
> List archive: http://lists.xml.org/archives/xml-dev/
> List Guidelines: http://www.oasis-open.org/maillists/guidelines.php
>
>   




[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.