无法针对xsd验证我的xml

时间:2014-07-16 12:14:52

标签: xml xsd

我正在尝试针对XSD验证一个简单的xml文件,但验证器总是告诉我

'Cvc-elt.1:找不到元素声明'shipmentCreationRequest'..行'3',列'36'。'

我搜索了SO并尝试了几种解决方案似乎没有任何效果并解决了我的问题... 这是xml

<?xml version="1.0" encoding="UTF-8"?>
 <Test xmlns="http://www.w3schools.com"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema"
       xsi:schemaLocation="Request.xsd" >
 </Test>

这是XSD

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/Request" xmlns:tns="http://www.example.org/Request" elementFormDefault="qualified">
 <element name="Test"></element>
</schema>

感谢您的帮助, 问候。

1 个答案:

答案 0 :(得分:1)

我认为你的实际错误信息可能就是这样:

cvc-elt.1.a: Cannot find the declaration of element 'Test'.

将您的XML更改为:

<?xml version="1.0" encoding="UTF-8"?>
<Test xmlns="http://www.example.org/Request"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema"
      xsi:schemaLocation="http://www.example.org/Request Request.xsd" >
</Test>

将您的XSD更改为:

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
        targetNamespace="http://www.example.org/Request"
        xmlns:tns="http://www.example.org/Request"
        elementFormDefault="qualified">
  <element name="Test"></element>
</schema>