assert test can't find node
This should cover W3C XML Schema, Relax NG and DTD related problems.
-
- Posts: 2
- Joined: Fri Mar 31, 2017 10:35 pm
assert test can't find node
Post by adampearlman »
I am using the OxygenXML editor to validate an XML document using XSD.
I am using assert in the XSD document.
However, I am unable to reference any nodes in my XML document in the assert test.
I've set my XSD to v1.1 and I can successfully validate the document if my assert simply returns true (<xs:assert test="true()"/>).
Furthermore, if I run the test as XPATH 2.0 in the XML document, it successfully returns a result.
Why can't I get my assert test to recognize the XML node?
I'm looking for the <type> node in the test. This is the error I get:
XML and XSD below.
I'm a XSD newb. Please help, thanks!
This is my XML. (The real version has many <item> nodes.)
This is my XSD. The assert is towards the bottom. (The actual test will be more complex, but I can't even get this to work at the moment. )
I am using assert in the XSD document.
However, I am unable to reference any nodes in my XML document in the assert test.
I've set my XSD to v1.1 and I can successfully validate the document if my assert simply returns true (<xs:assert test="true()"/>).
Furthermore, if I run the test as XPATH 2.0 in the XML document, it successfully returns a result.
Why can't I get my assert test to recognize the XML node?
I'm looking for the <type> node in the test. This is the error I get:
Code: Select all
cvc-assertion: Assertion evaluation ('type='Undergraduate'') for element 'item' on schema type '#AnonType_itemitems' did not succeed.
I'm a XSD newb. Please help, thanks!
This is my XML. (The real version has many <item> nodes.)
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<items
xmlns="http://magazine.babson.edu"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://magazine.babson.edu http://magazine.babson.edu/nnn.xsd">
<item>
<type>Undergraduate</type>
<year>1963</year>
<name>Mark Adler</name>
<issue>Summer 2013</issue>
<content><![CDATA[<b>Mark Adler</b> is CEO of M. Adler’s Son Inc. (mascoimports.com), importers and distributors of florist supplies. He emails, “My wife, Betsy, and I live in Raleigh, N.C. We relocated the business from New York in 2004, and our staff relocated, too. My son, Alec, is the fifth generation to work in our business. Unfortunately, I cannot attend reunion because I will be in Asia to set up purchases for 2014.”]]></content>
<image />
</item>
</items>
Code: Select all
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://magazine.babson.edu"
xmlns="http://magazine.babson.edu" elementFormDefault="qualified" vc:minVersion="1.1"
xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning">
<xs:element name="items">
<xs:complexType>
<xs:sequence>
<xs:element name="item" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="type">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="Undergraduate"/>
<xs:enumeration value="Graduate"/>
<xs:enumeration value="Weddings"/>
<xs:enumeration value="In Memoriam"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="year" nillable="true">
<xs:simpleType>
<xs:union>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:length value="0"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="1919"/>
<xs:maxInclusive value="2017"/>
</xs:restriction>
</xs:simpleType>
</xs:union>
</xs:simpleType>
</xs:element>
<xs:element name="name">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
<xs:maxLength value="255"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="issue" type="xs:string" fixed="Summer 2013"/>
<xs:element name="content">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="image" type="xs:string"/>
</xs:sequence>
<xs:assert test="type='Undergraduate'"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Re: assert test can't find node
Hello,
You need to add a namespace declaration on you schema root, something like this: xmlns:b="http://magazine.babson.edu"
Then change the assert to use the declared prefix, something like this: <xs:assert test="b:type='Undergraduate'"/>
Best Regards,
Octavian
You need to add a namespace declaration on you schema root, something like this: xmlns:b="http://magazine.babson.edu"
Then change the assert to use the declared prefix, something like this: <xs:assert test="b:type='Undergraduate'"/>
Best Regards,
Octavian
Octavian Nadolu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 2
- Joined: Fri Mar 31, 2017 10:35 pm
Re: assert test can't find node
Post by adampearlman »
First, huge thanks. This worked!
Second, why is the specific namespacing necessary if I have a default namespace declared?
Second, why is the specific namespacing necessary if I have a default namespace declared?
Re: assert test can't find node
Hello,
The namespace scope of the path elements in the assertion expression is determined by the value of the xpathDefaultNamespace attribute. If the attribute is absent, its value is assumed to be ##local - which translates into null namespace. This attribute can also be declared to hold any URI, or alternatively configured to use the targetNamespace or the default namespace declared for the XML Schema.
Therefore, if you don't want to use a prefix you need to add the xpathDefaultNamespace="http://magazine.babson.edu" on the assert element or on the schema root.
Best Regards,
Octavian
The namespace scope of the path elements in the assertion expression is determined by the value of the xpathDefaultNamespace attribute. If the attribute is absent, its value is assumed to be ##local - which translates into null namespace. This attribute can also be declared to hold any URI, or alternatively configured to use the targetNamespace or the default namespace declared for the XML Schema.
Therefore, if you don't want to use a prefix you need to add the xpathDefaultNamespace="http://magazine.babson.edu" on the assert element or on the schema root.
Best Regards,
Octavian
Octavian Nadolu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service