我正在针对XML文档验证XSD,但出现此错误:
cvc-complex-type.2.4.a:发现无效的内容(从元素'artSpent:name'开始)。其中之一
'{"http://www.dei.isep.ipp.pt/lprog":name}'
是预期的。[467]
这是一个XSD示例
<?xml version="1.0" encoding="utf-8"?>
<xsd:schema version="1.0"
xmlns:lprog="http://www.dei.isep.ipp.pt/lprog"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.dei.isep.ipp.pt/lprog"
elementFormDefault="qualified">
<xsd:element name="warehouse">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="ListSpent"
type="lprog:TListSpent"
maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:complexType name="ListSpent">
<xsd:sequence >
<xsd:element name="Spent"
type="lprog:TSpent"
maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="TSpent">
<xsd:sequence >
<xsd:element name="name" type="xsd:string" />
<xsd:element name="stock" type="lprog:TQtdArtigo" />
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
还有我的XML示例
<?xml version="1.0" encoding="UTF-8"?>
<warehouse xmlns="http://www.dei.isep.ipp.pt/lprog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.dei.isep.ipp.pt/lprog
TraXSD.xsd">
<ListSpent xmlns:artSpent="http://www.w3.org/2001/XMLSchema-instance"
artSpent:noNamespaceSchemaLocation="TraXSD.xsd">
<Spent>
<artSpent:name>Meat</artSpent:name>
<artSpent:stock>2</artSpent:stock>
</Spent>
</ListSpent>
</warehouse>
XSD和XML文件都存在多个问题,但是导致您在问题中引用的立即错误的特定问题是由于您没有在管理XSD中name
正确建立元素targetNamespace="http://www.dei.isep.ipp.pt/lprog"
。在下面的工作示例中查看我的操作方法...
以下更正的XSD将成功验证以下更正的XML文件。
<?xml version="1.0" encoding="utf-8"?>
<xsd:schema version="1.0"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:lprog="http://www.dei.isep.ipp.pt/lprog"
targetNamespace="http://www.dei.isep.ipp.pt/lprog"
elementFormDefault="qualified">
<xsd:element name="warehouse">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="ListSpent" type="lprog:ListSpent"
maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:complexType name="ListSpent">
<xsd:sequence >
<xsd:element name="Spent" type="lprog:TSpent" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="TSpent">
<xsd:sequence >
<xsd:element name="name" type="xsd:string" />
<xsd:element name="stock" type="xsd:integer" />
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
使用默认的名称空间声明:
<?xml version="1.0" encoding="UTF-8"?>
<warehouse xmlns="http://www.dei.isep.ipp.pt/lprog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.dei.isep.ipp.pt/lprog TraXSD.xsd">
<ListSpent>
<Spent>
<name>Meat</name>
<stock>2</stock>
</Spent>
</ListSpent>
</warehouse>
使用显式名称空间前缀:
<?xml version="1.0" encoding="UTF-8"?>
<lprog:warehouse xmlns:lprog="http://www.dei.isep.ipp.pt/lprog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.dei.isep.ipp.pt/lprog TraXSD.xsd">
<lprog:ListSpent>
<lprog:Spent>
<lprog:name>Meat</lprog:name>
<lprog:stock>2</lprog:stock>
</lprog:Spent>
</lprog:ListSpent>
</lprog:warehouse>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句