Click here to Skip to main content
15,889,335 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
Please tell me how to read version innertext(i.e "1.0.0.0") using Xpath for the below xml
XML
<package>
  <workflowprocesses>
    <workflowprocess>
    </workflowprocess>
    <workflowprocess>
      <activites>
          <activity>
             <version>1.0.0.0</version>
          </activity>
      </activites>
    </workflowprocess>
  </workflowprocesses>
</package>
Posted
Updated 8-Aug-11 6:09am
v2
Comments
Fredrik Bornander 8-Aug-11 12:10pm    
Fixed xml formatting.

There are some excellent XPath tutorials over here[^] that'll show you just about everything you need to know.

I think that something like this might do the trick for you;

XML
using System;
using System.IO;
using System.Xml.XPath;
namespace Sandbox
{
    class Program
    {
        static void Main(string[] args)
        {
            string xml = "<package><workflowprocesses><workflowprocess></workflowprocess><workflowprocess><activites><activity><version>1.0.0.0</version></activity></activites></workflowprocess></workflowprocesses></package>";

            XPathDocument document = new XPathDocument(new StringReader(xml));
            XPathNavigator navigator = document.CreateNavigator();
            XPathNodeIterator versionList = navigator.Select("/package/workflowprocesses/workflowprocess/activites/activity/version");
            foreach (XPathNavigator versionElement in versionList)
            {
                string version = versionElement.Value;
                Console.WriteLine("Version=[{0}]", version);
            }
        }
    }
}

Hope this helps,
Fredrik
 
Share this answer
 
v2
i don't know how many child node "workflowprocess" in your xml file, but... if you want to get "1.0.0.0" in that xml file, here is your XPath:

/package/workflowprocesses/workflowprocess[last()]/activites/activity/version
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900