Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
lavnish lalchandani
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic