How to rappresent XML in a tree field [message #1231340] |
Tue, 14 January 2014 12:06 |
|
Hi all,
I need to represent an XML file into a tree field with attribute and element; after that I need to enable the possibility to add, modify and delete node, element or attribute.
For the moment I use ScoutXmlParser, but I loose completely the attribute:
ScoutXmlParser parser = new ScoutXmlParser();
parser.setValidating(false);
try {
ScoutXmlDocument document = parser.parse(xml);
ScoutXmlElement rootElement = document.getRoot();
AbstractTreeNode root = getAbstractTree(rootElement.getLocalName());
tree.addChildNode(tree.getRootNode(), root);
this.recurse(tree, root, rootElement, rootElement.hasChildren());
setTree(tree, false);
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
public void recurse(Tree tree, AbstractTreeNode parent, ScoutXmlElement x, boolean b) {
AbstractTreeNode child = null;
if (b) {
List<ScoutXmlElement> list = x.getChildren();
for (ScoutXmlElement x1 : list) {
child = this.getAbstractTree(x1.getLocalName());
tree.addChildNode(parent, child);
this.recurse(tree, child, x1, x1.hasChildren());
}
}
else {
if (x.hasContent()) tree.addChildNode(parent, this.getAbstractTree(x.getText()));
}
}
I think to enable the various function (add, modify and delete) by use a event listener.
Thanks in advance for any help and explanation
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02364 seconds