create xml tree
Hi, I am trying do small application for showing tree structure of XML documents.
And how can I create tree of xml document with bad structure?
I can do it, when the xml file is correct. But I cannot make xml tree when the document has wrong tags:
<rt>
<aaa>
text
<bbb>
<ccc />
<ddd>text</aaa></ddd>
</rt>
I know, it is bad xml document, but is there any way how to create tree? Samething like this:
rt
+aaa : ERROR
-bbb : ERROR
-ccc
+ddd
-aaa : ERROR
I use these metods and at first build xml:
publicvoid buildXML(String fileName){
try{
SAXBuilder builder =new SAXBuilder();
builder.setValidation(false);
doc = builder.build(fileName);
}catch (JDOMException e){
e.printStackTrace();
}catch (IOException e){
e.printStackTrace();
}
root = doc.getRootElement();
}
then I get xml tree:
private DefaultMutableTreeNode tNode =new DefaultMutableTreeNode();
public DefaultMutableTreeNode getTreeNode(){
tNode.removeAllChildren();
makeTree(root, tNode);
return tNode;
}
privatevoid makeTree(Element el, DefaultMutableTreeNode tn){
DefaultMutableTreeNode tn_2 =new DefaultMutableTreeNode(el.getName());
tn.add(tn_2);
Attribute attr;
for (int i = 0; i < el.getChildren().size(); i++){
Element el2 = (Element)el.getChildren().get(i);
if (el2instanceof Element){
makeTree((Element)el2, tn_2);
}
}
}
can anybody help me, please?

