• 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

Simple jdom namespace question

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So i cant quite seem to find my misstep here...

XML
<txme:TXM_Envelope xmlns:txme="http://www.<some site>">
<txme:TXM_Header>
</txme:TXM_Header>
</txme:TXM_Envelope>

Java
Namespace ns = Namespace.getNamespace("txme","http://www.<some site>");
Element header = root.getChild("TXM_Header", ns);

and i keep getting null for the element header and i can't quite under stand what i am doing wrong

I thought that by defining the prefix to the txme that i should be able to get the element?

thanks in advance
 
Marshal
Posts: 28177
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
Strangely, all of the examples of namespaces in the JDOM FAQ are of the default namespace. So that doesn't help.

The API documentation says you are supposed to pass the local name to that method, so leaving off the prefix is (probably) the right thing to do.

However from what you've posted there is no evidence that the "root" variable actually refers to the txme:TXM_Envelope element, so perhaps it doesn't.
 
Jesse Reim
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry i left this off

and bis is a bufferedInputStream to the full xml file.

Document sdoc = saxb.build(bis);
Element root = sdoc.getRootElement();

 
Paul Clapham
Marshal
Posts: 28177
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
Have you done any debugging to see what the namespace of the root element is?
 
Jesse Reim
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes and the prefix for the namespace is txme for both the Envlope and the header...
 
Jesse Reim
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I dont know if this matters but both the URI's <somesite> dont actually contain the xsd's...was i too naive to think that didnt matter?
 
Jesse Reim
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So i believe what i am asking is this

Is it possible to use JDOM Document without having access to the schemes that are defined in the first line of the XML file....

can i just clobber them?
 
Paul Clapham
Marshal
Posts: 28177
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
If you aren't validating then you don't need access to the schemas. If you are validating, and you don't have access to them, then validation will fail -- and it sounds like that didn't happen. So I think the schema business is a red herring.

Also the first thing you need to know about namespaces is that it's the namespace URI which defines the namespace, not the prefix. When you try to match a namespaced element, you have to match the namespace URI of the namespace, not the prefix.

So... is the namespace of the root element equal to the namespace which you are using to search for other elements? I'm assuming that JDOM's Namespace object has an equals() method which tells you that.
 
reply
    Bookmark Topic Watch Topic
  • New Topic