Connecting Tech Pros Worldwide Help | Site Map
 
 
LinkBack Thread Tools Search this Thread
  #1  
Old November 12th, 2005, 04:38 AM
Steve Terepin
Guest
 
Posts: n/a
Default Finding out the default namespace of an XML document

I'm reading in an XML file with might be in either a 'new' format which
defines a default namespace, like this :

<rootElement xmlns:some-url>
<otherstuff/>
</rootElement>

.... or might be in an older format without a default namespace :

<rootElement>
<differentstuff>
</rootElement>

What's the best way of using an XPathNavigator to find out whether the xmlns
is present ?

Thanks,

Steve


  #2  
Old November 12th, 2005, 04:38 AM
Martin Honnen
Guest
 
Posts: n/a
Default Re: Finding out the default namespace of an XML document



Steve Terepin wrote:
[color=blue]
> I'm reading in an XML file with might be in either a 'new' format which
> defines a default namespace, like this :
>
> <rootElement xmlns:some-url>
> <otherstuff/>
> </rootElement>
>
> ... or might be in an older format without a default namespace :
>
> <rootElement>
> <differentstuff>
> </rootElement>
>
> What's the best way of using an XPathNavigator to find out whether the xmlns
> is present ?[/color]

As for the current node, you can check whether the Prefix property is
empty while the NamespaceUri points to a URL.
You could also try to navigate the namespace nodes with
MoveToFirstNamespace/MoveToNamespace/MoveToNextNamespace.

In general you need to be aware that a default namespace declaration can
occur on any element and not only on the root element.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,248 network members.