我正在为 Couchdb 创建一个 xml 挂件,并使用 xsd 验证文档。
现在 project:project 的嵌入不起作用并给出验证错误。
如何更改我的 xsd,使我的 xml 文件有效?
我想要以下 xml 布局:
<document:document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:document="urn:JCouch.Document"
xmlns:attachment="urn:JCouch.Attachment"
xmlns:project="urn:JCouch.Project"
xsi:schemaLocation="
urn:JCouch.Document document.xsd
urn:JCouch.Project project.xsd
">
<document:meta>
<document:id>123</document:id>
<document:revision>12321</document:revision>
<document:deleted>false</document:deleted>
<document:md5>md5 of everything including</document:md5>
</document:meta>
<!-- Auto generated based on files attached -->
<document:attachments>
<attachment:attachment>
<attachment:path></attachment:path>
<attachment:length>1</attachment:length>
<attachment:md5></attachment:md5>
</attachment:attachment>
</document:attachments>
<!-- The actual document content -->
<document:content>
<project:project>
<project:name>dsa</project:name>
<project:projectNumber>123</project:projectNumber>
</project:project>
</document:content>
</document:document>
我有 3 个 xsd 文件。1个文件,1个附件,1个项目。记住项目只是一个例子。我以后想添加 blog:blog blog:entry 等等。
文档.xsd:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
targetNamespace="urn:JCouch.Document"
xmlns="urn:JCouch.Document"
xmlns:attachment="urn:JCouch.Attachment"
xmlns:project="urn:JCouch.Project"
xsi:schemaLocation="
urn:JCouch.Attachment attachment.xsd
urn:JCouch.Project project.xsd"
elementFormDefault="qualified"
>
<xs:element name="document" type="documentType"/>
<xs:complexType name="documentType">
<xs:sequence>
<xs:element name="meta" minOccurs="1" maxOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="1" maxOccurs="1" name="id" type="xs:string"/>
<xs:element minOccurs="1" maxOccurs="1" name="revision" type="xs:string"/>
<xs:element minOccurs="1" maxOccurs="1" name="deleted" type="xs:boolean"/>
<xs:element minOccurs="1" maxOccurs="1" name="md5" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="attachments" minOccurs="1" maxOccurs="1" type="attachment:attachmentType"/>
<xs:element name="content" minOccurs="1" maxOccurs="1" type="contentType">
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:complexType name="contentType">
<xs:sequence>
<xs:element ref="project:project" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
项目.xsd:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="urn:JCouch.Project"
elementFormDefault="qualified">
<xs:complexType name="projectType">
<xs:sequence>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="projectNumber" type="xs:string"/>
</xs:sequence>
</xs:sequence>
</xs:complexType>
<xs:element name="project" type="projectType"/>
</xs:schema>
最后是附件.xsd,尽管这部分有效!
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="urn:JCouch.Attachment"
elementFormDefault="qualified">
<xs:complexType name="attachmentType">
<xs:sequence>
<xs:element name="attachment">
<xs:complexType>
<xs:sequence>
<xs:element name="path" type="xs:anyURI"/>
<xs:element name="length" type="xs:integer"/>
<xs:element name="md5" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:schema>
任何帮助将不胜感激。
最好的问候克雷斯滕·克亚尔