Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

why use an API

Status
Not open for further replies.

varocho

Programmer
Dec 4, 2000
238
US
The only reason for using an API like DOM for creating an XML file is to make sure that 'special characters' like <, >, &quot;, ' and & get properly encoded, right?
 
The DOM also does other things for you like making queries easier (&quot;Get me all albums where the artist name starts with C&quot;), 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.

Chip H.
 
Chip,

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.

Chip H.
 
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.

-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top