xml counts

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

    xml counts

    Is there a method/funciton in xmldocument
    to count all nodes in a xml doc

    or do i have to write my own

    thanks
    DAveL


  • Hans Kesting

    #2
    Re: xml counts

    on 18-9-2008, DaveL supposed :
    Is there a method/funciton in xmldocument
    to count all nodes in a xml doc
    >
    or do i have to write my own
    >
    thanks
    DAveL
    On XmlDocument there is a SelectNodes() method that accepts an XPath
    expression and returns a list of matching nodes. Get the Count of that.

    Hans Kesting


    Comment

    • Martin Honnen

      #3
      Re: xml counts

      DaveL wrote:
      Is there a method/funciton in xmldocument
      to count all nodes in a xml doc
      >
      or do i have to write my own
      It depends on the kind of nodes you are looking for
      xmlDocumentInst ance.SelectNode s("//*").Count
      gives you the number of all element nodes
      xmlDocumentInst ance.SelectNode s("//@*").Count
      the number of all attribute nodes (in the XPath 1.0 data model where
      namespace declarations are not attributes).

      --

      Martin Honnen --- MVP XML

      Comment

      • DaveL

        #4
        Re: xml counts

        Right, but it only has the count of its nodes
        child node mite have child node example

        <ROOT>
        <ONE>
        <TWO/>
        <THREE/>
        <TWO/>

        </ONE>
        <TWO>
        <THREE/>
        </TWO>
        </ONE>
        </ROOT>

        In the above i have a total of 6 nodes, i wonderd if XmlDocument Has a
        Count For all Nodes in a complete Document
        Seems Like i'll need to Write a method/function for recursion through the
        document

        Dave L

        "Hans Kesting" <news.hansdk@sp amgourmet.comwr ote in message
        news:eGGiFcjGJH A.3884@TK2MSFTN GP02.phx.gbl...
        on 18-9-2008, DaveL supposed :
        >Is there a method/funciton in xmldocument
        >to count all nodes in a xml doc
        >>
        >or do i have to write my own
        >>
        >thanks
        >DAveL
        >
        On XmlDocument there is a SelectNodes() method that accepts an XPath
        expression and returns a list of matching nodes. Get the Count of that.
        >
        Hans Kesting
        >
        >

        Comment

        • Hans Kesting

          #5
          Re: xml counts

          It happens that DaveL formulated :
          Right, but it only has the count of its nodes
          child node mite have child node example
          >
          <ROOT>
          <ONE>
          <TWO/>
          <THREE/>
          <TWO/>
          >
          </ONE>
          <TWO>
          <THREE/>
          </TWO>
          </ONE>
          </ROOT>
          >
          In the above i have a total of 6 nodes, i wonderd if XmlDocument Has a Count
          For all Nodes in a complete Document
          Seems Like i'll need to Write a method/function for recursion through the
          document
          >
          Dave L
          >
          "Hans Kesting" <news.hansdk@sp amgourmet.comwr ote in message
          news:eGGiFcjGJH A.3884@TK2MSFTN GP02.phx.gbl...
          >on 18-9-2008, DaveL supposed :
          >>Is there a method/funciton in xmldocument
          >>to count all nodes in a xml doc
          >>>
          >>or do i have to write my own
          >>>
          >>thanks
          >>DAveL
          >>
          >On XmlDocument there is a SelectNodes() method that accepts an XPath
          >expression and returns a list of matching nodes. Get the Count of that.
          >>
          >Hans Kesting
          >>
          >>
          The snippet below produces a result of 7 (I changed the XML somewhat to
          make it well-formed)

          public static void RunSnippet()
          {
          string s = @"<ROOT>
          <ONE>
          <TWO>
          <THREE/>
          </TWO>

          </ONE>
          <ONE>
          <TWO>
          <THREE/>
          </TWO>
          </ONE>
          </ROOT>";

          XmlDocument xml = new XmlDocument();
          xml.LoadXml(s);

          XmlNodeList nl = xml.SelectNodes ("//*");
          Console.WriteLi ne(nl.Count);

          }



          Hans Kesting


          Comment

          • DaveL

            #6
            Re: xml counts

            Thanks alot hans
            Much Appriciated
            DaveL

            "Hans Kesting" <news.hansdk@sp amgourmet.comwr ote in message
            news:OU6$lumGJH A.740@TK2MSFTNG P03.phx.gbl...
            It happens that DaveL formulated :
            >Right, but it only has the count of its nodes
            >child node mite have child node example
            >>
            ><ROOT>
            > <ONE>
            > <TWO/>
            > <THREE/>
            > <TWO/>
            >>
            > </ONE>
            > <TWO>
            > <THREE/>
            > </TWO>
            > </ONE>
            ></ROOT>
            >>
            >In the above i have a total of 6 nodes, i wonderd if XmlDocument Has a
            >Count For all Nodes in a complete Document
            >Seems Like i'll need to Write a method/function for recursion through the
            >document
            >>
            >Dave L
            >>
            >"Hans Kesting" <news.hansdk@sp amgourmet.comwr ote in message
            >news:eGGiFcjGJ HA.3884@TK2MSFT NGP02.phx.gbl.. .
            >>on 18-9-2008, DaveL supposed :
            >>>Is there a method/funciton in xmldocument
            >>>to count all nodes in a xml doc
            >>>>
            >>>or do i have to write my own
            >>>>
            >>>thanks
            >>>DAveL
            >>>
            >>On XmlDocument there is a SelectNodes() method that accepts an XPath
            >>expression and returns a list of matching nodes. Get the Count of that.
            >>>
            >>Hans Kesting
            >>>
            >>>
            >
            The snippet below produces a result of 7 (I changed the XML somewhat to
            make it well-formed)
            >
            public static void RunSnippet()
            {
            string s = @"<ROOT>
            <ONE>
            <TWO>
            <THREE/>
            </TWO>
            >
            </ONE>
            <ONE>
            <TWO>
            <THREE/>
            </TWO>
            </ONE>
            </ROOT>";
            >
            XmlDocument xml = new XmlDocument();
            xml.LoadXml(s);
            >
            XmlNodeList nl = xml.SelectNodes ("//*");
            Console.WriteLi ne(nl.Count);
            >
            }
            >
            >
            >
            Hans Kesting
            >
            >

            Comment

            Working...