Groups | Blog | Home
all groups > dotnet xml > september 2004 >

dotnet xml : XPath query problem.



Johan Smidje
9/21/2004 5:01:03 AM
Hi.
I'm trying to locate one node in the following XML:
<?xml version="1.0" encoding="utf-8" ?>
<ROUTINES>
<ROUTINE name="TA14">
<METHOD name="1">
<DEBET>
<SUBROUTINE name="1401"></SUBROUTINE>
<SUBROUTINE name="1402"></SUBROUTINE>
<SUBROUTINE name="1408"></SUBROUTINE>
</DEBET>
<CREDIT>
<SUBROUTINE name="1403"></SUBROUTINE>
<SUBROUTINE name="1404"></SUBROUTINE>
<SUBROUTINE name="1409"></SUBROUTINE>
</CREDIT>
</METHOD>
</ROUTINE>
</ROUTINES>

Why doesn't the following query find the subroutine node with attribute
name=TA1401

tempNode =
mVoRoutines.SelectSingleNode("ROUTINES/ROUTINE[@name='TA14']/METHOD[@name='1']/DEBET/SUBROUTINE[@name='1401']")

I can find it's parent node by:
tempNode =
mVoRoutines.SelectSingleNode("ROUTINES/ROUTINE[@name='TA14']/METHOD[@name='1']/DEBET")

Martin Honnen
9/21/2004 2:43:52 PM


[quoted text, click to view]


[quoted text, click to view]

Using the following C# .NET 1.1 code an element node is found:

XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(@"test2004092101.xml");
XmlElement subroutine = (XmlElement)
xmlDocument.SelectSingleNode("ROUTINES/ROUTINE[@name='TA14']/METHOD[@name='1']/DEBET/SUBROUTINE[@name='1401']");
if (subroutine != null) {
Console.WriteLine("Found {0}.", subroutine);
}
else {
Console.WriteLine("No node found.");
}

If your code doesn't find the node I assume that mVoRoutines is not the
document node (root node).

--

Martin Honnen
AddThis Social Bookmark Button