This week's book giveaway is in the Testing forum.
We're giving away four copies of Data Structures the Fun Way: An Amusing Adventure with Coffee-Filled Examples and have Jeremy Kubica on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

XML handling in Java

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 43028
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
"To do good, you actually have to do something." -- Yvon Chouinard
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic