Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

copy xml string into a dom tree

 
aswin pal
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • 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?
 
Paul Clapham
Sheriff
Pie
Posts: 20177
25
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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>

 
Anish Kuti
Greenhorn
Posts: 29
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. Could you tell the high-level steps.

Download http://xmlbeans.apache.org/ and...
 
aswin pal
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • 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).
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13045
6
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Worked. thanks. was over-engineering and forgot about good old SAX.
 
aswin pal
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • 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
Pie
Posts: 20177
25
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic