XmlSearch does not recognize xPath
I have an xml document like so
<cfxml variable="mydoc">
<?xml version="1.0" encoding="UTF-8"?>
<Feed xmlns="http://www.example.com/xs/PRR/SyndicationFeed/4.9" name="Test">
<Product id="test1" removed="false">
<Source>Widget</Source>
<ExternalId>Widget01</ExternalId>
<Name>iWidget 3G</Name>
<NumReviews>11</NumReviews>
</product>
</Feed>
</cfxml>
I want to return the NumReviews
node text. However:
numReviews = XmlSearch(mydoc, "/Feed/Product/NumReviews");
returns an empty array.
Whi开发者_JS百科le numReviews = XmlSearch(myDoc, "//*[local-name()='NumReviews']");
returns the node text.
As far as I can tell, the first line of code is correct and should return the value of NumReviews. Why is it instead returning an empty array?
Something like numReviews = XmlSearch(mydoc, "/:Feed/:Product/:NumReviews");
also should work when there are namespaces.
And it may be the name spaces. I think your second syntax is required when namespaces are involved. I know I've had to use it myself.
You are using backslashes in the first example. They should be frontslashes, right?
精彩评论