• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

copy xml string into a dom tree

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a DOM tree, and a node in it into which I need to copy another XML node.

The general examples advise to load the source as one more DOM tree, do a importNode.

The problem is performance.

I have a huge string (depth-wise) and am looking for alternatives.

Any ideas?
 
Sheriff
Posts: 27235
87
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What exactly were the performance problems which you encountered?

And what exactly are you looking for alternatives to? Do you want to scrap the idea of using a DOM and rewriting the application to handle the XML some other way? Or were you just looking for some other way to import data into an existing DOM?
 
aswin pal
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem is that I have a DOM tree into which I want to copy XML from a file. That XML content is huge in the number of nodes and their levels.

Loading it into a DOM node and using importNode will be expensive in my case, and I was just trying to see if I can copy that entire thing just as a String into my DOM tree.

Existing DOM tree in code:

<a>
<b>[insert huge XML here]</b>
</a>

XML:

<x>
<y>
<z>
</z>
</y>
</x>

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From your reply it seems .. the problem is huge XML - that memory consumption is high.
You can try using XML bean for this.
 
aswin pal
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks. Could you tell the high-level steps.

Download http://xmlbeans.apache.org/ and...
 
aswin pal
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, a quick read of http://xmlbeans.apache.org/ tells me of it as a java-xml binding api.

My XML is without a schema and all I want is to add huge XML to existing DOM tree without importNode that will parse that content (and therefore consume time).
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why are you using DOM at all, why not treat the problem as one of merging two text streams?

If you absolutely need to parse document 1 to find the insertion point, do it with SAX, writing the contents of all events as Strings to a new output file and inserting your new text when you hit the insertion point.

Bill
 
aswin pal
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Worked. thanks. was over-engineering and forgot about good old SAX.
 
aswin pal
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, would passing xml to createTextNode() as a normal string be a bad idea? I have not tried it at the moment...
 
Paul Clapham
Sheriff
Posts: 27235
87
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

aswin pal wrote:Also, would passing xml to createTextNode() as a normal string be a bad idea? I have not tried it at the moment...


It would be a bad idea if you expected the createTextNode method to parse the XML into nodes. It would be a good idea if you wanted the XML to remain as an uninterpreted string, and if you expected the markup (characters like < and >) to be escaped.
 
reply
    Bookmark Topic Watch Topic
  • New Topic