select nodes count

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • David

    select nodes count

    This is my xml sample:

    <po>
    <PurchaseOrderD etail>
    <ProductLineIte m>
    <LineNumber>1 </LineNumber>
    <ProductIdentif ication>
    <aaa>...</aaa>
    <bbb />
    </ProductIdentifi cation>
    <cc />
    </ProductLineItem >
    ....
    </PurchaseOrderDe tail>
    <PurchaseOrderD etail>
    <ProductLineIte m>
    <LineNumber>2 </LineNumber>
    <ProductIdentif ication>
    <aaa>...</aaa>
    <bbb />
    </ProductIdentifi cation>
    <cc />
    </ProductLineItem >
    ....
    </PurchaseOrderDe tail>
    </po>

    I want to select "PurchaseOrderD etail" tag count, like this sample, I
    should get "2". How should I get the count of it?

    Thanks, David.

  • David

    #2
    Re: select nodes count

    I use selectnodes:

    XmlElement root = doc.DocumentEle ment;
    XmlNodeList nodeList = root.SelectNode s("/PO/PurchaseOrderDe tail");
    int li_TotalCount = nodeList.Count;

    But the li_TotalCount always "0"
    I want get "2"...

    Thanks, David.

    Comment

    • singh_angrez@rediffmail.com

      #3
      Re: select nodes count

      Hi,
      You can do it like this.

      XmlNodeList nodeList = doc.GetElements ByTagName("Purc haseOrderDetail ");
      int li_TotalCount = nodeList.Count;

      I think this will give you a count of 2.

      Regards,
      Angrez

      Comment

      • Hans Kesting

        #4
        Re: select nodes count

        David wrote:[color=blue]
        > I use selectnodes:
        >
        > XmlElement root = doc.DocumentEle ment;
        > XmlNodeList nodeList = root.SelectNode s("/PO/PurchaseOrderDe tail");
        > int li_TotalCount = nodeList.Count;
        >
        > But the li_TotalCount always "0"
        > I want get "2"...
        >
        > Thanks, David.[/color]

        Here you use "PO" in capitals, your example uses "po" in lowercase.
        Is that a typo in your post? If not, then there is your problem: XML is case-sensitive
        and yours has only "/po/PurchaseOrderDe tail" nodes and no "/PO/PurchaseOrderDe tail"

        Hans Kesting


        Comment

        • David

          #5
          Re: select nodes count

          I got it!
          Thank you, Angrez.

          Comment

          • David

            #6
            Re: select nodes count

            Thank you, Hans.
            I solved it already.

            David

            Hans Kesting wrote:[color=blue]
            > David wrote:[color=green]
            > > I use selectnodes:
            > >
            > > XmlElement root = doc.DocumentEle ment;
            > > XmlNodeList nodeList = root.SelectNode s("/PO/PurchaseOrderDe tail");
            > > int li_TotalCount = nodeList.Count;
            > >
            > > But the li_TotalCount always "0"
            > > I want get "2"...
            > >
            > > Thanks, David.[/color]
            >
            > Here you use "PO" in capitals, your example uses "po" in lowercase.
            > Is that a typo in your post? If not, then there is your problem: XML[/color]
            is case-sensitive[color=blue]
            > and yours has only "/po/PurchaseOrderDe tail" nodes and no[/color]
            "/PO/PurchaseOrderDe tail"[color=blue]
            >
            > Hans Kesting[/color]

            Comment

            Working...