none
Reading through a nested XML RRS feed

  • General discussion

  • I have a nested complex XMl. I want to loop through it and read some tags(not all). I have implemented it using SelectNodes and SelectSingleNode and inner text property. But its not looking good at all. For every node i want to read, i have to first check if the node exists, if its not empty...Its looking so unmanaged.

    <Root>

    <node1>

    <node2><node2>

    <node3></node3>

    </node1>

    <node1>

    <node2><node2>

    <node3></node3>

    </node1>

    i am using like node1 = document.selectnodes("//node1")

    foreach node in node1

    {

    node.selectsinglenode("//node2").innertext;

    }

    </Root>

    Please suggest if there is any better way to implement. I am new to coding.

    Thanks

    Abhinav

    <node1>

    <node2><node2>

    <node3></node3>

    </node1>

    <node1>

    <node2><node2>

    <node3></node3>

    </node1>

    Monday, June 6, 2016 3:33 PM

All replies

  • If you need <node2>, but do not need <node1>, then consider longer expressions, such as:

       nodes2 = document.SelectNodes(“//node1/node2[1]”);

    Then enumerate nodes2, which will give you the found <node2> nodes.



    • Edited by Viorel_MVP Monday, June 6, 2016 6:02 PM
    Monday, June 6, 2016 5:54 PM