Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Jdom namespace issue

 
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

 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • 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.
 
Marshal
Posts: 25682
69
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
Marshal
Posts: 25682
69
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.
 
He repaced his skull with glass. So you can see his brain. Kinda like this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic