GeeCON Prague 2014*
The moose likes XML and Related Technologies and the fly likes can i use DOM.. to see if xml is well formed 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 "can i use DOM.. to see if xml is well formed " Watch "can i use DOM.. to see if xml is well formed " New topic
Author

can i use DOM.. to see if xml is well formed

lavnish lalchandani
Ranch Hand

Joined: Feb 28, 2007
Posts: 79
Hi
I am getting a string from user and need to check whether its well formed
( no need to validate against schema )
for the same i am using the following code ...



but its using SAX ... which "principally" is advisable to use for big xml files ...
I am aware that i will be getting a small xml file from user

two questions here
(i) Which way is better shud i use DOM or SAX ? why ? ( for my usecase i think DOM )
(ii) saw the APIs for DocumentBuilder.parse( ) as i am getting a String object from user cant give input as File , URI , StringBufferInputStream (deprecated) .. so is using SAX the only way ?
[ April 15, 2008: Message edited by: lavnish lalchandani ]

lavnish.blogspot.com
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12792
    
    5
Personally I would use SAX just to save time and memory. It is important to note that you can get useful information about the position of a parsing error out of a SAXParseException so I would catch that first.

Being able to tell your user the line and column of the error could be very helpful.

Note that DOM parsers really use a SAX parser underneath.

Bill
 
GeeCON Prague 2014
 
subject: can i use DOM.. to see if xml is well formed