Search code examples
xmlxsdxsd-validationxml-validation

XSD / XML quote escaping


I need to create XSD document with restriction so that we only allow the following values in the XML element.

3"
30"
5" x 18"
4" X 12"
Other

I started creating an element with restriction with enumeration but I do not know how to specify quotes in the enumeration. I tried adding restriction with &quote;, '"', \" but nothing is working.

<xs:element name="Diameter">
  <xs:simpleType>
    <xs:restriction base="xs:string">
      <xs:enumeration value="3&quote;" />
      <xs:enumeration value="30&quote;" />
      <xs:enumeration value="5&quote; x 18&quote;" />
      <xs:enumeration value="4&quote; x 12&quote;" />
      <xs:enumeration value="other" />
    </xs:restriction>
  </xs:simpleType>
</xs:element>

Solution

  • Use &quot;, not &quote;

    Alternatively, use ' ... ' to deliminate the attribute values, then " internally:

      <xs:enumeration value='3"' />