shiporder.xml
来自w3schools;模式验证失败,因为:
thufir@dur:~/xml/ship$
thufir@dur:~/xml/ship$ ls
shiporder.xml
thufir@dur:~/xml/ship$
thufir@dur:~/xml/ship$ trang shiporder.xml shiporder.xsd
thufir@dur:~/xml/ship$
thufir@dur:~/xml/ship$ ls
shiporder.xml shiporder.xsd xsi.xsd
thufir@dur:~/xml/ship$
thufir@dur:~/xml/ship$ cat xsi.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xs:import schemaLocation="shiporder.xsd"/>
<xs:attribute name="noNamespaceSchemaLocation" type="xs:NCName"/>
</xs:schema>
thufir@dur:~/xml/ship$
thufir@dur:~/xml/ship$ cat shiporder.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xs:import namespace="http://www.w3.org/2001/XMLSchema-instance" schemaLocation="xsi.xsd"/>
<xs:element name="shiporder">
<xs:complexType>
<xs:sequence>
<xs:element ref="orderperson"/>
<xs:element ref="shipto"/>
<xs:element maxOccurs="unbounded" ref="item"/>
</xs:sequence>
<xs:attribute name="orderid" use="required" type="xs:integer"/>
<xs:attribute ref="xsi:noNamespaceSchemaLocation" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="orderperson" type="xs:string"/>
<xs:element name="shipto">
<xs:complexType>
<xs:sequence>
<xs:element ref="name"/>
<xs:element ref="address"/>
<xs:element ref="city"/>
<xs:element ref="country"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="name" type="xs:string"/>
<xs:element name="address" type="xs:string"/>
<xs:element name="city" type="xs:string"/>
<xs:element name="country" type="xs:NCName"/>
<xs:element name="item">
<xs:complexType>
<xs:sequence>
<xs:element ref="title"/>
<xs:element minOccurs="0" ref="note"/>
<xs:element ref="quantity"/>
<xs:element ref="price"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="title" type="xs:string"/>
<xs:element name="note" type="xs:string"/>
<xs:element name="quantity" type="xs:integer"/>
<xs:element name="price" type="xs:decimal"/>
</xs:schema>
thufir@dur:~/xml/ship$
thufir@dur:~/xml/ship$ xmllint --noout --schema shiporder.xsd shiporder.xml
xsi.xsd:4: element attribute: Schemas parser error : Element '{http://www.w3.org/2001/XMLSchema}attribute': The target namespace must not match 'http://www.w3.org/2001/XMLSchema-instance'.
WXS schema shiporder.xsd failed to compile
thufir@dur:~/xml/ship$
thufir@dur:~/xml/ship$ cat shiporder.xml
<?xml version="1.0" encoding="UTF-8"?>
<shiporder orderid="889923"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="shiporder.xsd">
<orderperson>John Smith</orderperson>
<shipto>
<name>Ola Nordmann</name>
<address>Langgt 23</address>
<city>4000 Stavanger</city>
<country>Norway</country>
</shipto>
<item>
<title>Empire Burlesque</title>
<note>Special Edition</note>
<quantity>1</quantity>
<price>10.90</price>
</item>
<item>
<title>Hide your heart</title>
<quantity>1</quantity>
<price>9.90</price>
</item>
</shiporder>
thufir@dur:~/xml/ship$
xmllint
不能像通过xsd
生成trang
一样来验证document是有效的吗?
答案 0 :(得分:0)
我取出了引用“ http://www.w3.org/2001/XMLSchema-instance”的第2行和第12行,以便现在可以验证:
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<button class='btn btn-primary disabled' disabled>
<i class="fa fa-search"></i>
</button>
但是为什么呢?而且,我是否无法生成thufir@dur:~/xml/ship$
thufir@dur:~/xml/ship$ xmllint --noout --schema shiporder.xsd shiporder.xml
shiporder.xml validates
thufir@dur:~/xml/ship$
thufir@dur:~/xml/ship$ ls
shiporder.xml shiporder.xsd xsi.xsd
thufir@dur:~/xml/ship$
thufir@dur:~/xml/ship$ cat xsi.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xs:import schemaLocation="shiporder.xsd"/>
<xs:attribute name="noNamespaceSchemaLocation" type="xs:NCName"/>
</xs:schema>
thufir@dur:~/xml/ship$
thufir@dur:~/xml/ship$ cat shiporder.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xs:element name="shiporder">
<xs:complexType>
<xs:sequence>
<xs:element ref="orderperson"/>
<xs:element ref="shipto"/>
<xs:element maxOccurs="unbounded" ref="item"/>
</xs:sequence>
<xs:attribute name="orderid" use="required" type="xs:integer"/>
</xs:complexType>
</xs:element>
<xs:element name="orderperson" type="xs:string"/>
<xs:element name="shipto">
<xs:complexType>
<xs:sequence>
<xs:element ref="name"/>
<xs:element ref="address"/>
<xs:element ref="city"/>
<xs:element ref="country"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="name" type="xs:string"/>
<xs:element name="address" type="xs:string"/>
<xs:element name="city" type="xs:string"/>
<xs:element name="country" type="xs:NCName"/>
<xs:element name="item">
<xs:complexType>
<xs:sequence>
<xs:element ref="title"/>
<xs:element minOccurs="0" ref="note"/>
<xs:element ref="quantity"/>
<xs:element ref="price"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="title" type="xs:string"/>
<xs:element name="note" type="xs:string"/>
<xs:element name="quantity" type="xs:integer"/>
<xs:element name="price" type="xs:decimal"/>
</xs:schema>
thufir@dur:~/xml/ship$
,以便没有这样的引用,或者很好地引用了正确?