• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Get namespace of root element

 
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.


 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 270
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 :-)
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic