when the tmpElement is some node with value. So when I am standing on the node and doing getFirstChild() I am on the value (node) of this node. Then I do getValue() and I have the value as a string which is what I need. so if tmpElement is on node then value will be "value".
My problem is that now the value can be xml tree. for instance:
So now tmpElement.getFirstChild() gives me node1. What I need is to get all of the internal tree:
When you want to convert from internal representation (e.g. DOM nodes) to external representation (file, string, etc) that's called "serializing". (The opposite is called "parsing", as you probably know already.)
To serialize data from a DOM, the easiest way is to use a Transformer and call its transform(source, result) method. In your case the input is coming from a DOM node so the source would be a DOMSource based on that node. Output to a String is trickier unless you dig through the API documentation a bit more than superficially. Create your Result like this:
Joined: Sep 25, 2008
Yes but how do I get the whole internal tree? Forget toString() for a sec.
Originally posted by John Landon: So getFirstChild() gives me the whole tree? not just the first node?
In your example it gives you a node, yes. But that node has children, which in turn can have children.
As I mentioned in my first reply, parsing converts the XML document to an internal format. In your case it's a DOM, which is a tree structure containing the same data that the original document contained. You can write code to navigate to any node in that tree at all.
Watch out for getFirstChild() - if your XML document contains any text formatting for readability, the result is likely to be a Text Node, not the Element you were expecting. This commonly causes confusion for beginners.