Groups | Blog | Home
all groups > dotnet xml > april 2005 >

dotnet xml : help with SelectSingleNode


buildweb NO[at]SPAM infinito.it
4/14/2005 1:22:04 AM
Hi, I've xml file like this:

<?xml version="1.0" encoding="utf-8" ?>
<strings>
<component name="commesse">
<form name="dettagli">
<data name="open" description="">Open</data>
<data name="close" description="">Close</data>
<data name="exit" description="">Exit</data>
</form>
<form name="inserisci">
<data name="open" description="">Open</data>
<data name="close" description="">Close</data>
<data name="exit" description="">Exit</data>
</form>
</component>
</strings>

I would like to know value with 3 coordinates, for example

component name="commesse"
form name="inserisci"
data name="close"

then Value should be "Close"

I try using SelectSingleNode method, but I've problem:

string path = @"component name="commesse"/form name="inserisci"
/data name="close"";
XmlNode xmlNode = xmlDocument.DocumentElement.SelectSingleNode(path);

but this trow exception like path not found

Does anybody can helm me?

Oleg Tkachenko [MVP]
4/14/2005 12:31:15 PM
[quoted text, click to view]

It's
component[@name='commesse']/form[@name='inserisci']/data[@name='close']


--
Oleg Tkachenko [XML MVP, MCP]
Edo
4/15/2005 12:00:00 AM
Thanks a lot, but it seems not good, XmlNode is null after SelectSingleNode

this is my code:

xmlDocument = new XmlDocument();

xmlDocument.Load(filePath);

string path =
"component[@name='commesse']/form[@name='inserisci']/data[@name='close']";

XmlNode xmlNode = xmlDocument.DocumentElement.SelectSingleNode(path);

MessageBox.Show(xmlNode.InnerText);



Can you help me?

Thanks really, edo



[quoted text, click to view]

buildweb NO[at]SPAM infinito.it
4/15/2005 12:44:54 AM
Really thanks, bu it seem not good, XmlNode is undefined after
SelectSingleNode

this is my code:

xmlDocument = new XmlDocument();
xmlDocument.Load(filePath);
string path = "component[@name='commesse']/form[@name='inserisci']/data[@name='close']";
XmlNode xmlNode = xmlDocument.DocumentElement.SelectSingleNode(path);
MessageBox.Show(xmlNode.InnerText); // here throw exception null
object

Can you help me?
Thanks a lot,
Edo


[quoted text, click to view]
Oleg Tkachenko [MVP]
4/17/2005 12:00:00 AM
[quoted text, click to view]

Sorry, works for me. Make sure your XML is the same you have posted before.

--
Oleg Tkachenko [XML MVP, MCP]
AddThis Social Bookmark Button