permaculture playing cards*
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
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: 18541
    
    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 :-)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Get namespace of root element
 
Similar Threads
Jdom namespace issue
xPath and namespace problem
Couldn't access xhtml table using JDOM XPath
How to resolve namespaces for XPath with JDOM
XSL transformation