Xsd 使用序列创建多个元素名称。
下面是一个示例xml,它有多个Xsd 使用序列创建多个元素名称。,xsd,schema,xsd-validation,Xsd,Schema,Xsd Validation,下面是一个示例xml,它有多个,从序列1开始,最后可以变成许多规则,如,等 <?xml version="1.0" encoding="UTF-8"?> <AddressChange_181> <rules> <rule1> <conditions>xya</conditions> <response_path>abc</respons
,从序列1开始,最后可以变成许多规则,如,
等
<?xml version="1.0" encoding="UTF-8"?>
<AddressChange_181>
<rules>
<rule1>
<conditions>xya</conditions>
<response_path>abc</response_path>
</rule1>
<rule2>
<conditions>xxxx</conditions>
<response_path>aaaa</response_path>
</rule2>
<rule3>
<conditions>yyyyy</conditions>
<response_path>ffff</response_path>
</rule3>
<rule4>
<conditions>zzzz</conditions>
<response_path>yyyy</response_path>
</rule4>
<default>
<response_path>uuuuu</response_path>
</default>
</rules>
</AddressChange_181>
xya
abc
xxxx
aaaa
YYYY
ffff
zzzz
年份
乌乌
下面是我尝试为上述xml创建动态
元素名的模式。
当我从这个模式生成xml时,我得到的xml格式与上面的xml格式不同。
您能告诉我如何创建以序列号开头的多元素名称的模式吗。
我的要求是在xml文件中添加多个规则(,
等),并且应该根据模式验证此xml文件
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="mock_rule_list">
<xs:complexType>
<xs:sequence>
<xs:element ref="rules" minOccurs="1" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="rules">
<xs:complexType>
<xs:sequence>
<xs:element ref="rule" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="default" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="rule">
<xs:complexType>
<xs:simpleContent>
<xs:restriction base="xs:anyType">
<xs:pattern value="rule/d{1,3}"></xs:pattern>
</xs:restriction>
</xs:simpleContent>
<xs:sequence>
<xs:element ref="conditions" minOccurs="1" maxOccurs="1"/>
<xs:element ref="response_path" minOccurs="1" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="default">
<xs:complexType>
<xs:sequence>
<xs:element ref="response_path"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="conditions" type="xs:string">
</xs:element>
<xs:element name="response_path" type="xs:string"/>
</xs:schema>
谢谢,
Madhu如果任意定义了ruleX标记的数量,则无法使用XSD定义这样的结构。如果您可以将上限限制为最大值,并且您确实必须遵守ruleX命名约定,那么您可以定义一个复杂类型,例如ruleType,然后是一组rule1、rule2,这种类型的规则元素-我称之为混乱。。。我不推荐这个 XSD(最多6个):
或者,您可以有一个名为“rule”的标记,带有@sequence属性
XSD:
示例XML:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<!-- Sample XML generated by QTAssistant (http://www.paschidev.com) -->
<rules xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<rule sequence="1">
<conditions>conditions1</conditions>
<response_path>response_path1</response_path>
</rule>
<rule sequence="2">
<conditions>conditions2</conditions>
<response_path>response_path2</response_path>
</rule>
<default>
<response_path>response_path1</response_path>
</default>
</rules>
条件1
响应路径1
条件2
响应路径2
响应路径1
或者也可能只是在父集合中使用的索引。如果任意定义了ruleX标记的数量,则无法使用XSD定义此类结构。如果您可以将上限限制为最大值,并且您确实必须遵守ruleX命名约定,那么您可以定义一个复杂类型,例如ruleType,然后是一组rule1、rule2,这种类型的规则元素-我称之为混乱。。。我不推荐这个 XSD(最多6个):
或者,您可以有一个名为“rule”的标记,带有@sequence属性
XSD:
示例XML:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<!-- Sample XML generated by QTAssistant (http://www.paschidev.com) -->
<rules xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<rule sequence="1">
<conditions>conditions1</conditions>
<response_path>response_path1</response_path>
</rule>
<rule sequence="2">
<conditions>conditions2</conditions>
<response_path>response_path2</response_path>
</rule>
<default>
<response_path>response_path1</response_path>
</default>
</rules>
条件1
响应路径1
条件2
响应路径2
响应路径1
或者也可以简单地使用父集合中的索引。@Gardea,谢谢。。。在这种情况下,我将更改我的xml模板。@Gardea,谢谢你。。。在这种情况下,我将更改我的xml模板。
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<!-- Sample XML generated by QTAssistant (http://www.paschidev.com) -->
<rules xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<rule sequence="1">
<conditions>conditions1</conditions>
<response_path>response_path1</response_path>
</rule>
<rule sequence="2">
<conditions>conditions2</conditions>
<response_path>response_path2</response_path>
</rule>
<default>
<response_path>response_path1</response_path>
</default>
</rules>