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 ]
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.