所以我有一个XSD文档,可以正确地验证我的XML到一定程度。只要我有另一个DatabaseName元素或Webserver元素或两者,就会出现一个错误,说明这里没有预期的元素。"不太清楚问题是什么 - 任何人都可以帮忙吗?
XML:
<?xml version="1.0" encoding="ISO8859-1" ?>
<?xml-stylesheet type="text/xsl" href="xrt.xsl"?>
<Inventory>
<DatabaseName>
<GlobalName>Tom</GlobalName>
<Function>production</Function>
<Domain>tom.info</Domain>
<Administrator EmailAlias="xrichards" Extension="221">Xavier Richards</Administrator>
<Attributes Type="Production" Version="20ix"/>
<Comments>
...
</Comments>
<Usage>
500
</Usage>
</DatabaseName>
<WebserverName>
<GlobalName>Jim</GlobalName>
<Function>distribution</Function>
<Domain>jim1235.com</Domain>
<Administrator EmailAlias="rknowles" Extension="134237">Richard Knowles</Administrator>
<Administrator EmailAlias="thoffman" Extension="222237">Tom Hoffman</Administrator>
<Attributes Type="Production" Version="20ix"/>
<Comments>
...
</Comments>
<Usage>
1200
</Usage>
</WebserverName>
<DatabaseName>
<GlobalName>Tom</GlobalName>
<Function>production</Function>
<Domain>tom.info</Domain>
<Administrator EmailAlias="xrichards" Extension="221">Xavier Richards</Administrator>
<Attributes Type="Production" Version="20ix"/>
<Comments>
...
</Comments>
<Usage>
500
</Usage>
</DatabaseName>
</Inventory>
XSD:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.yourwebsite.com" xmlns="http://www.yourwebsite.com"
elementFormDefault="qualified">
<xs:element name="Inventory">
<xs:complexType>
<xs:all>
<xs:element name="DatabaseName">
<xs:complexType>
<xs:sequence>
<xs:element name="GlobalName" type="xs:string"/>
<xs:element name="Function" type="xs:string"/>
<xs:element name="Domain" type="xs:string"/>
<xs:element name="Administrator" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="EmailAlias" type="xs:string"
use="required"/>
<xs:attribute name="Extension">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="1000"/>
<xs:maxInclusive value="9999"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="Attributes">
<xs:complexType>
<xs:attribute name="Type" type="xs:string" use="required"/>
<xs:attribute name="Version" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="20ix|29i"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="Comments" type="xs:string"/>
<xs:element name="Usage" type="xs:integer"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="WebserverName">
<xs:complexType>
<xs:sequence>
<xs:element name="GlobalName" type="xs:string"/>
<xs:element name="Function" type="xs:string"/>
<xs:element name="Domain" type="xs:string"/>
<xs:element name="Administrator" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="EmailAlias" type="xs:string"
use="required"/>
<xs:attribute name="Extension">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="1000"/>
<xs:maxInclusive value="9999"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="Attributes">
<xs:complexType>
<xs:attribute name="Type" type="xs:string" use="required"/>
<xs:attribute name="Version" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="6i|7i|8i|9i"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="Comments" type="xs:string"/>
<xs:element name="Usage" type="xs:integer"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:all>
</xs:complexType>
</xs:element>
答案 0 :(得分:0)
Inventory的内容模型只允许使用一个DatabaseName。
使用内容模型
而不是all(DatabaseName, WebserverName)
choice minOccurs=0 maxOccurs=unbounded
element DatabaseName
element WebserverName