Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Scout » How to rappresent XML in a tree field
icon3.gif  How to rappresent XML in a tree field [message #1231340] Tue, 14 January 2014 12:06 Go to next message
marco giudici is currently offline marco giudiciFriend
Messages: 204
Registered: February 2013
Location: Italy
Senior Member
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
Re: How to rappresent XML in a tree field [message #1243817 is a reply to message #1231340] Tue, 11 February 2014 13:39 Go to previous messageGo to next message
Adrian Sacchi is currently offline Adrian SacchiFriend
Messages: 10
Registered: January 2013
Junior Member
The problem is that on ScoutXmlElement exists no method to query all attributes if you do not know the attributes' names in advance.

As ScoutXmlParser itself is just a wrapper around other xml parsers you can just use such a parser directly.

Please note: In future ScoutXmlParser will possibly be deprecated and eventually removed. (See: https://bugs.eclipse.org/bugs/show_bug.cgi?id=427899)

Re: How to rappresent XML in a tree field [message #1243901 is a reply to message #1243817] Tue, 11 February 2014 16:06 Go to previous message
marco giudici is currently offline marco giudiciFriend
Messages: 204
Registered: February 2013
Location: Italy
Senior Member
Ok, thank you Adrian for this information
Previous Topic:Replacing deprecated CTI classes
Next Topic:RAP theming Menu Bar
Goto Forum:
  


Current Time: Tue Mar 19 09:46:53 GMT 2024

Powered by FUDForum. Page generated in 0.02364 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top