File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Giridhar Jorapur
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20177
25
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI

Thanks for quick reply.

Let me me check this method.

Regards
Giridhar
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic