teja_98666
teja_98666

Reputation: 95

VB.Net Xpath Error: Expression must evaluate to a node-set.

I have xml data with node name as a numeric value and i need to retrieve the node with that name.

when i use the below code it throws the exception "Expression must evaluate to a node-set."

Code:

`lSampleXml.SelectSingleNode("//" & lClass.Name)`

where lClass.Name is a numeric value = 6556 casted into string.

Please help to get rid of the exception.

Sample XML :

<Root>
   <6556>
     <Data> </Data>
     <Text> </Text>
   </6556>
   <1223>
   </1223>
   <Phone>
   </Phone>
</Root>

Upvotes: 1

Views: 1016

Answers (1)

Martin Honnen
Martin Honnen

Reputation: 167716

Well an XML name (like an element name or attribute name) can't start with a digit so having <6556>...</6556> is not possible as well-formed XML and thus a path expression //6556 as well is not meaningful as a way to select elements of that name.

So you should get an error when trying to parse your markup sample.

Upvotes: 3

Related Questions