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: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
    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



::DISCLAIMER::
----------------------------------------------------------------------------------------------------------------------------------------------------

The contents of this e-mail and any attachment(s) are confidential and intended for the named recipient(s) only.
E-mail transmission is not guaranteed to be secure or error-free as information could be intercepted, corrupted,
lost, destroyed, arrive late or incomplete, or may contain viruses in transmission. The e mail and its contents
(with or without referred errors) shall therefore not attach any liability on the originator or HCL or its affiliates.
Views or opinions, if any, presented in this email are solely those of the author and may not necessarily reflect the
views or opinions of HCL or its affiliates. Any form of reproduction, dissemination, copying, disclosure, modification,
distribution and / or publication of this message without the prior written consent of authorized representative of
HCL is strictly prohibited. If you have received this email in error please delete it and notify the sender immediately.
Before opening any email and/or attachments, please check them for viruses and other defects.

----------------------------------------------------------------------------------------------------------------------------------------------------

_______________________________________________
General mailing list
[email protected]
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to