assert test can't find node
Posted: Fri Mar 31, 2017 11:42 pm
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>