通过XSD验证未知XML元素的后代?
我的XML文件如下所示:通过XSD验证未知XML元素的后代?,xml,xsd,xsd-validation,xml-validation,xsd-1.1,Xml,Xsd,Xsd Validation,Xml Validation,Xsd 1.1,我的XML文件如下所示: <root> <template> <unknownTag> <anotherUnknownTag/> <anotherKnownTag/> <field name='price'/> </unknownTag> </template> <te
<root>
<template>
<unknownTag>
<anotherUnknownTag/>
<anotherKnownTag/>
<field name='price'/>
</unknownTag>
</template>
<template>
<field name='salary'/>
</template>
<anothorKnownTag/>
</root>
实际上,您可以在XSD 1.0中表示请求的约束: XSD 1.0 但较长的形式不那么神秘 有效的XML
实际上,您可以在XSD 1.0中表示请求的约束: XSD 1.0 但较长的形式不那么神秘 有效的XML
<xs:element name="template">
<xs:complexType>
<xs:complexContent>
<xs:sequence>
<xs:element name="field">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="name">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[a-z][a-z_]*"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:any processContents="lax"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:any processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="field">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="name">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[a-z][a-z_]*"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:schema>
<xs:element name="root"/>
<?xml version="1.0" encoding="UTF-8"?>
<root>
<template>
<unknownTag>
<anotherUnknownTag/>
<anotherKnownTag/>
<field name="price"/>
</unknownTag>
</template>
<template>
<field name="salary"/>
</template>
<anothorKnownTag/>
</root>
<?xml version="1.0" encoding="UTF-8"?>
<root>
<template>
<unknownTag>
<anotherUnknownTag/>
<anotherKnownTag/>
<field name="price999"/>
</unknownTag>
</template>
<template>
<field name="big salary"/>
</template>
<anothorKnownTag/>
</root>