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. How to retrive the value?

How to retrive the value?

Scheduled Pinned Locked Moved C#
xmlquestioncsharphelptutorial
10 Posts 4 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.
  • L Offline
    L Offline
    Luckie
    wrote on last edited by
    #1

    Am getting the value of a node from my XML like this.. XmlDocument doc = new XmlDocument(); doc.Load(Application.StartupPath + "\\XMLfile.xml"); string xpath = "/Image/Crop/X"; XmlNode ReadX = doc.SelectSingleNode(xpath); XmlNode X = ReadX.FirstChild.ParentNode; XmlNodeReader nodeReader = new XmlNodeReader(X); X = doc.ReadNode(nodeReader); (Is this right? As I am new to .Net..I req u to check out and If am wrong.. kindly correct my mistake) And if am right.. I want to use this X as an integer.. How do I do this... I tried a method..But it throws an error that "Cannot implicitly convert type Int to system.xml.xmlnode"..tell me a way to retrieve the value of a node from my xml and to use in my further part of my program.. as an integer.. Thank You!

    E L 2 Replies Last reply
    0
    • L Luckie

      Am getting the value of a node from my XML like this.. XmlDocument doc = new XmlDocument(); doc.Load(Application.StartupPath + "\\XMLfile.xml"); string xpath = "/Image/Crop/X"; XmlNode ReadX = doc.SelectSingleNode(xpath); XmlNode X = ReadX.FirstChild.ParentNode; XmlNodeReader nodeReader = new XmlNodeReader(X); X = doc.ReadNode(nodeReader); (Is this right? As I am new to .Net..I req u to check out and If am wrong.. kindly correct my mistake) And if am right.. I want to use this X as an integer.. How do I do this... I tried a method..But it throws an error that "Cannot implicitly convert type Int to system.xml.xmlnode"..tell me a way to retrieve the value of a node from my xml and to use in my further part of my program.. as an integer.. Thank You!

      E Offline
      E Offline
      Ennis Ray Lynch Jr
      wrote on last edited by
      #2

      One of the nice benefits of the built in .NET xml serialization is that you can create an object decorated with attributes and then use the XML Serializer object to directly read all of the file with little or no word. I would like into it a bit.

      Need a C# Consultant? I'm available.
      Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway

      L 1 Reply Last reply
      0
      • L Luckie

        Am getting the value of a node from my XML like this.. XmlDocument doc = new XmlDocument(); doc.Load(Application.StartupPath + "\\XMLfile.xml"); string xpath = "/Image/Crop/X"; XmlNode ReadX = doc.SelectSingleNode(xpath); XmlNode X = ReadX.FirstChild.ParentNode; XmlNodeReader nodeReader = new XmlNodeReader(X); X = doc.ReadNode(nodeReader); (Is this right? As I am new to .Net..I req u to check out and If am wrong.. kindly correct my mistake) And if am right.. I want to use this X as an integer.. How do I do this... I tried a method..But it throws an error that "Cannot implicitly convert type Int to system.xml.xmlnode"..tell me a way to retrieve the value of a node from my xml and to use in my further part of my program.. as an integer.. Thank You!

        L Offline
        L Offline
        led mike
        wrote on last edited by
        #3

        Shan85 wrote:

        string xpath = "/Image/Crop/X";

        Shan85 wrote:

        I want to use this X as an integer.. How do I do this...

        The letter 'X' is not an integer. :confused: Say your XML looks like this: <Image><Crop><X>22</X></Crop></Image> Then, and this is certainly not the only way, without accounting for possible errors:

        XmlDocument doc = new XmlDocument();
        doc.LoadXml("<Image><Crop><X>22</X></Crop></Image>");
        XmlNode node = doc.SelectSingleNode("//Image/Crop/X");
        int val = int.Parse(node.InnerText);
        System.Diagnostics.Debug.WriteLine(string.Format("X+1 = {0}", val + 1));

        led mike

        L 1 Reply Last reply
        0
        • E Ennis Ray Lynch Jr

          One of the nice benefits of the built in .NET xml serialization is that you can create an object decorated with attributes and then use the XML Serializer object to directly read all of the file with little or no word. I would like into it a bit.

          Need a C# Consultant? I'm available.
          Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway

          L Offline
          L Offline
          Luckie
          wrote on last edited by
          #4

          Thanks for the response Sir,my reqst is.. Suppose i declare an integer called XP and now i want to assign the value of X(from previous coding) with XP. How do i convert it?

          1 Reply Last reply
          0
          • L led mike

            Shan85 wrote:

            string xpath = "/Image/Crop/X";

            Shan85 wrote:

            I want to use this X as an integer.. How do I do this...

            The letter 'X' is not an integer. :confused: Say your XML looks like this: <Image><Crop><X>22</X></Crop></Image> Then, and this is certainly not the only way, without accounting for possible errors:

            XmlDocument doc = new XmlDocument();
            doc.LoadXml("<Image><Crop><X>22</X></Crop></Image>");
            XmlNode node = doc.SelectSingleNode("//Image/Crop/X");
            int val = int.Parse(node.InnerText);
            System.Diagnostics.Debug.WriteLine(string.Format("X+1 = {0}", val + 1));

            led mike

            L Offline
            L Offline
            Luckie
            wrote on last edited by
            #5

            Great Job Mr.Mike.. A single line of code is enough..Littl confused now. :-( Like.... int XP = somthing.Convert.toint32(X) u said that x is not an integer,.. But i want to use this node value as an integer in my next part of my program.. is t possib?

            K L 2 Replies Last reply
            0
            • L Luckie

              Great Job Mr.Mike.. A single line of code is enough..Littl confused now. :-( Like.... int XP = somthing.Convert.toint32(X) u said that x is not an integer,.. But i want to use this node value as an integer in my next part of my program.. is t possib?

              K Offline
              K Offline
              KaptinKrunch
              wrote on last edited by
              #6

              Take a look at int.TryParse() and int.Parse();

              Just because we can; does not mean we should.

              1 Reply Last reply
              0
              • L Luckie

                Great Job Mr.Mike.. A single line of code is enough..Littl confused now. :-( Like.... int XP = somthing.Convert.toint32(X) u said that x is not an integer,.. But i want to use this node value as an integer in my next part of my program.. is t possib?

                L Offline
                L Offline
                led mike
                wrote on last edited by
                #7

                Shan85 wrote:

                u said that x is not an integer,.. But i want to use this node value as an integer in my next part of my program.. is t possib?

                You posted an XPath statement, we can't tell from that what your XML looks like. If you don't post a XML fragment with this 'X' node containing an integer value, we can't give you a specific code example for it. In my previous reply I posted an XML fragment to go with the code that obtains the value from it.

                led mike

                L 1 Reply Last reply
                0
                • L led mike

                  Shan85 wrote:

                  u said that x is not an integer,.. But i want to use this node value as an integer in my next part of my program.. is t possib?

                  You posted an XPath statement, we can't tell from that what your XML looks like. If you don't post a XML fragment with this 'X' node containing an integer value, we can't give you a specific code example for it. In my previous reply I posted an XML fragment to go with the code that obtains the value from it.

                  led mike

                  L Offline
                  L Offline
                  Luckie
                  wrote on last edited by
                  #8

                  i got it Mike...Thanks.. Pls clear my next doubt.. I have retrieved the value from an XML file... wen a button is clicked.. a new form opens with a text box.. i want the value of the XML node to be displayed in the text box... say..CropX is the integer.. tbX is the name of the text box.. How can i do that.. When the form,is initialised, the text box should be initiated with the cropX value.. pls help me lik previous time Mike..Awaiting for ur reply

                  L 1 Reply Last reply
                  0
                  • L Luckie

                    i got it Mike...Thanks.. Pls clear my next doubt.. I have retrieved the value from an XML file... wen a button is clicked.. a new form opens with a text box.. i want the value of the XML node to be displayed in the text box... say..CropX is the integer.. tbX is the name of the text box.. How can i do that.. When the form,is initialised, the text box should be initiated with the cropX value.. pls help me lik previous time Mike..Awaiting for ur reply

                    L Offline
                    L Offline
                    led mike
                    wrote on last edited by
                    #9

                    XmlNode node = doc.SelectSingleNode("//Image/Crop/X");
                    myTextBox.Text = node.InnerText;

                    led mike

                    L 1 Reply Last reply
                    0
                    • L led mike

                      XmlNode node = doc.SelectSingleNode("//Image/Crop/X");
                      myTextBox.Text = node.InnerText;

                      led mike

                      L Offline
                      L Offline
                      Luckie
                      wrote on last edited by
                      #10

                      Thank u Mike.. Got the answer yesterday itself.. But forgot to reply you..sorry.. And a big thanks.. :)

                      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