我有以下xsd:
<xs:schema xmlns="urn:bookroom-schema" targetNamespace="urn:bookstore-schema"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="book" type="xs:string" />
<xs:complexType name="booktype">
<xs:sequence>
<xs:element name="author" type="xs:string" />
<xs:element name="title" type="xs:string" />
<xs:element name="price" type="xs:decimal" />
</xs:sequence>
</xs:complexType>`
<xs:element name="publisher" type="xs:string" />
</xs:schema>这就是程序。
procedure TForm1.AllElementsinSchema;
var oSchemaCache : XMLSchemaCache60;
oSchema : ISchema;
nsTarget: widestring;
kk : integer;
begin
oSchemaCache := coXMLSchemaCache60.Create;
nsTarget := 'urn:bookstore-schema';
oSchemaCache.add(nsTarget,'c:\book.xsd');
oSchema := oSchemaCache.getSchema(nsTarget);
for kk := 0 to pred(oSchema.elements.length) do
showmessage('elements[' + inttostr(kk) + '] : ' + oschema.elements.item[kk].name);
end;当我运行这个程序时,我得到了:
book
publisher 我如何获得它(所有元素,包括子元素)?
book
author
title
price
publisher 请指导我如何在Delphi中实现它。提前谢谢。
发布于 2011-09-08 18:20:41
您还必须为oSchema.types编写一个循环,因为booktype显然是一个类型(确切地说是complexType ),而不是and元素。
https://stackoverflow.com/questions/7343165
复制相似问题