Suppose there is a simple XML file as below:
<a>
<b>hello</b>
<c>world</c>
</a>
I want to create a DOM tree, without using the parser provided by Java library ( I do want to use other APIs and data structures, like Element). I am kind of familiar with the lexing(tokenization) part, but how to use the tokens to build the tree ?
The tree creating algorithm is something I learnt from data structure classes. The problem is how to utilize the given DOM framework in Java library? like Element, or Node, or DOM APIs which can help insert new nodes to the DOM tree.
Is there any exiting examples that I can learn from ?
Start off from DocumentBuilderFactory, create a
DocumentBuilderand from this create a newDocumentobject. From there,Documenthas methods to add elements, attributes, etc so you can use these methods to generate a document.