Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. XML Node count

XML Node count

Scheduled Pinned Locked Moved Visual Basic
questionxmlhelp
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Shazz Rock
    wrote on last edited by
    #1

    Hello all I need help to count node and their respective id. 1 2 how can i count person node..?? and Person Id = 001 & 002 Thanx in advance.. Shazz here to help you...

    A 1 Reply Last reply
    0
    • S Shazz Rock

      Hello all I need help to count node and their respective id. 1 2 how can i count person node..?? and Person Id = 001 & 002 Thanx in advance.. Shazz here to help you...

      A Offline
      A Offline
      astanton1978
      wrote on last edited by
      #2

      Assuming that People is the root of the document, you can iterate the nodes like this. - Assumes the ID's are integers, you can change it to String if you want. - written without syntax checking. Sorry if its a bit off, but you can get the idea.

      Imports System.Xml

      Private Sub CountNodes(xmlDoc as XmlDocument)
      Dim xNode as XmlNode
      Dim nodeName as String
      Dim nodeCount as Integer
      Dim listOfIDs as New List(Of Integer)

      For Each xNode in xmlDoc.DocumentElement.ChildNodes
      If String.IsNullOrEmpty(xNode.Name) = False Then
      nodeName = xNode.Name.Trim().ToLower()
      If nodeName = "person" Then
      nodeCount++
      If node.Attributes("ID") IsNot Nothing Then
      listOfIDs.Add(Convert.ToInt32(node.GetAttributeValue("ID")))
      End If 'node attr
      End If 'node name
      End If 'node has name
      Next 'xNode

      End Sub

      You can also use Xpath Query to do the same, or if the nodes can be nested you will need a recursive function.

      S 1 Reply Last reply
      0
      • A astanton1978

        Assuming that People is the root of the document, you can iterate the nodes like this. - Assumes the ID's are integers, you can change it to String if you want. - written without syntax checking. Sorry if its a bit off, but you can get the idea.

        Imports System.Xml

        Private Sub CountNodes(xmlDoc as XmlDocument)
        Dim xNode as XmlNode
        Dim nodeName as String
        Dim nodeCount as Integer
        Dim listOfIDs as New List(Of Integer)

        For Each xNode in xmlDoc.DocumentElement.ChildNodes
        If String.IsNullOrEmpty(xNode.Name) = False Then
        nodeName = xNode.Name.Trim().ToLower()
        If nodeName = "person" Then
        nodeCount++
        If node.Attributes("ID") IsNot Nothing Then
        listOfIDs.Add(Convert.ToInt32(node.GetAttributeValue("ID")))
        End If 'node attr
        End If 'node name
        End If 'node has name
        Next 'xNode

        End Sub

        You can also use Xpath Query to do the same, or if the nodes can be nested you will need a recursive function.

        S Offline
        S Offline
        Shazz Rock
        wrote on last edited by
        #3

        Thanx for your refernce code. Partially its working fine though I am using VB6.0 application and your mention code belong to vb.net. I am slight confuse for declaration of `Node` because non of IXMLDom related datatype have properties of GetAtttributeValues("ID"). Please guide me how can I proceed. I had search and i tried many things help. Refernece as I had used "Microsoft XML v6.0" Thanx in advance. Awaiting for your reply.

        Shazz here to help you...

        A 1 Reply Last reply
        0
        • S Shazz Rock

          Thanx for your refernce code. Partially its working fine though I am using VB6.0 application and your mention code belong to vb.net. I am slight confuse for declaration of `Node` because non of IXMLDom related datatype have properties of GetAtttributeValues("ID"). Please guide me how can I proceed. I had search and i tried many things help. Refernece as I had used "Microsoft XML v6.0" Thanx in advance. Awaiting for your reply.

          Shazz here to help you...

          A Offline
          A Offline
          astanton1978
          wrote on last edited by
          #4

          Sorry, I no longer have VB6 available to help you with this exactly. The GetAttributeValues() method will get the value of an XMLNode (element)'s attribute. I cant find any IXMLDom documentation to look for a similar function, but if you can post a link I can try to find it.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups