• Post Reply Bookmark Topic Watch Topic
  • New Topic

XML handling in Java  RSS feed

 
Nitin Mehhta
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm facing a problem for which I am unable to find a correct solution. I have a XML file which I read into memory and make a DOM (using validating parser). Now I start removing certain nodes from the DOM. I want to check that each Node removal is not causing the document to be invalid against the DTD. I want to check this as and when i'm removing the nodes and if the document is becoming invalid because of theremoval then I do not want to remove the node. The only way I can think of achieving that right now is removing each node then writing the file back and again validating it by parsing through a validating parser. But that will hit the performance a lot. Can anyone suggest a better alternate, I'm sure they would be a better way.

Thanks in advance.
Nitin
 
Nitin Mehhta
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to add to my question, I know such a dynamic validation is possible in DOM3 but the environment I am using is DOM2 jdk1.4_2
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With the DOM2 standard API, there is unfortunately no way to revalidate an XML document. You can however serialize the document to text, then reparse it. However, this will have performance problems
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is possible to use DOM 3 with Java 1.4.2 if you have a DOM3-compliant XML parser like Xerces 2.7. See here and here on how to do that.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!