Xml 为什么不是';t xsd:有没有像我预期的那样有效的验证?
我想通过模式验证以下XML,如果Xml 为什么不是';t xsd:有没有像我预期的那样有效的验证?,xml,xsd,xsd-validation,xml-validation,Xml,Xsd,Xsd Validation,Xml Validation,我想通过模式验证以下XML,如果l10n元素中没有文本,则不应验证它。对于XML,content元素也是必需的。请有人告诉我相关的答案 要验证的XML是: <body xmlns="http://iddn.icis.com/ns/test"> <content> <l10n xml:lang="en"></l10n> </content> </body> 我目前使用的模式如下,但它仍然允许验证上
l10n
元素中没有文本,则不应验证它。对于XML,content元素也是必需的。请有人告诉我相关的答案
要验证的XML是:
<body xmlns="http://iddn.icis.com/ns/test">
<content>
<l10n xml:lang="en"></l10n>
</content>
</body>
我目前使用的模式如下,但它仍然允许验证上述XML
<xs:schema elementFormDefault="qualified" targetNamespace="http://iddn.icis.com/ns/test"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:conf="http://iddn.icis.com/ns/config"
xmlns="http://www.w3.org/1999/xhtml">
<xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="http://www.w3.org/2001/xml.xsd">
</xs:import>
<xs:simpleType name="nameType">
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
</xs:restriction>
</xs:simpleType>
<xs:element name="content">
<xs:complexType mixed="true">
<xs:sequence>
<xs:any maxOccurs="unbounded" minOccurs="0" processContents="skip"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="i18n-value">
<xs:sequence>
<xs:element name="l10n" maxOccurs="unbounded">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="nameType">
<xs:attribute ref="xml:lang" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:element name="body">
<xs:complexType>
<xs:sequence><xs:element ref="content"></xs:element></xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
在多个层面上都存在许多问题。让我们分两个阶段共同解决它们:首先,我们将修复阻止任何验证发生的XSD问题 修复初始XSD问题 此XML
<?xml version="1.0" encoding="utf-16"?>
<body xmlns="http://iddn.icis.com/ns/test"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://iddn.icis.com/ns/test try.xsd">
<content>
<l10n xml:lang="en"></l10n>
</content>
</body>
<?xml version="1.0" encoding="utf-16"?>
<body xmlns="http://iddn.icis.com/ns/test"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://iddn.icis.com/ns/test try.xsd">
<content>
<i18n-value>
<l10n xml:lang="en"></l10n>
</i18n-value>
</content>
</body>
XSD
<xs:schema elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://iddn.icis.com/ns/test"
xmlns:tst="http://iddn.icis.com/ns/test">
<xs:import namespace="http://www.w3.org/XML/1998/namespace"
schemaLocation="http://www.w3.org/2001/xml.xsd"/>
<xs:simpleType name="nameType">
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
</xs:restriction>
</xs:simpleType>
<xs:element name="content">
<xs:complexType mixed="true">
<xs:sequence>
<xs:any maxOccurs="unbounded" minOccurs="0" processContents="lax"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="i18n-value">
<xs:complexType>
<xs:sequence>
<xs:element name="l10n" maxOccurs="unbounded">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="tst:nameType">
<xs:attribute ref="xml:lang" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="body">
<xs:complexType>
<xs:sequence>
<xs:element ref="tst:content"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
感谢您的回复Kenneth。在我的例子中,body元素的类型应该是i18n value。对不起,我在第一个问题中漏掉了。考虑到我提供的答案修复了原始XSD中的许多错误,并且对原始XML非常有效,我要求您更新投票和/或此答案,如果需要进一步帮助,请使用新答案。更改后的XML确实构成了一个全新的问题。谢谢。你能为我在上一篇评论中提出的问题向我推荐肯尼斯的答案吗?提前谢谢。我很乐意看到一个新问题作为一个新问题发布,而不是在评论中。只要您使用[xsd]和/或相关标记对其进行标记,我就会看到它。谢谢
<xs:schema elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://iddn.icis.com/ns/test"
xmlns:tst="http://iddn.icis.com/ns/test">
<xs:import namespace="http://www.w3.org/XML/1998/namespace"
schemaLocation="http://www.w3.org/2001/xml.xsd"/>
<xs:simpleType name="nameType">
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
</xs:restriction>
</xs:simpleType>
<xs:element name="content">
<xs:complexType mixed="true">
<xs:sequence>
<xs:any maxOccurs="unbounded" minOccurs="0" processContents="lax"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="i18n-value">
<xs:complexType>
<xs:sequence>
<xs:element name="l10n" maxOccurs="unbounded">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="tst:nameType">
<xs:attribute ref="xml:lang" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="body">
<xs:complexType>
<xs:sequence>
<xs:element ref="tst:content"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>