I have the following partial xpath expression
IAAXML:party[@xsi:type='IAAXML:Organization']
My source XML is:
<IAAXML:party xsi:type="IAAXML:Organization">
With the namespace declared as such:
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
I get the following error:
The operand types are not compatible for the = operator
How do I do a compare on that attribute using the namespace?
JLRishe has essentially given you the answer, but I'll amplify it. The
xsi:type
attribute is of type QName. In a schema-aware processor, your comparison is therefore a typed comparison between a QName and a string, which for very good reasons isn't allowed. After all, your application logic shouldn't really depend on the fact that the source document uses the namespace prefix IAAXML rather than some other prefix of the author's choosing. Given that you've got a type-aware processor, it would be better to do a QName comparison:Michael Kay more thoroughly explained the cause of this issue, but as I conjectured, certain processors treat
xsi:type
attributes as references to a schema type (which, as Michael clarified, are identified by their QName). So that's why the processor won't let you just compare it against a string value. Assuming you are using the same namespace prefix for that type's namespace in both your source document and in that string value, it sounds like this works (and should work on any processor):But Michael's suggestion to use the QName with the namespace URI would be more a more robust approach in a schema-aware processor such as yours.