Navigating an XMLNode

Last post 11-05-2003 10:57 AM by hsd31. 1 replies.

Sort Posts:

  • Navigating an XMLNode

    11-05-2003, 9:55 AM
    • Member
      5 point Member
    • arrans
    • Member since 11-05-2003, 9:48 AM
    • Posts 1
    Hi,

    I have a web service accepting an XMLNode as one of its arguments.

    i.e.
    [WebMethod]
    myWebservice (XmlNode data){
    .....
    }

    The InnerXML of the node is of the form:

    <data>
    <row><myfield1></myfield1><myfield2></myfield2></row>
    <row>...</row>
    </data>

    I can easily loop through the row elements by itterating through the data.ChildNodes collection. But I cannot access any of the fields by their name. I've tried various XPath queries using selectSingleNode but to no avail.

    Can anyone give me a clue (i.e. tell me how to do it :o))

    It must be the simplest thing in the world but I can't get it to work, could it be that I need a XmlNamespaceManager that knows about my schema?

    thanks in advance.


    Arran
  • Re: Navigating an XMLNode

    11-05-2003, 10:57 AM
    • Member
      15 point Member
    • hsd31
    • Member since 11-05-2003, 5:21 AM
    • Posts 3
    Of the top of my head....

    Create an XmlDocument and append the XmlNode to it using the AppendChild method of the XmlDocument. Call the GetElementsByTagName method of the XmlDocument which will return a XmlNodeList collection. If the tag names are unique then there will be only one element in the XmlNodeList which can be accessed using the Items property and the value as xmlnodelist.Items(0).InnerText

    There might be other(better?) ways to do it. But this should get your work done. hope this helps.

    -H
Page 1 of 1 (2 items)