Include default values in Schema for XPath query

This should cover W3C XML Schema, Relax NG and DTD related problems.
daddyjones
Posts: 9
Joined: Wed Apr 11, 2018 4:43 pm

Include default values in Schema for XPath query

Post by daddyjones »

If an attribute is specified in my Schema as having a default value, is there a way to get the XPath query to include that value in the results? At present, my program code (which includes validation) returns 6 results from a given query, but Oxygen only returns 4 because the missing two don't have the attribute, but the Schema specifies a default value.

It would be really helpful if I could properly test my XPath before using it in code and be confident I'll get the same result...
adrian
Posts: 2855
Joined: Tue May 17, 2005 4:01 pm

Re: Include default values in Schema for XPath query

Post by adrian »

Hello,
If an attribute is specified in my Schema as having a default value, is there a way to get the XPath query to include that value in the results?
The XPath engine needs to be Schema Aware (SA) in order for this to work, so you must select either XPath 2.0 SA or XPath 3.0 SA from the XPath engine combo box in the toolbar (default is XPath 2.0).

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
daddyjones
Posts: 9
Joined: Wed Apr 11, 2018 4:43 pm

Re: Include default values in Schema for XPath query

Post by daddyjones »

That doesn't seem to make any difference. I am referring to the schema in the XML with:

Code: Select all

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.redfruit.co.uk/libgdx/wobbegong mobs.xsd"
I've tried with both 2.0 SA and 3.0 SA
adrian
Posts: 2855
Joined: Tue May 17, 2005 4:01 pm

Re: Include default values in Schema for XPath query

Post by adrian »

Hi,

1. Is the schema (mobs.xsd) available locally, in the same folder as the XML, or is there an XML catalog resolving the URI to point to its location?
2. What version of Oxygen are you using?
3. What XPath expression/query are you using?
Check if your XPath expression accounts for the namespaces.

I've tested in Oxygen v20 with the XPath //@* on one of the Oxygen samples (Oxygen/samples/personal-schema.xml). With XPath 2.0 I get all the attributes from the XML (but no defaults), with XPath 2.0 SA I also get the default attributes (person/@contr=false) from the personal.xsd schema.
If possible, please try the same on this sample.

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
daddyjones
Posts: 9
Joined: Wed Apr 11, 2018 4:43 pm

Re: Include default values in Schema for XPath query

Post by daddyjones »

Interestingly, if I use the person sample I get the same results as you. I'm using version 20.0 build 2018032903 and the xsd is in the same directory as the xml.

The XPath I'm using is:

Code: Select all

//rf:mob[@minDepth <=2]
and there are two elements without a minDepth attribute - which the schema defines as having a default of 0:

Code: Select all

<xs:attribute name="minDepth" default="0" type="xs:int"/>
adrian
Posts: 2855
Joined: Tue May 17, 2005 4:01 pm

Re: Include default values in Schema for XPath query

Post by adrian »

Hi,

I tested with an attribute of type xs:int, but XPath still works fine for me.
Perhaps the problem is within a specific context determined by the schema?

If you'd like me to have a look, please send the schema and XML to support@oxygenxml.com.
Please make sure the schema and XML do not contain confidential information. For the XML, you can use Help > Support Tools > Randomize XML text content to make the content random.

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
adrian
Posts: 2855
Joined: Tue May 17, 2005 4:01 pm

Re: Include default values in Schema for XPath query

Post by adrian »

Hi,

In case someone else encounters this, we have investigated and the XPath SA evaluation does not take into consideration default attribute values from the schema, if the XML Schema is of version 1.1 (vc:minVersion="1.1").
This has been logged on our issue tracking tool to be resolved in a future release.

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Post Reply