The only reason for using an API like DOM for creating an XML file is to make sure that 'special characters' like <, >, ", ' and & get properly encoded, right?
The DOM also does other things for you like making queries easier ("Get me all albums where the artist name starts with C", allowing you to build an XML document in an object-oriented way, and providing a place to hold a document while you apply a transform to it.
Thanks for responding. I just need to create an XML file, so I could use java.io classes instead, provided of course that the 'special characters' are encoded correctly, right?
You could, but that's not the recommended way. You'll likely have problems with character set encoding (most XML docs are UTF-8, Java uses UTF-16 internally), plus you'd have to write functions to escape the special characters (entities) when that functionality is already in the DOM, waiting for you to use it.
So, yes you could, but if you have to exchange your XML doc with someone else, they might have problems reading it.
IT seems you are asking the wrong question, it should be: Why don't you want to use the DOM to create an XML document? If you have a technically valid reason then fine, if not, use the DOM.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.