I got a specific xml data below
<l7:ApiPlans xmlns:l7="http://ns.xcompany.com/2012/04/api-management">
<l7:ApiPlan>
<l7:PlanPolicy>
<wsp:Policy xmlns:L7p="http://www.xcompany.com/ws/policy" xmlns:wsp="http://schemas.xmlsoap.org/ws/2002/12/policy">
<wsp:All wsp:Usage="Required">
<wsp:All wsp:Usage="Required">
...... some other welformed xml
</wsp:All>
</wsp:All>
</wsp:Policy>
</l7:PlanPolicy>
</l7:ApiPlan>
</l7:ApiPlans>
That I need to write an XSD (if possible) to validate that PlanPolicy starts with
<wsp:Policy xmlns:L7p="http://www.xcompany.com/ws/policy"
xmlns:wsp="http://schemas.xmlsoap.org/ws/2002/12/policy">
<wsp:All wsp:Usage="Required">
<wsp:All wsp:Usage="Required">
and ends with
</wsp:All>
</wsp:All>
</wsp:Policy>
So far I have this,
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://ns.xcompany.com/2012/04/api-management" xmlns:l7="http://ns.xcompany.com/2012/04/api-management">
<xs:element name="ApiPlans">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" ref="l7:ApiPlan"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="ApiPlan">
<xs:complexType>
<xs:sequence>
<xs:element ref="l7:PlanPolicy"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="PlanPolicy" type="policyDataType"/>
<simpleType name="policyDataType">
<restriction base="xs:string">
<minLength value="1"></minLength>
<pattern value="(<).*(>).*(<).*(>)"></pattern>
</restriction>
</simpleType>
</xs:schema>
Is that possible? And as a side question, How do you define in pattern: new lines(CR/LF), tab and quotes.
Thanks in advance
Yes, it is definitely possible, and regular expressions are about your only option with this untypical task. Note that the escaped content will not be processed as XML, but rather as a string.
Be sure to read how to properly escape various special characters, including parentheses, in the regular expression.
Newline and tab are represented by
\nand\tm respectively.Quotes can be entered by doubling them up.