- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我有一个这种形式的 XSD:
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/example"
xmlns:tns="http://www.example.org/example" elementFormDefault="qualified">
<complexType name="bType">
</complexType>
<complexType name="aType">
<choice maxOccurs="unbounded">
<element name="a" type="tns:aType" />
<element name="b" type="tns:bType" />
</choice>
</complexType>
<element name="topelement">
<complexType>
<sequence>
<element name="a" type="tns:aType" maxOccurs="1" />
</sequence>
</complexType>
</element>
</schema>
还有一个我希望匹配它的 XML 文件,例如:
<?xml version="1.0" encoding="UTF-8"?>
<topelement xmlns="http://www.example.org/example"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.example.org/example example.xsd ">
<a> <!-- Error on this line. -->
<a/>
<b/>
<b/>
<a/>
</a>
</topelement>
不幸的是,XSD 说这是无效的,并出现以下错误:
cvc-complex-type.2.4.b: The content of element 'a' is not complete. One of '{"http://www.example.org/example":a, "http://www.example.org/example":b}' is expected. example.xml line 5
据我所知,我已经完成了使标签完整所需的一切工作。我用“a”和“b”标签的无限选择来填充它。谁能看出哪里出了问题?
澄清一下,我希望在 topelement 下只有一个“a”标签,而在其下方是“a”和“b”标签的混合。
最佳答案
Before posting this answer, I hadn't observed your own answer .. Anyway I don't want to let my effort/time-spent go waste .. So I won't delete this post .. Along with the same answer I have also .. written some points please go through ..
复杂类型 aType
定义它总是有 <a/>
或 <b/>
作为子元素 .. 这意味着 .. 无论元素 <a/>
看来它必须有一个 child <a/>
或 <b/>
.. 这不是真的.. 根据您输入的 XML。
所以这是我为克服错误而编写的 XSD 代码,(注意代码中的“minOccurs”属性 .. 因为缺少它你会得到错误 ..)
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/example"
xmlns:tns="http://www.example.org/example" elementFormDefault="qualified">
<element name="topelement">
<complexType>
<sequence>
<element name="a" type="tns:aType" minOccurs="0" maxOccurs="1" />
</sequence>
</complexType>
</element>
<complexType name="bType">
</complexType>
<complexType name="aType">
<sequence>
<choice maxOccurs="unbounded">
<element name="a" type="tns:aType" minOccurs="0"/>
<element name="b" type="tns:bType" minOccurs="0"/>
</choice>
</sequence>
</complexType>
</schema>
所以根据我的代码.. 标签 <a/>
可能有也可能没有任何子元素。
如果您不想更改 XSD 文件.. 那么您的 XML 必须有 <a/>
标签或 <b/>
标记为 <a/>
的 child ..像这样:
<topelement xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.example.org/example" xsi:schemaLocation="http://www.example.org/example example.xsd">
<a>
<a>
<b/>
</a>
<b/>
<b/>
<a>
<a>
<b/>
</a>
<b/>
</a>
</topelement>
无效的地方:
<topelement xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.example.org/example" xsi:schemaLocation="http://www.example.org/example example.xsd">
<a>
<a>
<b/>
</a>
<a/><!--this is wrong-->
<b/>
</a>
</topelement>
问候:婴幼儿专业
关于xml - 为什么 XSD 说我的元素不完整?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2212653/
我正在编写一个 JS 程序,我有一个条件可以根据输入进行一些算术运算。如果我遇到操作类型为“add”,我需要将两个值相加;如果我得到“times”作为我的运算符值,我需要相乘。 我尝试使用基本的 if
我正在编写一个仅作为查看器的应用程序 - 无需创建、无需编辑、无需保存。 显然,那么,不会有自动保存,但是还有什么其他东西可以从 autosavesInPlace 返回 YES 改变世界,从而对观看者
Azure 开始出现以下错误: Unsupported token. Unable to initialize the authorization context. 每当我尝试更改我的应用程序时,我都
当我编写 out.println() 时,Eclipse 提示 out 无法解析。 我导入了 java.io.* 和其他 servlet 包。 最佳答案 只是在黑暗中拍摄,我认为这就是您正在寻找的出路
Azure 开始出现以下错误: Unsupported token. Unable to initialize the authorization context. 每当我尝试更改我的应用程序时,我都
是否可以执行类似的操作来检查 radio 表单是否未选中: if !($(this).find("input:checked")) {} 正确的语法是什么? 最佳答案 试试这个: $(this).fi
我正在尝试从表中选择行,其中 date 列值等于澳大利亚悉尼的当前日期 (UTC+10h)。服务器位于悉尼,因此我想使用 SYSDATETIME()。这是我的查询: SELECT * FROM dat
我听说 JavaScript 实际上并不像其他语言那样“指向”内存中的值(或对象,因为在 JS 中一切都是对象)。相反,JS 变量引用内存中的其他值/对象。这是真的?指向和引用之间的语义区别是什么?
我的计算机科学类(class)有一项作业,其中要求读取包含多个测试分数的文件,并要求我对它们进行求和并求平均值。虽然求和和求平均值很容易,但我在读取文件时遇到问题。老师说用这个语法 Scanner s
Java 的 XML 解析器似乎认为我的 XML 文档在根元素之后的格式不正确。但我已经用几种工具验证了它,但他们都不同意。这可能是我的代码错误,而不是文档本身的错误。如果你们能给我提供任何帮助,我将
根据这份文件: http://www.stroustrup.com/terminology.pdf l 值具有同一性且不可移动。 公关值是可移动的,但没有身份。 x 值具有同一性并且是可移动的。 关于
这个问题在这里已经有了答案: What does "atomic" mean in programming? (7 个答案) 关闭 5 年前。 我正在阅读 MongoDB 的 documentati
在 PHP 和 MySQL 中有没有一种方法能够比较 2 个不同的数组(列表)变量并说出有多少项是相同的 例如, $array1 = "hello, bye, google, laptop, yes"
本文来自 Effective Java Programs that use the int enum pattern are brittle. Because int enums are compil
C++ 中有一些特性是类型安全的,而另一些则不是。 C++ 类型安全示例: char c = 'a'; int *p = &c; // this is not allowed (compiler
我有一个 CS 课的作业,它说要读取一个包含多个测试分数的文件,并要求我对它们求和并取平均值。虽然求和和平均很容易,但我在读取文件时遇到了问题。老师说要用这个语法 Scanner scores = n
嗯.. 有时,PyDev 会说“ Unresolved 导入错误”。 在我的环境中 Python2.6.6 Eclipse3.7 PyDev2.2.2 错误是。 > Unresolved import
我正在向服务器发送请求,服务器正在处理请求并做出响应。但是在我的应用程序中,我收到了: Error Domain=NSURLErrorDomain Code=-1017 "cannot parse r
在我最近的一次讨论中,有人告诉我这样说是不正确的,因为 Ajax 已经是 Javascript。 上下文: “我如何在网页中 blablababal,这样它就不必刷新页面” 我的回答: “使用 Jav
下午好。 我一直在尝试使用 ffmpeg 将 .mpeg 拆分为一系列 .jpeg 图像。请注意,这是指定 here 的逆问题,但我面临的问题与该线程的作者面临的问题不同。 具体来说,我已经在我的 f
我是一名优秀的程序员,十分优秀!