• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Jdom namespace issue

 
geeta lalchandani
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I dont know if this is the correct forum. Please do let me know where to post in case it isnt correct.

I have a root element 'myset' and i need to add namespace to it .. like xmlns="http://abc.com", and i have a sub element 'my'. The problem is that, when i add namespace to 'myset', its added to 'my' as well, though the value of the xmlns in 'my' is blank.

The xml structure is as:

<?xml version="1.0" encoding="UTF-8"?>
<myset xmlns="http://www.google.com/schemas/sitemap/0.84">
<my xmlns=""></my>
</myset>

The code is

 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This forum is for JSP questions.
I'll move this to our XML forum for you.
 
Paul Clapham
Sheriff
Pie
Posts: 20978
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is to be expected. You have said that the urlset/myset element is in the default namespace, so you get the default namespace declaration there in the serialized XML document. But you have said that the url/my element is NOT in a namespace. Since elements inherit namespaces from their containing elements, the serializer has to put that empty namespace declaration on the url/my element to prevent the inheritance.

If you want the url/my element to be in the same namespace as the urlset/myset element, then create the two elements in the same way with the same namespace URI.
 
geeta lalchandani
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul. I managed to solve that issue. Now what i want is to generate the xml with these headers, using jdom



I could create the namespace as xsi and add the attribute schemaLocation.BUt jdom doesnt allow the namespace to start with 'xml' so i could not add the xmlns="http://www.google.com/schemas/sitemap/0.84".
How can i do this?
 
Paul Clapham
Sheriff
Pie
Posts: 20978
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by geetu lalchandani:
But jdom doesnt allow the namespace to start with 'xml' so i could not add the xmlns="http://www.google.com/schemas/sitemap/0.84".
How can i do this?
I find that hard to understand, when you posted code earlier in the thread where you did exactly that. But at any rate, in JDOM (I looked it up in the API documentation) the Element object has an addNamespaceDeclaration() method. You need to call that. I will leave it to you to read the documentation for the Namespace class, where it does explain how to create a Namespace object for a default namespace.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic