aspose file tools*
The moose likes XML and Related Technologies and the fly likes Get namespace of root element Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Get namespace of root element" Watch "Get namespace of root element" New topic
Author

Get namespace of root element

Jeppe Sommer
Ranch Hand

Joined: Jan 07, 2004
Posts: 270
Hi,

I am trying to get the first namespace value (URI) of the root element:
xmlns="http://rep.oio.dk/ubl/xml/schemas/0p71/testpie/"

The XML document starts with:



I wish to print out the value "http://rep.oio.dk/ubl/xml/schemas/0p71/testpie/", but my code below returns null:



Any help would be appreciated.

Thanks in advance.


Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18669
    
    8

Well, first of all, is your parser namespace-aware? By default parsers created by DocumentBuilderFactory (which it looks like you are using that) are not namespace-aware. Check the methods of DocumentBuilderFactory.

Then once you have taken care of that, the method you're looking for is getNamespaceURI().
Jeppe Sommer
Ranch Hand

Joined: Jan 07, 2004
Posts: 270
Paul Clapham wrote:Well, first of all, is your parser namespace-aware? By default parsers created by DocumentBuilderFactory (which it looks like you are using that) are not namespace-aware. Check the methods of DocumentBuilderFactory.

Then once you have taken care of that, the method you're looking for is getNamespaceURI().


Thanks. It works :-)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Get namespace of root element