RHPT
RHPT

Reputation: 2650

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.

While 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?

Upvotes: 1

Views: 534

Answers (3)

Sergey Galashyn
Sergey Galashyn

Reputation: 6956

Something like numReviews = XmlSearch(mydoc, "/:Feed/:Product/:NumReviews"); also should work when there are namespaces.

Upvotes: 6

Raymond Camden
Raymond Camden

Reputation: 10857

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.

Upvotes: 4

Jason Dean
Jason Dean

Reputation: 9615

You are using backslashes in the first example. They should be frontslashes, right?

Upvotes: 0

Related Questions