[英]Can my XSD schema be set up so namespace elements appear as global to validated XML?
Given this XSD:鉴于此 XSD:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="ABC" xmlns:abc="ABC">
<xs:complexType name="thing">
<xs:sequence>
<xs:element name="NAME" type="xs:string" />
<xs:element name="DESCRIPTION" type="xs:string" />
</xs:sequence>
</xs:complexType>
<xs:element name="things">
<xs:complexType>
<xs:sequence>
<xs:element name="thing" type="abc:accident"
maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
I am having issues validating the following against it:我在验证以下内容时遇到问题:
<?xml version="1.0" encoding="UTF-8"?>
<things>
<thing>
<NAME>Zaphod Beeblebrox</NAME>
<DESCRIPTION>Just this guy</DESCRIPTION>
</thing>
</things>
I think it's all down to namespaces... I only added a namespace to my XSD since I was getting errors about "namespace ''" in the XSD validation.我认为这完全取决于名称空间......我只向我的 XSD 添加了一个名称空间,因为我在 XSD 验证中遇到了关于“命名空间 ''”的错误。 But I don't control the XML to insert some sort of namespace reference.但我不控制 XML 插入某种命名空间引用。
Is there some simple way that <things>
in the XML will be validated as <abc:things>
- or a way to exclude namespaces in the XSD altogether?是否有一些简单的方法可以将 XML 中的<things>
验证为<abc:things>
- 或者完全排除 XSD 中的命名空间?
If your XML is set,如果您的 XML 已设置,
<?xml version="1.0" encoding="UTF-8"?>
<things xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="try.xsd">
<thing>
<NAME>Zaphod Beeblebrox</NAME>
<DESCRIPTION>Just this guy</DESCRIPTION>
</thing>
</things>
and it does not use namespaces, then simply write your XSD not to use namespaces:并且它不使用名称空间,那么只需编写您的 XSD 不使用名称空间:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="thing">
<xs:sequence>
<xs:element name="NAME" type="xs:string" />
<xs:element name="DESCRIPTION" type="xs:string" />
</xs:sequence>
</xs:complexType>
<xs:element name="things">
<xs:complexType>
<xs:sequence>
<xs:element name="thing" type="thing"
maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
The above XSD will successfully validate the above XML.上述 XSD 将成功验证上述 XML。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.