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?

[2687 byte] By [weepeea] at [2007-10-3 2:57:44]
# 1
The question makes no sense. You display something that isn't tree-structured data and ask if there is any way to display it in a tree structure. Well, no, there isn't.And also, no XML parser will complete parsing of a malformed XML document. It's against the rules.
DrClapa at 2007-7-14 20:47:05 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2
JAXP API creates an XML document with matching tags.
dvohra09a at 2007-7-14 20:47:05 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3
To create an ML document that does not have matching tags use the StAX API, that does not check if the document is valid.
dvohra09a at 2007-7-14 20:47:05 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...