aspose file tools*
The moose likes XML and Related Technologies and the fly likes Blank xmlns  added as attributes when converting from String to XML using Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Blank xmlns  added as attributes when converting from String to XML using Java" Watch "Blank xmlns  added as attributes when converting from String to XML using Java" New topic
Author

Blank xmlns added as attributes when converting from String to XML using Java

Giridhar Jorapur
Greenhorn

Joined: Jun 05, 2014
Posts: 2
HI
I am converting string to XML using java as below.
When i see final xml , i see blank xmlns are added as attributes to each tags.

below is the sample code.
----



below is the method which converts from string to XML.





My Final out put is looking like this.




Any idea why this is happening?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18992
    
    8

Those instances of xmlns="" mean that those elements are not in any namespace. In your original string they are in the default namespace, but something has changed in your processing which caused that namespace information to be lost, correct?

So that must be your DOM parser's fault. And that happens because DOM parsers are not namespace-aware by default. (Not a very good default, but that's how it is.) Check out the setNamespaceAware() method of DocumentBuilderFactory and use it in your code.

(By the way, is there a reason you did this XML processing instead of just writing the string directly to the file?)

And, welcome to the Ranch!
Giridhar Jorapur
Greenhorn

Joined: Jun 05, 2014
Posts: 2
HI

Thanks for quick reply.

Let me me check this method.

Regards
Giridhar
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Blank xmlns added as attributes when converting from String to XML using Java