我被要求建立一个商业数据库,这是我的第一个虚构的公司。"我已经获得了使用XML验证的模式,但是被要求为XML文件中的至少一个公司输入ORDER / RANKING。但是我尝试这样做,我无法使其验证(即使提供了正确的行)。
这是我的XML文件(你可以看到我把排名=" 3"这就是我不能写入我的模式的行)。
<?xml version="1.0"?>
<CompanyList>
<Company ranking="3">
<CompanyName>CasesWorldwide</CompanyName>
<CompanyID>00001</CompanyID>
<City>Edmonton</City>
<Province>Alberta</Province>
<ContactName>
<LastName>Soliman</LastName>
<FirstName>Ahmed</FirstName>
<PhoneNumber>646959891</PhoneNumber>
<ContactCompanyID>00001</ContactCompanyID>
</ContactName>
<NumberOfEmployees>4000</NumberOfEmployees>
</Company>
</CompanyList>
这是架构(我的尝试线在#34;公司&#34;旁边):
<?xml version="1.0"?>
<!-- XSD schema for CS Assignment #3.xml -->
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="CompanyList">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Company"> <xsd:attribute name="ranking” type=“xsd:string” use=“optional”/>
<xsd:complexType>
<xsd:sequence>
<xsd:element name="CompanyName">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:minLength value="1"/>
<xsd:pattern value=".*[^\s].*" />
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="CompanyID" type="xsd:integer"/>
<xsd:element name="City" type="xsd:string" minOccurs="0"/>
<xsd:element name="Province" type="xsd:string" minOccurs="0"/>
<xsd:element name="ContactName" minOccurs = "1" maxOccurs="5">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="LastName" type="xsd:string" minOccurs="1"/>
<xsd:element name="FirstName" type="xsd:string" minOccurs="1"/>
<xsd:element name="PhoneNumber" type="xsd:integer" minOccurs="1"/>
<xsd:element name="ContactCompanyID" type="xsd:integer" minOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="NumberOfEmployees" type="xsd:integer" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
答案 0 :(得分:1)
通常,xsd:attribute
可以显示:
xsd:schema
内)。xsd:complexType
内(完全或通过引用)。xs:attributeGroup
内(完全或通过引用)。你很亲密;你只需要两次更正:
xsd:attribute
放在xsd:sequence
之后xsd:complexType
。 xsd:attribute
中的智能引号更改为常规引号。共:
<?xml version="1.0"?>
<!-- XSD schema for CS Assignment #3.xml -->
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="CompanyList">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Company">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="CompanyName">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:minLength value="1"/>
<xsd:pattern value=".*[^\s].*" />
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="CompanyID" type="xsd:integer"/>
<xsd:element name="City" type="xsd:string" minOccurs="0"/>
<xsd:element name="Province" type="xsd:string" minOccurs="0"/>
<xsd:element name="ContactName" minOccurs = "1" maxOccurs="5">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="LastName" type="xsd:string"
minOccurs="1"/>
<xsd:element name="FirstName" type="xsd:string"
minOccurs="1"/>
<xsd:element name="PhoneNumber" type="xsd:integer"
minOccurs="1"/>
<xsd:element name="ContactCompanyID" type="xsd:integer"
minOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="NumberOfEmployees" type="xsd:integer"
minOccurs="0"/>
</xsd:sequence>
<xsd:attribute name="ranking" type="xsd:string" use="optional"/>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
此XSD将成功验证您的XML。