Groups | Blog | Home
all groups > dotnet xml > may 2006 >

dotnet xml : Error selecting nodes


Dhanvanth
5/31/2006 2:47:39 PM
[quoted text, click to view]

Your XPATH ("/root/Prov/[@Abrev='" + strProv + "']/Postals is
incorrect. @ is used to denote attributes, not elements. But according
to your xml Abrev is an element, not an attribute.

If you need to select the Postal nodes under Prov which has Abrev=
strProv then your XPATH needs to be

/root/Prov[Abrev='" + strProv + "']/Postals

-Dhanvanth
barbaraann
5/31/2006 2:56:56 PM
I am new to dotnet and I am having trouble reading an xml file.
"The expression passed to this method should result in a NodeSet."

Here is my xml file:

<?xml version="1.0" encoding="Windows-1252" ?>
<root>
<Prov>
<Abrev>AB</Abrev>
<Postals>
<Postal>T</Postal>
</Postals>
</Prov>
<Prov>
<Abrev>BC</Abrev>
<Postals>
<Postal>V</Postal>
</Postals>
</Prov>
....
<Prov>
<Abrev>ON</Abrev>
<Postals>
<Postal>K</Postal>
<Postal>L</Postal>
<Postal>M</Postal>
<Postal>N</Postal>
<Postal>P</Postal>
</Postals>
</Prov>
</root>

I want to read through it for the Abrev and get all the Postal values for it.
I load my file into an xml document and use

XmlNodeList nodeList = xml.SelectNodes("/root/Prov/[@Abrev='" + strProv +
"']/Postals");

to retrieve the node for the variable passes to this function.
Is my syntax incorrect or my xml baddly formed or am I just barking up the
wrong tree?

barbaraann
6/1/2006 6:43:42 AM
AddThis Social Bookmark Button