我需要为CodeSynthesis的XSD生成一个xsd文件。对于不同的响应类型,将有多个模式。正如您在示例XML文件中看到的,有些元素有type属性,有些元素没有nil属性。这些属性不提供解析信息,我已经知道类型并在xsd文件中正确设置了它们。除此之外,我不知道哪些元素是nillable。这些属性是否可以在xsd模式中以某种方式跳过,或者我应该为每个元素编写:
<xsd:complexType>
<xsd:attribute name="type" type="TypeAttr" fixed="integer"/>
<xsd:attribute ref="nil"/>
</xsd:complexType>哪里
<xsd:attribute name="nil" type="xsd:boolean"/>这是其中一个XML文件:
<?xml version="1.0" encoding="UTF-8"?>
<account>
<access-key>bla-bla-bla</access-key>
<billing-error-date type="date" nil="true"></billing-error-date>
<default-ticket-report-id type="integer">0</default-ticket-report-id>
<default-time-zone nil="true"></default-time-zone>
<description nil="true"></description>
<disk-usage type="integer">38048</disk-usage>
<flagged-for-billing-error type="boolean">false</flagged-for-billing-error>
<force-ssl type="boolean">false</force-ssl>
<id type="integer">1</id>
<plan>micro</plan>
<subdomain>companyname</subdomain>
<text-markup>markdown,textile,plain</text-markup>
<title>companyname</title>
<features>
<attachments>true</attachments>
<ssl>false</ssl>
<storage>512</storage>
<time_tracking>false</time_tracking>
<max_people>10</max_people>
<max_pages>99999</max_pages>
<beta>false</beta>
</features>
<notebook_pages>0</notebook_pages>
<created-at>2011-02-16T13:50:09Z</created-at>
<updated-at>2011-04-07T09:11:10Z</updated-at>
</account>发布于 2011-04-08 10:17:19
我使用以下代码添加了类型和nil属性支持。
<xsd:complexType name="UString">
<xsd:simpleContent>
<xsd:extension base="xsd:string">
<xsd:attribute name="type" type="TypeAttr" fixed="string" use="optional"/>
<xsd:attribute name="nil" type="xsd:boolean" use="optional"/>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
<xsd:complexType name="UInteger">
<xsd:simpleContent>
<xsd:extension base="xsd:integer">
<xsd:attribute name="type" type="TypeAttr" fixed="integer" use="optional"/>
<xsd:attribute name="nil" type="xsd:boolean" use="optional"/>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
<xsd:simpleType name="TypeAttr">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="datetime"/>
<xsd:enumeration value="integer"/>
<xsd:enumeration value="boolean"/>
</xsd:restriction>
</xsd:simpleType>https://stackoverflow.com/questions/5581101
复制相似问题