XPath expression -- problem with namespace

Having trouble installing Oxygen? Got a bug to report? Post it all here.
kilhor
Posts: 15
Joined: Thu Jun 10, 2004 1:51 pm
Location: ETH Zurich, Switzerland

XPath expression -- problem with namespace

Post by kilhor »

I have no idea what is wrong here. Consider this XML Schema

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright P&P Software GmbH (Zurich, Switzerland) -->
<xs:schema
targetNamespace="http://www.pnp-software.com/fmt/fm"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:dm="http://www.pnp-software.com/fmt/displayModel"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xs:element name="FeatureNode">
<xs:complexType dm:displayType="node">
<xs:choice>
<xs:element name="foo">
<xs:complexType>
<xs:choice>
<xs:element name="bar" type="xs:string"/>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
If I write this //xs:element[xs:complexType[@*='node']] XPath expression to the XPath "comboBox" it corectly returns /xs:schema[1]/xs:element[1]. However if I change "*" for "dm:displayType" i.e. use the XPath expression //xs:element[xs:complexType[@dm:displayType='node'] Oxygen reports the following: Invalid XPath expression Prefix must resolve to a namespace dm:

Can anyone provide me with some hint?
Thanks a lot!

K!lhor
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Post by george »

Hi,

Oxygen detects only the prefixes used in elements when it evaluates XPath expressions. To workaround this you can add an annotation and use a dummy element from that namespace inside appinfo:

<xs:schema targetNamespace="http://www.pnp-software.com/fmt/fm"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:dm="http://www.pnp-software.com/fmt/displayModel"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:annotation>
<xs:appinfo>
<dm:test/>
</xs:appinfo>
</xs:annotation>
...

Another workaround is to check only the local name:

//xs:element[xs:complexType[@*[local-name()='displayType']='node']]

Best Regards,
George
Post Reply