简体   繁体   中英

How to write an XML Schema for which this XML document is a valid instance?

<Unit Number="1">
 <Identifier Type="ABC" Text="STO0001"/>
 <Identifier Type="DEF" Text="Some Value"/>
 <Identifier Type="GHI" Text="20070805"/>
 <Disposition Unit="Accept"/>
</Unit>

I need to validate that Type="DEF" Text="Some Value" is not empty

Something Like:

<xs:complexType name="requiredValue" abstract="true"/>

<xs:complexType name="Identifier">
    <xs:complexContent>
        <xs:extension base="requiredValue">
            <xs:attribute name="Type" use="required" fixed="DEF"/>
            <xs:attribute name="Text" type="NonEmptyString"/>
        </xs:extension>
    </xs:complexContent>
</xs:complexType>

This is not exactly what you are after, but it might help you to do the bulk of the schema.

This allows you to upload a xml file and it will create a xsd schema or a DTD.

http://www.hitsw.com/xml_utilites/

This does the same sort of thing.

http://www.flame-ware.com/products/xml-2-xsd/Default.aspx

Pavel mentioned Schematron. To help construct these schemas you might like to use pyang.

http://code.google.com/p/pyang/

Using the xsd:minLength restriction:

<xsd:attribute name="Type">
  <xsd:simpleType>
    <xsd:restriction base="xsd:string">
      <xsd:minLength value="1"/>
    </xsd:restriction>
  </xsd:simpleType>
</xsd:element>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM