moving in xml nodes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • barantamer
    New Member
    • Dec 2007
    • 5

    #1

    moving in xml nodes

    hello,
    i am actually a php developer and i am new to java
    i think i have a pretty easy question.
    How can i do this exactly in java ?

    Code:
    foreach ($rootnode->children() as $child)
      {
         //some code here
      }
    $node is an xml node here. In my java code i have a root in Element type

    it will be something like i guess

    Code:
    for(Element node : rootnode.getchildren()) //rootnode.getchildren should return the child nodes of rood node in type Element
    {
       // some code here
    }
  • barantamer
    New Member
    • Dec 2007
    • 5

    #2
    Thanks for the help, here is the answer :)

    Code:
    NodeList List = root.getChildNodes();
    for (int i=0;i<List.getLength();i++)
    {
        /* 
       If you want to modify the node 
       you must cast the node to the type element
       */ 
       Element e = (Element)List.item(i);
    }

    Comment

    Working...