I simply want to return the count of a condition in an XML file using XPath.
My XPath expression works fine and have tested in XML Spy and it returns the right count but when I evaluate the expression, it always returns 0.
Dim xpd As New XPathDocument(strFileName)
Response.Write(fi.Name & "<br/>")
Dim xpn As XPathNavigator = xpd.CreateNavigator
Dim intCount As Int32 = xpn.Evaluate("count(Expression)")
Response.Write(fi.Name & "<br/>")
Only ever had to return a node set before. Am I going about returning a single value in the right way?
Any thoughts?
Chris
ASP.NETC#Visual Basic.NET
Last Comment
cmhunty
8/22/2022 - Mon
Carl Tawn
If your expression returns a node-set then you may as well just return it into an XmlNodeList object and use the Count (or Length, can't remember which) property to get the number.
Thanks but still giving 0. I'm beginning to think it may be a problem with my XPath string even though it returns a proper count in XML Spy.
XPath:
count(//System/Payload/StaticEvent/ChargeCodeInst[contains(Code,'PHLX9994')])
TheLearnedOne - I'll give you the points as you've confirmed that I'm going about getting the result in the correct method. I think the problem must be somewhere else.
The problem seems to be because the schema location is not valid. Wouldn't have thought this would be required for XPath query? No exceptions are thrown, XPath queries just don't work! Could this be a bug?
Anyway, back to finding a way of sorting this.............