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. C#
  4. read xml

read xml

Scheduled Pinned Locked Moved C#
questionxml
6 Posts 5 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.
  • A Offline
    A Offline
    arkiboys
    wrote on last edited by
    #1

    I have an xml file which I would like to read and pull out it's contents as follows: xml sample: <persons> <person></person> <person> <value>x</value> <value>y</value> <value>z</value> </person> <person> <value>w</value> <value>u</value> </person> ... ... ... </persons> So as I read through the above xml, I would like to go through them one record at a time so I would like to see: record No xml 1 <person></person> 2 <person> <value>x</value> <value>y</value> <value>z</value> </person> 3 <person> <value>w</value> <value>u</value> </person> How can I code this please? Thanks

    G B M 3 Replies Last reply
    0
    • A arkiboys

      I have an xml file which I would like to read and pull out it's contents as follows: xml sample: <persons> <person></person> <person> <value>x</value> <value>y</value> <value>z</value> </person> <person> <value>w</value> <value>u</value> </person> ... ... ... </persons> So as I read through the above xml, I would like to go through them one record at a time so I would like to see: record No xml 1 <person></person> 2 <person> <value>x</value> <value>y</value> <value>z</value> </person> 3 <person> <value>w</value> <value>u</value> </person> How can I code this please? Thanks

      G Offline
      G Offline
      Giorgi Dalakishvili
      wrote on last edited by
      #2

      XML + Read =XmlReader[^]

      Giorgi Dalakishvili #region signature My Articles / My Latest Article[^] / My blog[^] #endregion

      1 Reply Last reply
      0
      • A arkiboys

        I have an xml file which I would like to read and pull out it's contents as follows: xml sample: <persons> <person></person> <person> <value>x</value> <value>y</value> <value>z</value> </person> <person> <value>w</value> <value>u</value> </person> ... ... ... </persons> So as I read through the above xml, I would like to go through them one record at a time so I would like to see: record No xml 1 <person></person> 2 <person> <value>x</value> <value>y</value> <value>z</value> </person> 3 <person> <value>w</value> <value>u</value> </person> How can I code this please? Thanks

        B Offline
        B Offline
        bcozican
        wrote on last edited by
        #3

        Try the code below: string xmlFilePath = @"C:\Persons.xml"; System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); doc.Load(xmlFilePath); System.Xml.XmlNode pNode = doc.SelectSingleNode("persons"); for (int i = 0; i < pNode.ChildNodes.Count; i++) { System.Xml.XmlNode personNode = pNode.ChildNodes[i]; for (int x = 0; x < personNode.ChildNodes.Count; x++) { string value = personNode.ChildNodes[x].InnerText; } } Hope this helps.

        A 1 Reply Last reply
        0
        • B bcozican

          Try the code below: string xmlFilePath = @"C:\Persons.xml"; System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); doc.Load(xmlFilePath); System.Xml.XmlNode pNode = doc.SelectSingleNode("persons"); for (int i = 0; i < pNode.ChildNodes.Count; i++) { System.Xml.XmlNode personNode = pNode.ChildNodes[i]; for (int x = 0; x < personNode.ChildNodes.Count; x++) { string value = personNode.ChildNodes[x].InnerText; } } Hope this helps.

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

          Thank you

          modified on Tuesday, October 14, 2008 10:20 AM

          P 1 Reply Last reply
          0
          • A arkiboys

            Thank you

            modified on Tuesday, October 14, 2008 10:20 AM

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #5

            Look at the member methods of XmlDocument, read the documentation.

            1 Reply Last reply
            0
            • A arkiboys

              I have an xml file which I would like to read and pull out it's contents as follows: xml sample: <persons> <person></person> <person> <value>x</value> <value>y</value> <value>z</value> </person> <person> <value>w</value> <value>u</value> </person> ... ... ... </persons> So as I read through the above xml, I would like to go through them one record at a time so I would like to see: record No xml 1 <person></person> 2 <person> <value>x</value> <value>y</value> <value>z</value> </person> 3 <person> <value>w</value> <value>u</value> </person> How can I code this please? Thanks

              M Offline
              M Offline
              Mohammad Dayyan
              wrote on last edited by
              #6

              If you can use .Net Framework 3.5, I suggest using LINQ http://msdn.microsoft.com/en-us/library/bb387098.aspx[^]

              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