Pages

Search This Blog

Monday, March 14, 2011

XmlValidatingReader validator does not allow an element having an attribute as well as inner text value. How to make it working?

Problem I faced was that I was trying to validate an XML document with an XSD file. Each time I run the XmlValidatingReader class to validate the XML aginst the XSD at the TranslationSettings elements raises validation error "The element cannot contain text. Content model is empty". I found that this issue is occuring because of TranslationSettings element which contains an attribute as well as inner text value.

To resolve this issue just modify the xsd file as below:

<xs:element name="TranslationSettings">
 <xs:complexType>
  <xs:sequence>
   <xs:element name="Language" minOccurs="0" maxOccurs="unbounded">
    <xs:complexType>
     <xs:simpleContent>
      <xs:extension base="xs:string">
       <xs:attribute name="LanguageKey" type="xs:string">
       </xs:attribute>
      </xs:extension>
     </xs:simpleContent>
    </xs:complexType>
   </xs:element>
  </xs:sequence>
 <xs:attribute name="Enabled" type="xs:boolean"></xs:attribute>
 </xs:complexType>
</xs:element>

Earlier I was using the below attached XSD:

<xs:element name="TranslationSettings">
 <xs:complexType>
  <xs:sequence>
   <xs:element name="Language" minOccurs="0" maxOccurs="unbounded">
    <xs:complexType>
     <xs:attribute name="LanguageKey" type="xs:string"></xs:attribute>
    </xs:complexType>
   </xs:element>
 </xs:sequence>
<xs:attribute name="Enabled" type="xs:boolean"></xs:attribute>
</xs:complexType>
</xs:element>


Thanks

No comments:

Post a Comment