为包含属性的xml元素定义架构的合适格式是什么?子元素和子元素也包含子元素
例如:我的xml
<element1 attribute1="hello">
<element-sub1>
<element-sub-sub1 attribute-sub-1="hi"/>
<elementsubsub1>
</element1>我尝试使用以下模式
<xs:element name="element1">
<xs:complexType>
<xs:sequence>
<xs:element name="element-sub1" type="xs:anyType" maxOccurs="unbounded"/>
<xs:complexType>
<xs:sequence>
<xs:element name="element-sub-sub1" type="xs:anyType" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="attribute-sub-1" type="xs:string"/>
</xs:complexType>
</xs:sequence>
<xs:attribute name="attribute1" type="xs:string"/>
</xs:complexType>
</xs:element>但是我得到了以下错误
The content of 'sequence' must match (annotation?, (element | group | choice | sequence | any)*). A problem was found st
arting at: complexType.我为什么要犯这个错误?为我的需求编写模式的正确格式是什么?
注意事项
元素“元素-子-子1”可能也有文本。
更新1
<element1 URI="">
<element-sub1>
<element-sub-sub1 Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
<element-sub-sub1 Algorithm="http://www.w3.org/TR/1999/REC-xslt-19991116">
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text"/>
<xsl:template match="/">
Pan : <xsl:copy-of select="//Pp"/>
MobileNo : <xsl:copy-of select="//Mm"/>
TotalAmount : <xsl:copy-of select="//Total"/>
</xsl:template>
</xsl:stylesheet>
element-sub-sub1
</element-sub1>
</element1>发布于 2012-05-28 09:26:04
首先,您不能在同一个type="xs:anyType"上拥有一个<xs:complexType>属性和一个<xs:complexType>元素
其次,<xs:complexType>的定义可能只会立即出现在<xs:element>中,或者作为<schema>的子类型出现在全局类型中。
最后但并非最不重要。如果希望元素包含属性,则使其类型变得复杂。
<xs:element name="element1">
<xs:complexType>
<xs:sequence>
<xs:element name="element-sub1" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="element-sub-sub1" maxOccurs="unbounded">
<xs:complexType mixed="true">
<xs:any minOccurs="0" maxOccurs="1"/>
<xs:attribute name="attribute-sub-1" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="attribute1" type="xs:string" />
</xs:complexType>
</xs:element>正如注释中提到的,元素允许您在该位置上插入任何xml元素。无论元素是否按照某种标准有效,验证都将通过。它必须有良好的结构。
如果要验证整个样式表,请使用xs:import访问名称空间,其中定义了xsl样式表:http://www.w3.org/XML/2000/04schema-hacking/xslt.xsd,并在xsd中引用样式表或转换元素。在<xs:element name="sub-sub1>内部:
<xs:complexType mixed="true">
<xs:choice minOccurs="0" maxOccurs="1">
<xs:element ref="xsl:stylesheet"/>
<xs:element ref="xsl:transform"/>
<xs:choice>
<!-- You'll have to define a prefix for the xslt namespace imported -->
<xs:attribute name="attribute-sub-1" type="xs:string" />
</xs:complexType>选择元素允许您为XSL样式表使用两个可接受的顶部标记之一,<stylesheet>或<transform>
UPDATE:为可选样式表/转换添加了minOccurs、maxOccurs属性
发布于 2012-05-28 09:25:58
您的架构是无效的,甚至是格式良好的。以下是你所需要的:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:test:1">
<xs:element name="element1">
<xs:complexType>
<xs:sequence>
<xs:element name="element-sub1" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="element-sub-sub1" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="attribute-sub-1" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="attribute1" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:schema>https://stackoverflow.com/questions/10782069
复制相似问题