我想在浏览器中看到xml文件,我在.xsd文件中定义。请检查以下两个文件给我,并指出我需要做什么。这两个文件在同一个文件夹下。
employee.xml
<?xml version="1.0"?> <employee xmlns="http://www.w3schools.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="employee.xsd"> <firstname>John</firstname> <lastname>Smith</lastname> </employee>
的employee.xsd
<xs:element name="employee"> <xs:complexType> <xs:sequence> <xs:element name="firstname" type="xs:string" fixed="red" /> <xs:element name="lastname" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element>
您造成了两个错误:一个在模式文件中,另一个在XML文件的xsi:schemaLocation属性的值的语法中。
主要的错误是你的employee.xsd文件只是XML Schema的一个片段。您应该完成对employee.xsd的包含。例如,
<?xml version="1.0" encoding="utf-8"?> <xs:schema targetNamespace="http://www.w3schools.com/RedsDevils" elementFormDefault="qualified" xmlns="http://www.w3schools.com/RedsDevils employee.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="employee"> <xs:complexType> <xs:sequence> <xs:element name="firstname" type="xs:string" fixed="red" /> <xs:element name="lastname" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>
和employee.xml:
<?xml version="1.0" encoding="utf-8"?> <employee xmlns="http://www.w3schools.com/RedsDevils" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3schools.com/RedsDevils employee.xsd"> <firstname>John</firstname> <lastname>Smith</lastname> </employee>
因为您在XML文件中定义了默认命名空间,所以模式位置属性xsi:schemaLocation必须包含命名空间和与空白对应的模式的路径。我更改了命名空间名称,以便它将更加独特:“http://www.w3schools.com/RedsDevils”而不是“http://www.w3schools.com”。
最后我可以补充说,XML文件employee.xml与模式employee.xsd不对应,因为元素< firstname> John< / firstname>具有其他红色的值,但可能正是您想要测试的。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。