File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes Jdom namespace issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Jdom namespace issue" Watch "Jdom namespace issue" New topic
Author

Jdom namespace issue

geeta lalchandani
Ranch Hand

Joined: Jun 07, 2005
Posts: 118
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

Joined: Dec 11, 2004
Posts: 13410

This forum is for JSP questions.
I'll move this to our XML forum for you.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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

Joined: Jun 07, 2005
Posts: 118
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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Jdom namespace issue
 
Similar Threads
Oracle BPEL result SOAP message
xPath and namespace problem
Get namespace of root element
ws bb1.1: Explanation needed for examples
ws bb1.1: Explanation needed for examples