Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - Re: RegEx not right in my XmlSchema >Thread Next - Re: RegEx not right in my XmlSchema Re: RegEx not right in my XmlSchemaTo: NULL Date: 10/1/2007 6:01:00 AM "Bjoern Hoehrmann" wrote: > It is neither good practise nor generally possible to distinguish be- > tween these cases, certainly not in XML Schema. In short, what you seem > to be trying to do cannot be made to work. Thanks for your reply Bjoern, however, maybe a little background on the issue might help. What we are trying to achieve is validation against an XmlSchema who has an element declaration for a particular node requiring content of the following format <![CDATA[ html markup goes here ]]> If the Xml document does not contain such content for the named element then the document is deemed to be invalid. ... we are passing Xml to an Adobe Flash ActionScript object, it expects the xml in the following format <someElement> <content><![CDATA[ <P>my <B>html</B> goes here</P> ]]></content> </someElement> and we want to validate the Xml PRIOR to it being transmitted to the ActionScript object. We can do this using the XmlSchema <?xml version="1.0" encoding="utf-8" ?> <xs:schema targetNamespace="http://uri/test.xsd" elementFormDefault="qualified" xmlns="http://uri/test.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="root"> <xs:complexType> <xs:choice maxOccurs="unbounded"> <xs:element name="cd" type="CDATAContentElementType" /> </xs:choice> </xs:complexType> </xs:element> <xs:simpleType name="CDATAContentElementType"> <xs:restriction base="xs:string"> <xs:pattern value="\& lt;\!\[CDATA\[\s*(\d*|\w*|\W*|\s*|.*|>*)*\s*\]\]\& gt;" /> </xs:restriction> </xs:simpleType> </xs:schema> and the data ... <root xmlns="http://uri/test.xsd"> <cd>& lt;![CDATA[ <P>my <B>html</B> goes here</P> ]]& gt;</cd> </root> However, because the CDATA section declaration is escaped, the contents are not treated as a CDATA section per se, and the schema is then called upon to further validate the contents of the faux CDATA section (not required behaviour). If the above xml were written without escaping the CDATA section declaration <root xmlns="http://uri/test.xsd"> <cd><![CDATA[ <P>my <B>html</B> goes here</P> ]]></cd> </root> the contents of that CDATA section are themselves not parsed during Schema validation (required behaviour) ******************** * SOLUTION DISCOVERED * ******************** The solution appears to be ... defining the content element as follows: <xs:simpleType name="CDATAContentElementType"> <xs:restriction base="xs:string"> <xs:pattern value="\s*(\d*|\w*|\W*|\s*|.*|>*)*\s*" /> </xs:restriction> </xs:simpleType> i.e. leave the <![CDATA[ ]]> part out of the RegEx pattern. I have discovered that the VisualStudio IDE itself indicates that the CDATA declaration might be necessary. Therefore using the VS IDE we have the following successfully validated against the Schema <cd><![CDATA[ <P>my <B>html</B> goes here</P> ]]></cd> <cd>something here</cd> which is fine in our particular case (because we are dealing with text that may or may not be html markup-ed), and the Schema disallows <cd><P>my <B>html</B> goes here</P></cd> So, again (though not the response I was looking for) thanks for your reply -- Of all words of tongue and pen, the saddest are: "It might have been" Bill.Richards @ greyskin .co .uk http://greyskin.co.uk | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
