SXI Forum

A place to collect usefull tips, tricks and implementation strategies.

You are not logged in.

#1 24-08-2020 12:54:19

KevinM
Moderator
Registered: 21-11-2018
Posts: 13

XPath failed due to: Cannot compare xs:Qname to xs:String

When specifying an Xpath to extract specific data from an XML document you may get a similar error to "XPath failed due to: Cannot compare xs:Qname to xs:String" (The "Qname" may differ). This is because you are trying to do a String comparison to an entity that has been defined with different type, in this case a Qname.

For Example lets say you were trying to ascertain whether or not a mapping with an id = "CollectId3" under the Action "testAction2" existed, you may be tempted to compile an xPath as follows: 

/Configuration/Actions/Action[@name='testAction2']//@id='CollectId3'

This would fail with "XPath failed due to: Cannot compare xs:Qname to xs:String" because you have given a String value but the id attribute type is actually a Qname.

To resolve this issue  you would need to do the following:

Xpath 1.0
======

/Configuration/Actions/Action[@name='testAction2']//@id=fn:string('CollectId3')

Xpath 2.0 (Not compatible with X-ServiceBroker but can be used in Stylesheets)
======

/Configuration/Actions/Action[@name='testAction2']//@id=fn:QName( 'http://www.sxi.co.za/XMLSchema/Configuration','CollectId3')

Note: If you get a fn: prefix not defined error you will need to add the fn: prefix namespace with the URI "http://www.w3.org/2005/xpath-functions"

Offline

Board footer

Powered by FluxBB