我已经使用XML向导从XSD文件生成了一个单元。
一切正常,但是我有一个可选节点,minOccurs="0"
没有最大值。
<xs:complexType name="Party">
<xs:sequence>
<xs:element name="Nm" type="Max70Text" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
在Delphi代码中,我可以使用以下方法访问值:
LDocument.Aaa.Bbb.Items[0].Xxx.Nm
但是,如果<Nm>
XML中有2个节点,该如何访问呢?生成的接口仅支持单个<Nm>
节点。
IXMLParty = interface(IXMLNode)
{ Property Accessors }
function Get_Nm: UnicodeString;
procedure Set_Nm(Value: UnicodeString);
{ Methods & Properties }
property Nm: UnicodeString read Get_Nm write Set_Nm;
end;
您认为省略maxOccurs
元素定义中的属性将允许多个元素的假设<Nm>
是错误的。为默认值maxOccurs
,以及minOccurs
是1
。
要允许多个<Nm>
元素,您必须maxOccurs="unbounded"
在架构中明确指定(我将Max70Text
type替换为generic xs:string
):
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema targetNamespace="http://tempuri.org/XMLSchema.xsd" elementFormDefault="qualified"
xmlns="http://tempuri.org/XMLSchema.xsd" xmlns:mstns="http://tempuri.org/XMLSchema.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="Party">
<xs:sequence>
<xs:element name="Nm" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
生成的接口是:
{ IXMLParty }
IXMLParty = interface(IXMLNodeCollection)
{ Property Accessors }
function Get_Nm(Index: Integer): UnicodeString;
{ Methods & Properties }
function Add(const Nm: UnicodeString): IXMLNode;
function Insert(const Index: Integer; const Nm: UnicodeString): IXMLNode;
property Nm[Index: Integer]: UnicodeString read Get_Nm; default;
end;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句