Check InnterText value in XMLDocument

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • E11esar
    New Member
    • Nov 2008
    • 132

    Check InnterText value in XMLDocument

    Hi there.

    I have written an application which returns an XmlDocument which has several nodes. What I am looking to do is display the InnerText value of one of these specific nodes but I cannot get this to work at all.

    I have tried Googling this but none of the results so far have worked, so any help would be most appreciated please?

    In my code, I create an XmlDocument and assign it to a returned result from a method which makes a call to an external process:

    e.g.

    Code:
     
    XmlDocument xmlDoc = SomeExternalWebService("123");           
     
    txtXMLString.Text = anInnterText_value_returned_xml;
    Hence I am looking to find out how to parse the InnerText value which will only occur for one of the nodes, so this node is uniquely named.

    Ultimately I want to test this InnerText value within an If-Condition and take action accordingly but any help will be so much appreciated.

    Thank you.

    Mark
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    if your programming language supports the DOM, you can use its Node.textConten t or CharacterData.d ata properties.

    Comment

    • E11esar
      New Member
      • Nov 2008
      • 132

      #3
      Hi there. I am coding in C# but will look up what you have suggested. I am also thinking that maybe Linq to XML might help me, but this is all new to me.
      Thank you.

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        ultimately, you would have to look up in the C# documentation, how XML data are handled (be it through DOM or otherwise)

        Comment

        • E11esar
          New Member
          • Nov 2008
          • 132

          #5
          Yes I have done that but all the suggestions have not worked for me. I thought this would take about an hour to accomplish, so far I have worked on this for over a month now!

          It really is getting silly as it can't be this hard to achieve.

          Thank you.

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            Moving to C# forum, maybe the guys here have a better idea than me.

            Comment

            • GaryTexmo
              Recognized Expert Top Contributor
              • Jul 2009
              • 1501

              #7
              First off, maybe give your spelling a check. I'm pretty sure you're after the InnerText object, but you've written InnterText more than once. Can you please confirm?

              Anyway, I'm pretty sure you mean the InnerText object on an XmlNode object. An XmlDocument object has a property called DocumentElement , which is the root node for your XML structure. You can start your processing there and then go through all the XmlNodes in DocumentElement 's ChildNodes property.

              At any point, you can then inspect the InnerText property.

              I'm not entirely sure if that answers your question. If it doesn't, can you please clarify?

              Comment

              • E11esar
                New Member
                • Nov 2008
                • 132

                #8
                Hi there. Yup I meant InnerText - just been a long night and day with this, thank you.

                I have finally cracked the solution with this. One of those slap palm on forehead moments as I had literally written the answer several times in my code.

                I wasn't quoting the correct web uri within my xml namespace definition so my code was somewhat suspect.

                I've taken a step back and followed the example as highlighted via MSDN:



                i.e.
                Code:
                 
                XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
                 nsmgr.AddNamespace("ab", "http://www.lucernepublishing.com");
                 XmlNode book = doc.SelectSingleNode("//ab:book", nsmgr);
                So all working now.

                Thank you for your help.

                M :)

                Comment

                Working...