XML Files are very popular for storing and sharing information, I'll not repeat what you can find in search engines.
XML format is a tree structure for storing data and fits perfectly in a JTree.
I used dom4j for parsing the file (which is really easy to use).
This is a snapshot with a pom.xml used by maven:
Dom4j provide a really easy way for parsing the file:
SAXReader reader = new SAXReader();
Document doc = reader.read(inputFile);
Element e = doc.getRootElement();
Now you can traverse the xml tree using the root element in your favorite order.
You can see a way using recursion in the source code (attached into the jar file).
Download.
This can be helpful for parsing web pages, most of them are malformed but you can find a way to add / remove / change content with a little bit of parsing to make a well formed document and use dom4j to parse it for you (I did it several times).
I hope this can be helpful for you.
Thanks for reading and see you in the next post.
No comments:
Post a Comment
Leave me a comment