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. XML / XSL
  4. Read XML in C#

Read XML in C#

Scheduled Pinned Locked Moved XML / XSL
tutorialcsharpcssxml
6 Posts 5 Posters 1 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
    ShafiqA
    wrote on last edited by
    #1

    hello guys, I am reading xml file and showing in grid in c# but now i want to read specific record(node) of that xml file like where clouse in sqlserver Example <Root> <Data id="1" Name="aaa" Phone="852963" Gender="Male" /> <Data id="2" Name="bbb" Phone="123456789" Gender="Female" /> <Data id="3" Name="ccc" Phone="987654" Gender="Male" /> <Data id="3" Name="ddd" Phone="7676767" Gender="Male" /> </Root> i need to read the first(TOP)id record and who's Gender="male". how to do this Regards Shafiq

    G P T Y 4 Replies Last reply
    0
    • S ShafiqA

      hello guys, I am reading xml file and showing in grid in c# but now i want to read specific record(node) of that xml file like where clouse in sqlserver Example <Root> <Data id="1" Name="aaa" Phone="852963" Gender="Male" /> <Data id="2" Name="bbb" Phone="123456789" Gender="Female" /> <Data id="3" Name="ccc" Phone="987654" Gender="Male" /> <Data id="3" Name="ddd" Phone="7676767" Gender="Male" /> </Root> i need to read the first(TOP)id record and who's Gender="male". how to do this Regards Shafiq

      G Offline
      G Offline
      Ger Hayden
      wrote on last edited by
      #2

      Try Bipin Joshi's book "Beginning XML with C# 2008" by Apress. I think thats there. ~GER

      Ger

      1 Reply Last reply
      0
      • S ShafiqA

        hello guys, I am reading xml file and showing in grid in c# but now i want to read specific record(node) of that xml file like where clouse in sqlserver Example <Root> <Data id="1" Name="aaa" Phone="852963" Gender="Male" /> <Data id="2" Name="bbb" Phone="123456789" Gender="Female" /> <Data id="3" Name="ccc" Phone="987654" Gender="Male" /> <Data id="3" Name="ddd" Phone="7676767" Gender="Male" /> </Root> i need to read the first(TOP)id record and who's Gender="male". how to do this Regards Shafiq

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

        SelectNodes and XPath.

        1 Reply Last reply
        0
        • S ShafiqA

          hello guys, I am reading xml file and showing in grid in c# but now i want to read specific record(node) of that xml file like where clouse in sqlserver Example <Root> <Data id="1" Name="aaa" Phone="852963" Gender="Male" /> <Data id="2" Name="bbb" Phone="123456789" Gender="Female" /> <Data id="3" Name="ccc" Phone="987654" Gender="Male" /> <Data id="3" Name="ddd" Phone="7676767" Gender="Male" /> </Root> i need to read the first(TOP)id record and who's Gender="male". how to do this Regards Shafiq

          T Offline
          T Offline
          Tarun K S
          wrote on last edited by
          #4

          Here is the Answer!

          XmlDocument xmlDoc =new XmlDocument;
          xmlDoc.Load("C:\MyXml");
          string myXPath="/Root/Data[@Gender='Male']"; //so with this you can get only male nodes

          XmlNodeList NodeList=xmlDoc.SelectNodes(myXPath); //Selects all the male nodes

          XmlNode xmlNod=NodeList(0); //The first male node

          Int myId=xmlNod.Attributes("id").Value; //Returns the id of the first Male node

          Cheers! :)

          T 1 Reply Last reply
          0
          • T Tarun K S

            Here is the Answer!

            XmlDocument xmlDoc =new XmlDocument;
            xmlDoc.Load("C:\MyXml");
            string myXPath="/Root/Data[@Gender='Male']"; //so with this you can get only male nodes

            XmlNodeList NodeList=xmlDoc.SelectNodes(myXPath); //Selects all the male nodes

            XmlNode xmlNod=NodeList(0); //The first male node

            Int myId=xmlNod.Attributes("id").Value; //Returns the id of the first Male node

            Cheers! :)

            T Offline
            T Offline
            Tarun K S
            wrote on last edited by
            #5

            It would be much better if you use XQuery or LINQ which has the same querying pattern like that of SQL. But i am still in the learning phase, so once i get a good hold in it, i shall write my answer.

            1 Reply Last reply
            0
            • S ShafiqA

              hello guys, I am reading xml file and showing in grid in c# but now i want to read specific record(node) of that xml file like where clouse in sqlserver Example <Root> <Data id="1" Name="aaa" Phone="852963" Gender="Male" /> <Data id="2" Name="bbb" Phone="123456789" Gender="Female" /> <Data id="3" Name="ccc" Phone="987654" Gender="Male" /> <Data id="3" Name="ddd" Phone="7676767" Gender="Male" /> </Root> i need to read the first(TOP)id record and who's Gender="male". how to do this Regards Shafiq

              Y Offline
              Y Offline
              Yvan Rodrigues
              wrote on last edited by
              #6

              XPath is easy to use, uses a hierarchical syntax and is available in many languages. LINQ is far more flexible, but is .NET-centric.

              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