Results 1 to 5 of 5

Thread: arborescent xml

  1. #1
    mharsijamel is offline Member
    Join Date
    Aug 2011
    Posts
    60
    Rep Power
    0

    Default arborescent xml

    I have a xml tree that I want to browse

    <?xml version="1.0" encoding="UTF-8"?>
    <Ontology name="Ontology">
    <DecisionMaker name="SalesManager">
    <BusinessProcess name="Order" />
    </DecisionMaker>
    </Ontology>
    but with this code
    Java Code:
                 List le=racine.getChildren();
                 ListIterator le1=le.listIterator();
                 while(le1.hasNext())
                 {
                     Element f=(Element) le1.next();
                     System.out.println("f"+f.getName());
                     String name=f.getAttributeValue("name");
                     System.out.println("name"+name);
                 }
    I can not access to some nodes such "BusinessProcess" in this example
    and i have as result:
    fDecisionMaker
    nSalesManager

    when i added to my code after "System.out.println("name"+name);"
    Java Code:
    List h=f.getChildren();
    ListIterator a1=h.listIterator();   
    while(a1.hasNext())
             {
                 Element e=(Element) a1.next();
                 le1.add(e);
             }
    i have this error "The Content already has an existing parent "DecisionMaker""
    i don't know what i do?please help me

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,005
    Blog Entries
    7
    Rep Power
    20

    Default Re: arborescent xml

    That doesn't surprise me: the top level node (Ontology) has one child node (DecisionMaker) which has one child itself (BusinessProcess). Your iterator traverses the children of the top level node only. An Element extends a Node and a Node has a getChildNodes() method; try that on your DecisionMaker node ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    mharsijamel is offline Member
    Join Date
    Aug 2011
    Posts
    60
    Rep Power
    0

    Default Re: arborescent xml

    thanks
    but i don't have this method "getChildNodes()" when i made
    Java Code:
    f.getChildNodes();
    i hade error of unexistion method

  4. #4
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,005
    Blog Entries
    7
    Rep Power
    20

    Default Re: arborescent xml

    Quote Originally Posted by mharsijamel View Post
    thanks
    but i don't have this method "getChildNodes()" when i made
    Java Code:
    f.getChildNodes();
    i hade error of unexistion method
    I find that strange because an Element (an interface) extends the interface Node and getChildNodes() is defined in the Node interface ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    mharsijamel is offline Member
    Join Date
    Aug 2011
    Posts
    60
    Rep Power
    0

    Default Re: arborescent xml

    my problem is to browse all nodes in this arborescent and to read or to add other nodes
    so how???

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •