有以下 XML:
<dict >
<key>key1</key>
<string>bla-bla</string>
<key>key2</key>
<int>123</int>
<key>key3</key>
<string>blah-blah</string>
<!-- key... -->
<!-- string or int tag -->
<!-- the pair repeats several times -->
</dict>
我正在尝试为此文件结构创建一个 XSD,目前我使用以下代码:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="Test"
targetNamespace="http://tempuri.org/Test.xsd"
elementFormDefault="qualified"
xmlns="http://tempuri.org/Test.xsd"
xmlns:mstns="http://tempuri.org/Test.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
>
<xs:complexType name ="objectType">
</xs:complexType>
<xs:complexType name ="stringType" >
<xs:complexContent>
<xs:extension base ="objectType">
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name ="intType">
<xs:complexContent>
<xs:extension base ="objectType">
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name ="dictType">
<xs:sequence minOccurs ="0" maxOccurs ="unbounded">
<xs:element type ="xs:string" name ="key"/>
<xs:element ref ="object" />
</xs:sequence>
</xs:complexType>
<xs:element name ="object" type ="objectType" abstract ="true"/>
<xs:element name ="string" type ="stringType" substitutionGroup="object" />
<xs:element name ="int" type ="intType" substitutionGroup="object"/>
<xs:element name ="dict" type ="dictType" />
</xs:schema>
这个架构让我生成以下 xmls
<?xml version="1.0" encoding="utf-8"?>
<dict xmlns="http://tempuri.org/Test.xsd">
<key>key1</key>
<string />
<key>key2</key>
<string />
<key>key3</key>
<int />
</dict>
在这个阶段,我找不到一种方法来提供一些带有标签<int>
的数据。<string>
当我写类似的东西时<int>1</int>
。我看到错误消息。“元素不能包含文本。内容模型为空”
您能否告诉我是否可以<int>
用整数填充标签内容并<string>
用字符串标记内容?如何?
先感谢您!