我修改了 XSD 以添加新项目,而无需创建新的 XSD。目前在这种情况下我有一个元素是“轮胎”。
我创建了一个“轮胎”类型的元素。
<xs:element name="tire" type="x:tire" />
但验证时出现错误。错误:
Not valid.
Error - Line 4, 43: org.xml.sax.SAXParseException; lineNumber: 4; columnNumber: 43; src-resolve.4.2: Error resolving component 'x:tire'. It was detected that 'x:tire' is in namespace 'http://www.w3.org/2001/XMLSchema', but components from this namespace are not referenceable from schema document 'null'. If this is the incorrect namespace, perhaps the prefix of 'x:tire' needs to be changed. If this is the correct namespace, then an appropriate 'import' tag should be added to 'null'.
Error - Line 4, 43: org.xml.sax.SAXParseException; lineNumber: 4; columnNumber: 43; src-resolve: Cannot resolve the name 'x:tire' to a(n) 'type definition' component.
XML
<?xml version="1.0" encoding="UTF-8"?>
<tire trademark="runway" id="369954" product-type="tire">
<url>http://www.tire.es/product/369954.html</url>
<price>28.95</price>
<specs>
<spec name="b_homologation">0</spec>
<spec name="b_xl">0</spec>
<spec name="b_runflat">0</spec>
<spec name="s_drawing_type">simétrico</spec>
<spec name="s_consumption">f</spec>
<spec name="i_noise">69</spec>
<spec name="s_grip">c</spec>
</specs>
</tire>
XSD
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:x="http://www.w3.org/2001/XMLSchema">
<xs:element name="tire" type="x:tire" />
<xs:complexType name="product">
<xs:sequence>
<xs:element type="xs:anyURI" name="url" />
<xs:element type="xs:double" name="price" />
<xs:element name="specs" maxOccurs="unbounded"
minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="spec" maxOccurs="unbounded"
minOccurs="0">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:string" name="name"
use="optional" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="features" maxOccurs="unbounded"
minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="feature" maxOccurs="unbounded"
minOccurs="0">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:string" name="name"
use="optional" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute type="xs:string" name="id" />
<xs:attribute type="xs:string" name="product-type" />
</xs:complexType>
<xs:complexType name="tire">
<xs:complexContent>
<xs:extension base="product">
<xs:attribute type="xs:string" name="model" />
<xs:attribute type="xs:string" name="trademark" />
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="products">
<xs:complexType>
<xs:sequence>
<xs:element name="tire" maxOccurs="unbounded"
minOccurs="0" type="x:tire" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
新产品会将它们添加为元素。
<xs:element name="glass" maxOccurs="unbounded" minOccurs="0" type="x:glass" />
谢谢。