我正在尝试根据我的XML模式验证我的XML文档.
这是我的架构:
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://cars.example.org/">
<element name="cars">
<complexType>
<sequence minOccurs="0" maxOccurs="unbounded">
<element name="brand" type="string"/>
</sequence>
</complexType>
</element>
</schema>
Run Code Online (Sandbox Code Playgroud)
这是我的XML文档:
<?xml version="1.0" encoding="UTF-8"?>
<cars xmlns="http://cars.example.org/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://cars.example.org/ cars.xsd">
<brand>x</brand>
</cars>
Run Code Online (Sandbox Code Playgroud)
现在,当我验证文档时(通过Eclipse),我在第4行得到以下消息:
cvc-complex-type.2.4.a: Invalid content was found starting with element 'brand'. One of '{"":brand}' is expected.
Run Code Online (Sandbox Code Playgroud)
这条消息没有任何意义:(.谷歌解决方案很难(不可能?).
谢谢您的帮助.
Alo*_*hci 14
您的架构将"品牌"定义为没有命名空间.这'{"":brand}'意味着什么.但是在XML文档中,"brand"元素位于http://cars.example.org/命名空间中.所以他们不匹配,你得到验证错误.
要将模式中的"brand"元素声明为http://cars.example.org/名称空间,请将该属性添加elementFormDefault="qualified"到模式元素.
我建议为了完整性,您还要添加attributeFormDefault="unqualified"到schema元素,尽管在这种情况下这不是您的问题.