|
Hi Melkis,
If you make direct changes inside the xsd file, it will not work. No need to place your change directly inside the xsd file. Place your changes inside the xml schematron file and then compile it in query console using sch:compile-schema() function of schematron.xqy
file. It will generate a compiled xsd file and then use this file against the xml file, which you want to validate.
Regards,
Asit Nautiyal
From: [email protected] [[email protected]] on behalf of Melkis Penyameen Sathak Jebarathinam [[email protected]]
Sent: Friday, May 29, 2015 5:58 PM To: [email protected] Subject: [MarkLogic Dev General] Embedding Schematron inside XSD and validating a xml document against that XSD Hi,
I want to embed a Schematron validation (which allows Xpath) in XSD. Example below is to validate "subjectLevel" element. First subjectLevel" element should have the value "Yes" and "subjectLevel" element other than the first position should have value
"No". I tried using "xs:annotation" to embed Schmatron rules in XSD but while validating the xml against that XSD, I am not getting Schematron validation error.
Please let me know if there is any other approach of doing this kind of Schematron validation inside XSD.
--------------------------------------------------------------------------------
> ***XML to validate:***
--------------------------------------------------------------------------------
<correlationResponse>
<correlationElement>
<subjectLevel>No</subjectLevel>
</correlationElement>
<correlationElement>
<subjectLevel>Yes</subjectLevel>
</correlationElement>
</correlationResponse>
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
> ***Schematron:***
--------------------------------------------------------------------------------
<schema
schemaVersion = "3.3.1"
xmlns = "http://purl.oclc.org/dsdl/schematron"
xmlns:s = "http://purl.oclc.org/dsdl/schematron"
xmlns:dp = "http://www.dpawson.co.uk/ns#">
<pattern>
<title>subjectLevel value based on correlationElement order</title>
<rule context = "/correlationResponse/correlationElement[position() = 1]">
<assert test = "subjectLevel = 'Yes'">subjectLevel value of first correlationElement must be "Yes"</assert>
</rule>
<rule context = "/correlationResponse/correlationElement[position() != 1]">
<assert test = "subjectLevel = 'No'">subjectLevel value other than first correlationElement must be "No"</assert>
</rule>
</pattern>
</schema>
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
> ***Schema:***
--------------------------------------------------------------------------------
<xs:schema
xmlns:xs = "http://www.w3.org/2001/XMLSchema"
elementFormDefault = "qualified"
attributeFormDefault = "unqualified">
<!--XML Schema Generated from XML Document on Fri May 29 2015 17:23:05 GMT+0530 (India Standard Time) -->
<!--with XmlGrid.net Free Online Service
http://xmlgrid.net -->
<xs:element name = "correlationResponse">
<xs:complexType>
<xs:sequence>
<xs:element name = "correlationElement" maxOccurs = "unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name = "subjectLevel" type = "xs:string"></xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
> ***Solution tried***
--------------------------------------------------------------------------------
<xs:annotation>
<xs:appinfo>
<sch:pattern>
<sch:title>subjectLevel value based on correlationElement order</sch:title>
<sch:rule abstract = "false" context = "/correlationResponse/correlationElement[position() = 1]">
<sch:assert test = "subjectLevel = 'Yes'">subjectLevel value of first correlationElement must be "Yes" .</sch:assert>
</sch:rule>
<sch:rule abstract = "false" context = "/correlationResponse/correlationElement[position()!= 1]">
<sch:assert test = "subjectLevel = 'No'">subjectLevel value other than first correlationElement must be "No" .</sch:assert>
</sch:rule>
</sch:pattern>
</xs:appinfo>
</xs:annotation>
--------------------------------------------------------------------------------
Thanks,
Melkis Penyameen Sathak J
Associate - Projects
Cognizant Technology Solutions
The contents of this e-mail and any attachment(s) are confidential and intended for the named recipient(s) only. ---------------------------------------------------------------------------------------------------------------------------------------------------- |
_______________________________________________ General mailing list [email protected] Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general
