Discussions

XML & Web services: Parsing the XML

  1. Parsing the XML (4 messages)

    This is regarding the XML parsing .I am using xerces parser for parsing the xml.I am trying to get the node value null when i invoke the method getNodeValue()....
    assuem this is my xml
    <Test>TestingXML
    </Test>
    I need to get the TestingXML ....Can anyone explian me how to get...
    Thanking advance for ur valuable reply...

    Threaded Messages (4)

  2. Parsing the XML[ Go to top ]

    After u reach a node u can get the name by calling the method getNodeName(),but to get the node value u have to do a getFirstChild() and then do getNodeValue(),this is because the node value is one level below the node name

    Mahesh
  3. Parsing the XML[ Go to top ]

    Hi is working thanks,
    Let me know where i can get some sames on these ...
    I would like to know how to get the childes
    <Testxml>
     Testing
    < FirstXML> FirstXML Test
    </FirstXML>
    </Testxml>
    I would thank u for the above information...
  4. Parsing the XML[ Go to top ]

    NodeList nl = doc.getElementsByName("Testxml");
    Node n = nl.getFirstChild(); // I think, been a while!

    String t = n.getNodeValue();


    t should now contain the value you want.

    Bear in mind, that getFirstChild() will return the FIRST CHILD. If you add an attribute to the tag, such as

    <Testxml myattr="value">

    then getFirstChild() will probably return the attribute now, rather than the node value itself, which now becomes the LAST child of the node.

    HTH

    Chz

    Tony

    PS. I have been forced to use the MSXML Dom recently, in which the above is most definitely true, and to the best of my knowledge it's true for all of them. Also, in a moment of sheer adequacy the MSXML Dom is amazing quick! Shocked the hell out of me! :-)
  5. Parsing the XML[ Go to top ]

    Missed out a piece.

    Node n = nl.children(0).getFirstChild();

    Note the added children(0). Might have the name of the method wrong, but you can work it out! :-)

    CHz

    TOny