ianinspain
asked on
Manipulating xml with c# using xpath, a little help needed please
Hi there,
I have an xml file stored as a string in a variable.... it looks exactly like this
<t id="11" s="2" /><t id="1" s="5." />
currently there is 2 records but there will be many more..
I need to extract the contents of id and s... i.e. first record id=11 and s=2
I got so far ... just need a little help with the expression i think
XPathDocument document = new XPathDocument(xmlFields); // CAN I DO THIS WHEN ITS A STRING?
XPathNavigator navigator = document.CreateNavigator() ;
XPathNavigator expr = navigator.Compile("/t id); // ???????????
XPathNodeIterator nodes = navigator.Select(expr);
while (nodes.MoveNext())
{
// need to add each value to a local variable
}
I have an xml file stored as a string in a variable.... it looks exactly like this
<t id="11" s="2" /><t id="1" s="5." />
currently there is 2 records but there will be many more..
I need to extract the contents of id and s... i.e. first record id=11 and s=2
I got so far ... just need a little help with the expression i think
XPathDocument document = new XPathDocument(xmlFields); // CAN I DO THIS WHEN ITS A STRING?
XPathNavigator navigator = document.CreateNavigator()
XPathNavigator expr = navigator.Compile("/t id); // ???????????
XPathNodeIterator nodes = navigator.Select(expr);
while (nodes.MoveNext())
{
// need to add each value to a local variable
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks ... that worked great
XmlDocument doc = new XmlDocument();
doc.Load(filePath);
foreach (XmlNode node in doc.SelectNodes("//t"))
{
string id = node.Attributes["id"].valu
}
Bob