XML数据绑定向导不会正确绑定XSD [英] XML Data Binding Wizard doesn't bind XSD's correctly

查看:135
本文介绍了XML数据绑定向导不会正确绑定XSD的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上,简单的问题。只是好奇,如果其他人认识到这个问题,也许有一个工作的解决方案...



我有一个简单的XSD文件,我用来定义使用的配置文件通过我的申请我需要将此架构绑定到我的项目,这是使用XDBW完成的。在Delphi 2007中,该向导只会将XSD视为模式,因此我将获得完美的代码。
我最近升级到Delphi XE,我想再次重新创建这个代码,只是为了它的乐趣。我可以使用旧的代码,所以没有问题。我只想看看D-XE是否增加了一些改进。
不幸的是,D-XE像任何其他文件一样解释文件,并生成代码,帮助我从代码创建这个模式。铮铮! (这是我的头撞墙的声音...)我不想要!我想要代码生成由模式描述的XML!
那么这个问题是其他用户熟悉的吗?任何解决方案?






一个解决方案是使用D2007源文件。这不是一个答案,但是,因为我需要从D-XE专门完成。






另一个解决方案是重命名xsd文件到.biz扩展名。但是这是一个非常丑的黑客...

解决方案

这是Delphi XE中的一个错误。
现在将Embarcadero错误跟踪系统作为条目 88893



我尝试使用XML数据绑定向导在Rad Studio XE中导入ASX.XSD文件,它的工作原理就像您所描述的那样:它导入XSD,就像它是XML而不是XSD。

 <?xml version =1.0encoding =utf-8?> ; 
< xsd:schema attributeFormDefault =unqualifiedelementFormDefault =qualifiedversion =1.0xmlns:xsd =http://www.w3.org/2001/XMLSchema>
< xsd:element name =asxtype =asxType/>
< xsd:complexType name =asxType>
< xsd:sequence>
< xsd:element name =titletype =xsd:string/>
< xsd:element maxOccurs =unboundedname =entrytype =entryType/>
< / xsd:sequence>
< xsd:attribute name =versiontype =xsd:decimal/>
< / xsd:complexType>
< xsd:complexType name =entryType>
< xsd:sequence>
< xsd:element name =titletype =xsd:string/>
< xsd:element name =reftype =refType/>
< xsd:element name =authortype =xsd:string/>
< / xsd:sequence>
< / xsd:complexType>
< xsd:complexType name =refType>
< xsd:attribute name =hreftype =xsd:string/>
< / xsd:complexType>
< / xsd:schema>

它得到我这个单位:

  {**************************************** ************************************** ***********} 
{}
{XML数据绑定}
{}
{生成于:10/12/2010 9:41: 06 PM}
{生成于:C:\develop\codeplex\TFS05\bo\Native\Delphi\Apps\NederlandFM2WMP\doc\ASX.xsd}
{设置存储在:C:\develop\codeplex\TFS05\bo\Native\Delphi\Apps\NederlandFM2WMP\doc\ASX.xdb}
{ }
{******************************************** ************************************** *******}

单位ASX;

接口

使用xmldom,XMLDoc,XMLIntf;

type

{Forward Decls}

IXMLSchemaType = interface;
IXMLElementType = interface;
IXMLComplexType = interface;
IXMLComplexTypeList = interface;
IXMLSequenceType = interface;
IXMLAttributeType = interface;

{IXMLSchemaType}

IXMLSchemaType =接口(IXMLNode)
['{F8A90A02-2236-4A50-A278-CFBB8625B36C}']
{属性Accessors}
函数Get_AttributeFormDefault:UnicodeString;
函数Get_ElementFormDefault:UnicodeString;
函数Get_Version:UnicodeString;
函数Get_Element:IXMLElementType;
函数Get_ComplexType:IXMLComplexTypeList;
程序Set_AttributeFormDefault(Value:UnicodeString);
程序Set_ElementFormDefault(Value:UnicodeString);
程序Set_Version(Value:UnicodeString);
{方法与属性}
属性AttributeFormDefault:UnicodeString读取Get_AttributeFormDefault写入Set_AttributeFormDefault;
属性ElementFormDefault:UnicodeString读取Get_ElementFormDefault写入Set_ElementFormDefault;
属性版本:UnicodeString读取Get_Version写入Set_Version;
属性元素:IXMLElementType读取Get_Element;
属性ComplexType:IXMLComplexTypeList读取Get_ComplexType;
结束

{IXMLElementType}

IXMLElementType =接口(IXMLNode)
['{9AAD80FD-06BC-4F82-9321-538F05522F83}']
{属性访问者}
函数Get_Name:UnicodeString;
函数Get_Type_:UnicodeString;
函数Get_MaxOccurs:UnicodeString;
procedure Set_Name(Value:UnicodeString);
procedure Set_Type_(Value:UnicodeString);
程序Set_MaxOccurs(Value:UnicodeString);
{方法与属性}
属性名称:UnicodeString读取Get_Name写入Set_Name;
属性Type_:UnicodeString read Get_Type_ write Set_Type_;
属性MaxOccurs:UnicodeString读取Get_MaxOccurs写入Set_MaxOccurs;
结束

{IXMLComplexType}

IXMLComplexType = interface(IXMLNode)
['{9C0618C5-D81F-4BB5-8DED-0BF9AF757ABD}']
{属性访问者}
函数Get_Name:UnicodeString;
函数Get_Sequence:IXMLSequenceType;
函数Get_Attribute:IXMLAttributeType;
procedure Set_Name(Value:UnicodeString);
{方法与属性}
属性名称:UnicodeString读取Get_Name写入Set_Name;
属性序列:IXMLSequenceType读取Get_Sequence;
属性属性:IXMLAttributeType读取Get_Attribute;
结束

{IXMLComplexTypeList}

IXMLComplexTypeList = interface(IXMLNodeCollection)
['{26C4DF98-1DCA-44C8-9D58-9BEB9348FA5B}']
{方法&属性}
function Add:IXMLComplexType;
function Insert(const Index:Integer):IXMLComplexType;

函数Get_Item(Index:Integer):IXMLComplexType;
属性项[Index:Integer]:IXMLComplexType读取Get_Item;默认;
结束

{IXMLSequenceType}

IXMLSequenceType =接口(IXMLNodeCollection)
['{9289143E-C0E2-462E-AD77-239966EEAEEC}']
{属性访问者}
函数Get_Element(Index:Integer):IXMLElementType;
{方法与属性}
函数Add:IXMLElementType;
函数Insert(const Index:Integer):IXMLElementType;
属性Element [Index:Integer]:IXMLElementType读取Get_Element;默认;
结束

{IXMLAttributeType}

IXMLAttributeType =接口(IXMLNode)
['{409542A8-7FB2-4C90-BE41-C081A0518773}']
{属性访问者}
函数Get_Name:UnicodeString;
函数Get_Type_:UnicodeString;
procedure Set_Name(Value:UnicodeString);
procedure Set_Type_(Value:UnicodeString);
{方法与属性}
属性名称:UnicodeString读取Get_Name写入Set_Name;
属性Type_:UnicodeString read Get_Type_ write Set_Type_;
结束

{Forward Decls}

TXMLSchemaType = class;
TXMLElementType = class;
TXMLComplexType = class;
TXMLComplexTypeList = class;
TXMLSequenceType = class;
TXMLAttributeType = class;

{TXMLSchemaType}

TXMLSchemaType = class(TXMLNode,IXMLSchemaType)
private
FComplexType:IXMLComplexTypeList;
protected
{IXMLSchemaType}
函数Get_AttributeFormDefault:UnicodeString;
函数Get_ElementFormDefault:UnicodeString;
函数Get_Version:UnicodeString;
函数Get_Element:IXMLElementType;
函数Get_ComplexType:IXMLComplexTypeList;
程序Set_AttributeFormDefault(Value:UnicodeString);
程序Set_ElementFormDefault(Value:UnicodeString);
程序Set_Version(Value:UnicodeString);
public
procedure AfterConstruction;覆盖
结束

{TXMLElementType}

TXMLElementType = class(TXMLNode,IXMLElementType)
protected
{IXMLElementType}
函数Get_Name:UnicodeString;
函数Get_Type_:UnicodeString;
函数Get_MaxOccurs:UnicodeString;
procedure Set_Name(Value:UnicodeString);
procedure Set_Type_(Value:UnicodeString);
程序Set_MaxOccurs(Value:UnicodeString);
结束

{TXMLComplexType}

TXMLComplexType = class(TXMLNode,IXMLComplexType)
protected
{IXMLComplexType}
函数Get_Name:UnicodeString;
函数Get_Sequence:IXMLSequenceType;
函数Get_Attribute:IXMLAttributeType;
procedure Set_Name(Value:UnicodeString);
public
procedure AfterConstruction;覆盖
结束

{TXMLComplexTypeList}

TXMLComplexTypeList = class(TXMLNodeCollection,IXMLComplexTypeList)
protected
{IXMLComplexTypeList}
function Add:IXMLComplexType;
function Insert(const Index:Integer):IXMLComplexType;

函数Get_Item(Index:Integer):IXMLComplexType;
结束

{TXMLSequenceType}

TXMLSequenceType = class(TXMLNodeCollection,IXMLSequenceType)
protected
{IXMLSequenceType}
函数Get_Element(Index:Integer) :IXMLElementType;
function Add:IXMLElementType;
函数Insert(const Index:Integer):IXMLElementType;
public
procedure AfterConstruction;覆盖
结束

{TXMLAttributeType}

TXMLAttributeType =类(TXMLNode,IXMLAttributeType)
protected
{IXMLAttributeType}
函数Get_Name:UnicodeString;
函数Get_Type_:UnicodeString;
procedure Set_Name(Value:UnicodeString);
procedure Set_Type_(Value:UnicodeString);
结束

{全局函数}

函数Getschema(Doc:IXMLDocument):IXMLSchemaType;
函数Loadschema(const FileName:string):IXMLSchemaType;
函数Newschema:IXMLSchemaType;

const
TargetNamespace ='http://www.w3.org/2001/XMLSchema';

实现

{全局函数}

函数Getschema(Doc:IXMLDocument):IXMLSchemaType;
begin
结果:= Doc.GetDocBinding('schema',TXMLSchemaType,TargetNamespace)为IXMLSchemaType;
结束

函数Loadschema(const FileName:string):IXMLSchemaType;
begin
结果:= LoadXMLDocument(FileName).GetDocBinding('schema',TXMLSchemaType,TargetNamespace)为IXMLSchemaType;
结束

函数Newschema:IXMLSchemaType;
begin
结果:= NewXMLDocument.GetDocBinding('schema',TXMLSchemaType,TargetNamespace)为IXMLSchemaType;
结束

{TXMLSchemaType}

程序TXMLSchemaType.AfterConstruction;
begin
RegisterChildNode('element',TXMLElementType);
RegisterChildNode('complexType',TXMLComplexType);
FComplexType:= CreateCollection(TXMLComplexTypeList,IXMLComplexType,'complexType')为IXMLComplexTypeList;
继承;
结束

函数TXMLSchemaType.Get_AttributeFormDefault:UnicodeString;
begin
结果:= AttributeNodes ['attributeFormDefault']。
结束

程序TXMLSchemaType.Set_AttributeFormDefault(Value:UnicodeString);
begin
SetAttribute('attributeFormDefault',Value);
结束

函数TXMLSchemaType.Get_ElementFormDefault:UnicodeString;
begin
结果:= AttributeNodes ['elementFormDefault']。
结束

procedure TXMLSchemaType.Set_ElementFormDefault(Value:UnicodeString);
begin
SetAttribute('elementFormDefault',Value);
结束

函数TXMLSchemaType.Get_Version:UnicodeString;
begin
结果:= AttributeNodes ['version']。
结束

程序TXMLSchemaType.Set_Version(值:UnicodeString);
begin
SetAttribute('version',Value);
结束

函数TXMLSchemaType.Get_Element:IXMLElementType;
begin
结果:= ChildNodes ['element'] as IXMLElementType;
结束

函数TXMLSchemaType.Get_ComplexType:IXMLComplexTypeList;
begin
结果:= FComplexType;
结束

{TXMLElementType}

函数TXMLElementType.Get_Name:UnicodeString;
begin
结果:= AttributeNodes ['name']。文本;
结束

procedure TXMLElementType.Set_Name(Value:UnicodeString);
begin
SetAttribute('name',Value);
结束

函数TXMLElementType.Get_Type_:UnicodeString;
begin
结果:= AttributeNodes ['type']。
结束

procedure TXMLElementType.Set_Type_(Value:UnicodeString);
begin
SetAttribute('type',Value);
结束

函数TXMLElementType.Get_MaxOccurs:UnicodeString;
begin
结果:= AttributeNodes ['maxOccurs']。
结束

procedure TXMLElementType.Set_MaxOccurs(Value:UnicodeString);
begin
SetAttribute('maxOccurs',Value);
结束

{TXMLComplexType}

程序TXMLComplexType.AfterConstruction;
begin
RegisterChildNode('sequence',TXMLSequenceType);
RegisterChildNode('attribute',TXMLAttributeType);
继承;
结束

函数TXMLComplexType.Get_Name:UnicodeString;
begin
结果:= AttributeNodes ['name']。文本;
结束

procedure TXMLComplexType.Set_Name(Value:UnicodeString);
begin
SetAttribute('name',Value);
结束

函数TXMLComplexType.Get_Sequence:IXMLSequenceType;
begin
Result:= ChildNodes ['sequence'] as IXMLSequenceType;
结束

函数TXMLComplexType.Get_Attribute:IXMLAttributeType;
begin
Result:= ChildNodes ['attribute'] as IXMLAttributeType;
结束

{TXMLComplexTypeList}

函数TXMLComplexTypeList.Add:IXMLComplexType;
begin
结果:= AddItem(-1)为IXMLComplexType;
结束

函数TXMLComplexTypeList.Insert(const Index:Integer):IXMLComplexType;
begin
结果:= AddItem(Index)为IXMLComplexType;
结束

函数TXMLComplexTypeList.Get_Item(Index:Integer):IXMLComplexType;
begin
结果:= List [Index]为IXMLComplexType;
结束

{TXMLSequenceType}

procedure TXMLSequenceType.AfterConstruction;
begin
RegisterChildNode('element',TXMLElementType);
ItemTag:='element';
ItemInterface:= IXMLElementType;
继承;
结束

函数TXMLSequenceType.Get_Element(Index:Integer):IXMLElementType;
begin
结果:= List [Index] as IXMLElementType;
结束

函数TXMLSequenceType.Add:IXMLElementType;
begin
Result:= AddItem(-1)as IXMLElementType;
结束

函数TXMLSequenceType.Insert(const Index:Integer):IXMLElementType;
begin
结果:= AddItem(Index)为IXMLElementType;
结束

{TXMLAttributeType}

函数TXMLAttributeType.Get_Name:UnicodeString;
begin
结果:= AttributeNodes ['name']。文本;
结束

procedure TXMLAttributeType.Set_Name(Value:UnicodeString);
begin
SetAttribute('name',Value);
结束

函数TXMLAttributeType.Get_Type_:UnicodeString;
begin
结果:= AttributeNodes ['type']。
结束

procedure TXMLAttributeType.Set_Type_(Value:UnicodeString);
begin
SetAttribute('type',Value);
结束

结束。

但是,当使用.BIZ扩展名时,它会生成正确的单位:

  {****************************** ************************************** ******************* $ 
{}
{XML数据绑定}
{}
{生成于:10 / 12/2010 9:47:29 PM}
{生成自:C:\develop\codeplex\TFS05\bo\Native\Delphi\Apps\NederlandFM2WMP\doc\ ASX.biz}
{存储在以下位置的设置:C:\develop\codeplex\TFS05\bo\Native\Delphi\Apps\NederlandFM2WMP\doc\ASX.xdb}
{ }
{******************************************** ************************************** *******}

单位ASXUnit;

接口

使用xmldom,XMLDoc,XMLIntf;

type

{Forward Decls}

IXMLAsxType = interface;
IXMLEntryType = interface;
IXMLEntryTypeList = interface;
IXMLRefType = interface;

{IXMLAsxType}

IXMLAsxType =接口(IXMLNode)
['{491F413D-0118-47A0-A00E-1BB7FCAD96C2}']
{属性Accessors}
函数Get_Version:UnicodeString;
函数Get_Title:UnicodeString;
函数Get_Entry:IXMLEntryTypeList;
程序Set_Version(Value:UnicodeString);
程序Set_Title(Value:UnicodeString);
{方法与属性}
属性版本:UnicodeString读取Get_Version写入Set_Version;
属性标题:UnicodeString read Get_Title write Set_Title;
属性条目:IXMLEntryTypeList读取Get_Entry;
结束

{IXMLEntryType}

IXMLEntryType =接口(IXMLNode)
['{E1F7A8DC-0893-4853-BFFD-19D22AF3313C}']
{属性访问者}
函数Get_Title:UnicodeString;
函数Get_Ref:IXMLRefType;
函数Get_Author:UnicodeString;
程序Set_Title(Value:UnicodeString);
程序Set_Author(Value:UnicodeString);
{方法与属性}
属性标题:UnicodeString读取Get_Title写入Set_Title;
属性参考:IXMLRefType读取Get_Ref;
属性作者:UnicodeString read Get_Author写Set_Author;
结束

{IXMLEntryTypeList}

IXMLEntryTypeList = interface(IXMLNodeCollection)
['{4CA3727D-89DA-4498-B617-48D413D63887}']
{方法&属性}
function Add:IXMLEntryType;
function Insert(const Index:Integer):IXMLEntryType;

函数Get_Item(Index:Integer):IXMLEntryType;
属性项[Index:Integer]:IXMLEntryType读取Get_Item;默认;
结束

{IXMLRefType}

IXMLRefType =接口(IXMLNode)
['{0860418C-E35A-4315-8B1C-7C0D19C45740}']
{属性访问者}
函数Get_Href:UnicodeString;
程序Set_Href(Value:UnicodeString);
{方法与属性}
属性Href:UnicodeString读取Get_Href写入Set_Href;
结束

{Forward Decls}

TXMLAsxType = class;
TXMLEntryType = class;
TXMLEntryTypeList = class;
TXMLRefType = class;

{TXMLAsxType}

TXMLAsxType = class(TXMLNode,IXMLAsxType)
private
FEntry:IXMLEntryTypeList;
protected
{IXMLAsxType}
函数Get_Version:UnicodeString;
函数Get_Title:UnicodeString;
函数Get_Entry:IXMLEntryTypeList;
程序Set_Version(Value:UnicodeString);
程序Set_Title(Value:UnicodeString);
public
procedure AfterConstruction;覆盖
结束

{TXMLEntryType}

TXMLEntryType = class(TXMLNode,IXMLEntryType)
protected
{IXMLEntryType}
函数Get_Title:UnicodeString;
函数Get_Ref:IXMLRefType;
函数Get_Author:UnicodeString;
程序Set_Title(Value:UnicodeString);
程序Set_Author(Value:UnicodeString);
public
procedure AfterConstruction;覆盖
结束

{TXMLEntryTypeList}

TXMLEntryTypeList = class(TXMLNodeCollection,IXMLEntryTypeList)
protected
{IXMLEntryTypeList}
函数Add:IXMLEntryType;
function Insert(const Index:Integer):IXMLEntryType;

函数Get_Item(Index:Integer):IXMLEntryType;
结束

{TXMLRefType}

TXMLRefType = class(TXMLNode,IXMLRefType)
protected
{IXMLRefType}
函数Get_Href:UnicodeString;
程序Set_Href(Value:UnicodeString);
结束

{全局函数}

函数Getasx(Doc:IXMLDocument):IXMLAsxType;
函数Loadasx(const FileName:string):IXMLAsxType;
函数Newasx:IXMLAsxType;

const
TargetNamespace ='';

实现

{全局函数}

函数Getasx(Doc:IXMLDocument):IXMLAsxType;
begin
结果:= Doc.GetDocBinding('asx',TXMLAsxType,TargetNamespace)为IXMLAsxType;
结束

函数Loadasx(const FileName:string):IXMLAsxType;
begin
结果:= LoadXMLDocument(FileName).GetDocBinding('asx',TXMLAsxType,TargetNamespace)为IXMLAsxType;
结束

函数Newasx:IXMLAsxType;
begin
结果:= NewXMLDocument.GetDocBinding('asx',TXMLAsxType,TargetNamespace)为IXMLAsxType;
结束

{TXMLAsxType}

程序TXMLAsxType.AfterConstruction;
begin
RegisterChildNode('entry',TXMLEntryType);
FEntry:= CreateCollection(TXMLEntryTypeList,IXMLEntryType,'entry')为IXMLEntryTypeList;
继承;
结束

函数TXMLAsxType.Get_Version:UnicodeString;
begin
结果:= AttributeNodes ['version']。
结束

procedure TXMLAsxType.Set_Version(Value:UnicodeString);
begin
SetAttribute('version',Value);
结束

函数TXMLAsxType.Get_Title:UnicodeString;
begin
结果:= ChildNodes ['title']。
结束

程序TXMLAsxType.Set_Title(值:UnicodeString);
begin
ChildNodes ['title']。NodeValue:= Value;
结束

函数TXMLAsxType.Get_Entry:IXMLEntryTypeList;
begin
结果:= FEntry;
结束

{TXMLEntryType}

程序TXMLEntryType.AfterConstruction;
begin
RegisterChildNode('ref',TXMLRefType);
继承;
结束

函数TXMLEntryType.Get_Title:UnicodeString;
begin
结果:= ChildNodes ['title']。
结束

procedure TXMLEntryType.Set_Title(Value:UnicodeString);
begin
ChildNodes ['title']。NodeValue:= Value;
结束

函数TXMLEntryType.Get_Ref:IXMLRefType;
begin
结果:= ChildNodes ['ref'] as IXMLRefType;
结束

函数TXMLEntryType.Get_Author:UnicodeString;
begin
结果:= ChildNodes ['author']。Text;
结束

procedure TXMLEntryType.Set_Author(Value:UnicodeString);
begin
ChildNodes ['author']。NodeValue:= Value;
结束

{TXMLEntryTypeList}

函数TXMLEntryTypeList.Add:IXMLEntryType;
begin
结果:= AddItem(-1)为IXMLEntryType;
结束

函数TXMLEntryTypeList.Insert(const Index:Integer):IXMLEntryType;
begin
Result:= AddItem(Index)as IXMLEntryType;
结束

函数TXMLEntryTypeList.Get_Item(Index:Integer):IXMLEntryType;
begin
结果:= List [Index]为IXMLEntryType;
结束

{TXMLRefType}

函数TXMLRefType.Get_Href:UnicodeString;
begin
结果:= AttributeNodes ['href']。
结束

procedure TXMLRefType.Set_Href(Value:UnicodeString);
begin
SetAttribute('href',Value);
结束

结束。

错误:将尽快QC。


Simple issue, actually. Just curious if others recognize the problem and perhaps have a working solution for it...

I have a simple XSD file which I use to define a configuration file that is used by my application. I need to bind this schema to my project and this is done using the XDBW. In Delphi 2007, this wizard would just recognise an XSD as a schema and thus I would get perfect code for my schema. I recently upgraded to Delphi XE and I want to recreate this code again, just for the fun of it. I could use the old code, so no problem there. I just want to see if D-XE had added some improvements. Unfortunately, D-XE interprets the file just like any other file and generates code that would help me to create this schema from code. CLANK! (That's the sound of my head hitting a wall...) I don't want that! I want code to generate the XML that is described by the schema! So, is this problem familiar for other users? Any solutions yet?


One solution is to just use the D2007 source files. That's not an answer, though, since I need to do this exclusively from D-XE.


Another solution is by renaming the xsd file to an .biz extension. But this is an extremely ugly hack...

解决方案

This is indeed a bug in Delphi XE. It is now in the Embarcadero bug tracking system as entry 88893

I tried importing the ASX.XSD file below in Rad Studio XE using the XML Data Binding Wizard, and it just works like you describe: it imports the XSD as if it were XML in stead of XSD.

<?xml version="1.0" encoding="utf-8"?>
<xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" version="1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:element name="asx" type="asxType" />
  <xsd:complexType name="asxType">
    <xsd:sequence>
      <xsd:element name="title" type="xsd:string" />
      <xsd:element maxOccurs="unbounded" name="entry" type="entryType" />
    </xsd:sequence>
    <xsd:attribute name="version" type="xsd:decimal" />
  </xsd:complexType>
  <xsd:complexType name="entryType">
    <xsd:sequence>
      <xsd:element name="title" type="xsd:string" />
      <xsd:element name="ref" type="refType" />
      <xsd:element name="author" type="xsd:string" />
    </xsd:sequence>
  </xsd:complexType>
  <xsd:complexType name="refType">
    <xsd:attribute name="href" type="xsd:string" />
  </xsd:complexType>
</xsd:schema>

It gets me this unit:

{*****************************************************************************************************}
{                                                                                                     }
{                                          XML Data Binding                                           }
{                                                                                                     }
{         Generated on: 10/12/2010 9:41:06 PM                                                         }
{       Generated from: C:\develop\codeplex\TFS05\bo\Native\Delphi\Apps\NederlandFM2WMP\doc\ASX.xsd   }
{   Settings stored in: C:\develop\codeplex\TFS05\bo\Native\Delphi\Apps\NederlandFM2WMP\doc\ASX.xdb   }
{                                                                                                     }
{*****************************************************************************************************}

unit ASX;

interface

uses xmldom, XMLDoc, XMLIntf;

type

{ Forward Decls }

  IXMLSchemaType = interface;
  IXMLElementType = interface;
  IXMLComplexType = interface;
  IXMLComplexTypeList = interface;
  IXMLSequenceType = interface;
  IXMLAttributeType = interface;

{ IXMLSchemaType }

  IXMLSchemaType = interface(IXMLNode)
    ['{F8A90A02-2236-4A50-A278-CFBB8625B36C}']
    { Property Accessors }
    function Get_AttributeFormDefault: UnicodeString;
    function Get_ElementFormDefault: UnicodeString;
    function Get_Version: UnicodeString;
    function Get_Element: IXMLElementType;
    function Get_ComplexType: IXMLComplexTypeList;
    procedure Set_AttributeFormDefault(Value: UnicodeString);
    procedure Set_ElementFormDefault(Value: UnicodeString);
    procedure Set_Version(Value: UnicodeString);
    { Methods & Properties }
    property AttributeFormDefault: UnicodeString read Get_AttributeFormDefault write Set_AttributeFormDefault;
    property ElementFormDefault: UnicodeString read Get_ElementFormDefault write Set_ElementFormDefault;
    property Version: UnicodeString read Get_Version write Set_Version;
    property Element: IXMLElementType read Get_Element;
    property ComplexType: IXMLComplexTypeList read Get_ComplexType;
  end;

{ IXMLElementType }

  IXMLElementType = interface(IXMLNode)
    ['{9AAD80FD-06BC-4F82-9321-538F05522F83}']
    { Property Accessors }
    function Get_Name: UnicodeString;
    function Get_Type_: UnicodeString;
    function Get_MaxOccurs: UnicodeString;
    procedure Set_Name(Value: UnicodeString);
    procedure Set_Type_(Value: UnicodeString);
    procedure Set_MaxOccurs(Value: UnicodeString);
    { Methods & Properties }
    property Name: UnicodeString read Get_Name write Set_Name;
    property Type_: UnicodeString read Get_Type_ write Set_Type_;
    property MaxOccurs: UnicodeString read Get_MaxOccurs write Set_MaxOccurs;
  end;

{ IXMLComplexType }

  IXMLComplexType = interface(IXMLNode)
    ['{9C0618C5-D81F-4BB5-8DED-0BF9AF757ABD}']
    { Property Accessors }
    function Get_Name: UnicodeString;
    function Get_Sequence: IXMLSequenceType;
    function Get_Attribute: IXMLAttributeType;
    procedure Set_Name(Value: UnicodeString);
    { Methods & Properties }
    property Name: UnicodeString read Get_Name write Set_Name;
    property Sequence: IXMLSequenceType read Get_Sequence;
    property Attribute: IXMLAttributeType read Get_Attribute;
  end;

{ IXMLComplexTypeList }

  IXMLComplexTypeList = interface(IXMLNodeCollection)
    ['{26C4DF98-1DCA-44C8-9D58-9BEB9348FA5B}']
    { Methods & Properties }
    function Add: IXMLComplexType;
    function Insert(const Index: Integer): IXMLComplexType;

    function Get_Item(Index: Integer): IXMLComplexType;
    property Items[Index: Integer]: IXMLComplexType read Get_Item; default;
  end;

{ IXMLSequenceType }

  IXMLSequenceType = interface(IXMLNodeCollection)
    ['{9289143E-C0E2-462E-AD77-239966EEAEEC}']
    { Property Accessors }
    function Get_Element(Index: Integer): IXMLElementType;
    { Methods & Properties }
    function Add: IXMLElementType;
    function Insert(const Index: Integer): IXMLElementType;
    property Element[Index: Integer]: IXMLElementType read Get_Element; default;
  end;

{ IXMLAttributeType }

  IXMLAttributeType = interface(IXMLNode)
    ['{409542A8-7FB2-4C90-BE41-C081A0518773}']
    { Property Accessors }
    function Get_Name: UnicodeString;
    function Get_Type_: UnicodeString;
    procedure Set_Name(Value: UnicodeString);
    procedure Set_Type_(Value: UnicodeString);
    { Methods & Properties }
    property Name: UnicodeString read Get_Name write Set_Name;
    property Type_: UnicodeString read Get_Type_ write Set_Type_;
  end;

{ Forward Decls }

  TXMLSchemaType = class;
  TXMLElementType = class;
  TXMLComplexType = class;
  TXMLComplexTypeList = class;
  TXMLSequenceType = class;
  TXMLAttributeType = class;

{ TXMLSchemaType }

  TXMLSchemaType = class(TXMLNode, IXMLSchemaType)
  private
    FComplexType: IXMLComplexTypeList;
  protected
    { IXMLSchemaType }
    function Get_AttributeFormDefault: UnicodeString;
    function Get_ElementFormDefault: UnicodeString;
    function Get_Version: UnicodeString;
    function Get_Element: IXMLElementType;
    function Get_ComplexType: IXMLComplexTypeList;
    procedure Set_AttributeFormDefault(Value: UnicodeString);
    procedure Set_ElementFormDefault(Value: UnicodeString);
    procedure Set_Version(Value: UnicodeString);
  public
    procedure AfterConstruction; override;
  end;

{ TXMLElementType }

  TXMLElementType = class(TXMLNode, IXMLElementType)
  protected
    { IXMLElementType }
    function Get_Name: UnicodeString;
    function Get_Type_: UnicodeString;
    function Get_MaxOccurs: UnicodeString;
    procedure Set_Name(Value: UnicodeString);
    procedure Set_Type_(Value: UnicodeString);
    procedure Set_MaxOccurs(Value: UnicodeString);
  end;

{ TXMLComplexType }

  TXMLComplexType = class(TXMLNode, IXMLComplexType)
  protected
    { IXMLComplexType }
    function Get_Name: UnicodeString;
    function Get_Sequence: IXMLSequenceType;
    function Get_Attribute: IXMLAttributeType;
    procedure Set_Name(Value: UnicodeString);
  public
    procedure AfterConstruction; override;
  end;

{ TXMLComplexTypeList }

  TXMLComplexTypeList = class(TXMLNodeCollection, IXMLComplexTypeList)
  protected
    { IXMLComplexTypeList }
    function Add: IXMLComplexType;
    function Insert(const Index: Integer): IXMLComplexType;

    function Get_Item(Index: Integer): IXMLComplexType;
  end;

{ TXMLSequenceType }

  TXMLSequenceType = class(TXMLNodeCollection, IXMLSequenceType)
  protected
    { IXMLSequenceType }
    function Get_Element(Index: Integer): IXMLElementType;
    function Add: IXMLElementType;
    function Insert(const Index: Integer): IXMLElementType;
  public
    procedure AfterConstruction; override;
  end;

{ TXMLAttributeType }

  TXMLAttributeType = class(TXMLNode, IXMLAttributeType)
  protected
    { IXMLAttributeType }
    function Get_Name: UnicodeString;
    function Get_Type_: UnicodeString;
    procedure Set_Name(Value: UnicodeString);
    procedure Set_Type_(Value: UnicodeString);
  end;

{ Global Functions }

function Getschema(Doc: IXMLDocument): IXMLSchemaType;
function Loadschema(const FileName: string): IXMLSchemaType;
function Newschema: IXMLSchemaType;

const
  TargetNamespace = 'http://www.w3.org/2001/XMLSchema';

implementation

{ Global Functions }

function Getschema(Doc: IXMLDocument): IXMLSchemaType;
begin
  Result := Doc.GetDocBinding('schema', TXMLSchemaType, TargetNamespace) as IXMLSchemaType;
end;

function Loadschema(const FileName: string): IXMLSchemaType;
begin
  Result := LoadXMLDocument(FileName).GetDocBinding('schema', TXMLSchemaType, TargetNamespace) as IXMLSchemaType;
end;

function Newschema: IXMLSchemaType;
begin
  Result := NewXMLDocument.GetDocBinding('schema', TXMLSchemaType, TargetNamespace) as IXMLSchemaType;
end;

{ TXMLSchemaType }

procedure TXMLSchemaType.AfterConstruction;
begin
  RegisterChildNode('element', TXMLElementType);
  RegisterChildNode('complexType', TXMLComplexType);
  FComplexType := CreateCollection(TXMLComplexTypeList, IXMLComplexType, 'complexType') as IXMLComplexTypeList;
  inherited;
end;

function TXMLSchemaType.Get_AttributeFormDefault: UnicodeString;
begin
  Result := AttributeNodes['attributeFormDefault'].Text;
end;

procedure TXMLSchemaType.Set_AttributeFormDefault(Value: UnicodeString);
begin
  SetAttribute('attributeFormDefault', Value);
end;

function TXMLSchemaType.Get_ElementFormDefault: UnicodeString;
begin
  Result := AttributeNodes['elementFormDefault'].Text;
end;

procedure TXMLSchemaType.Set_ElementFormDefault(Value: UnicodeString);
begin
  SetAttribute('elementFormDefault', Value);
end;

function TXMLSchemaType.Get_Version: UnicodeString;
begin
  Result := AttributeNodes['version'].Text;
end;

procedure TXMLSchemaType.Set_Version(Value: UnicodeString);
begin
  SetAttribute('version', Value);
end;

function TXMLSchemaType.Get_Element: IXMLElementType;
begin
  Result := ChildNodes['element'] as IXMLElementType;
end;

function TXMLSchemaType.Get_ComplexType: IXMLComplexTypeList;
begin
  Result := FComplexType;
end;

{ TXMLElementType }

function TXMLElementType.Get_Name: UnicodeString;
begin
  Result := AttributeNodes['name'].Text;
end;

procedure TXMLElementType.Set_Name(Value: UnicodeString);
begin
  SetAttribute('name', Value);
end;

function TXMLElementType.Get_Type_: UnicodeString;
begin
  Result := AttributeNodes['type'].Text;
end;

procedure TXMLElementType.Set_Type_(Value: UnicodeString);
begin
  SetAttribute('type', Value);
end;

function TXMLElementType.Get_MaxOccurs: UnicodeString;
begin
  Result := AttributeNodes['maxOccurs'].Text;
end;

procedure TXMLElementType.Set_MaxOccurs(Value: UnicodeString);
begin
  SetAttribute('maxOccurs', Value);
end;

{ TXMLComplexType }

procedure TXMLComplexType.AfterConstruction;
begin
  RegisterChildNode('sequence', TXMLSequenceType);
  RegisterChildNode('attribute', TXMLAttributeType);
  inherited;
end;

function TXMLComplexType.Get_Name: UnicodeString;
begin
  Result := AttributeNodes['name'].Text;
end;

procedure TXMLComplexType.Set_Name(Value: UnicodeString);
begin
  SetAttribute('name', Value);
end;

function TXMLComplexType.Get_Sequence: IXMLSequenceType;
begin
  Result := ChildNodes['sequence'] as IXMLSequenceType;
end;

function TXMLComplexType.Get_Attribute: IXMLAttributeType;
begin
  Result := ChildNodes['attribute'] as IXMLAttributeType;
end;

{ TXMLComplexTypeList }

function TXMLComplexTypeList.Add: IXMLComplexType;
begin
  Result := AddItem(-1) as IXMLComplexType;
end;

function TXMLComplexTypeList.Insert(const Index: Integer): IXMLComplexType;
begin
  Result := AddItem(Index) as IXMLComplexType;
end;

function TXMLComplexTypeList.Get_Item(Index: Integer): IXMLComplexType;
begin
  Result := List[Index] as IXMLComplexType;
end;

{ TXMLSequenceType }

procedure TXMLSequenceType.AfterConstruction;
begin
  RegisterChildNode('element', TXMLElementType);
  ItemTag := 'element';
  ItemInterface := IXMLElementType;
  inherited;
end;

function TXMLSequenceType.Get_Element(Index: Integer): IXMLElementType;
begin
  Result := List[Index] as IXMLElementType;
end;

function TXMLSequenceType.Add: IXMLElementType;
begin
  Result := AddItem(-1) as IXMLElementType;
end;

function TXMLSequenceType.Insert(const Index: Integer): IXMLElementType;
begin
  Result := AddItem(Index) as IXMLElementType;
end;

{ TXMLAttributeType }

function TXMLAttributeType.Get_Name: UnicodeString;
begin
  Result := AttributeNodes['name'].Text;
end;

procedure TXMLAttributeType.Set_Name(Value: UnicodeString);
begin
  SetAttribute('name', Value);
end;

function TXMLAttributeType.Get_Type_: UnicodeString;
begin
  Result := AttributeNodes['type'].Text;
end;

procedure TXMLAttributeType.Set_Type_(Value: UnicodeString);
begin
  SetAttribute('type', Value);
end;

end.

But when using the .BIZ extension, it generates the correct unit:

{*****************************************************************************************************}
{                                                                                                     }
{                                          XML Data Binding                                           }
{                                                                                                     }
{         Generated on: 10/12/2010 9:47:29 PM                                                         }
{       Generated from: C:\develop\codeplex\TFS05\bo\Native\Delphi\Apps\NederlandFM2WMP\doc\ASX.biz   }
{   Settings stored in: C:\develop\codeplex\TFS05\bo\Native\Delphi\Apps\NederlandFM2WMP\doc\ASX.xdb   }
{                                                                                                     }
{*****************************************************************************************************}

unit ASXUnit;

interface

uses xmldom, XMLDoc, XMLIntf;

type

{ Forward Decls }

  IXMLAsxType = interface;
  IXMLEntryType = interface;
  IXMLEntryTypeList = interface;
  IXMLRefType = interface;

{ IXMLAsxType }

  IXMLAsxType = interface(IXMLNode)
    ['{491F413D-0118-47A0-A00E-1BB7FCAD96C2}']
    { Property Accessors }
    function Get_Version: UnicodeString;
    function Get_Title: UnicodeString;
    function Get_Entry: IXMLEntryTypeList;
    procedure Set_Version(Value: UnicodeString);
    procedure Set_Title(Value: UnicodeString);
    { Methods & Properties }
    property Version: UnicodeString read Get_Version write Set_Version;
    property Title: UnicodeString read Get_Title write Set_Title;
    property Entry: IXMLEntryTypeList read Get_Entry;
  end;

{ IXMLEntryType }

  IXMLEntryType = interface(IXMLNode)
    ['{E1F7A8DC-0893-4853-BFFD-19D22AF3313C}']
    { Property Accessors }
    function Get_Title: UnicodeString;
    function Get_Ref: IXMLRefType;
    function Get_Author: UnicodeString;
    procedure Set_Title(Value: UnicodeString);
    procedure Set_Author(Value: UnicodeString);
    { Methods & Properties }
    property Title: UnicodeString read Get_Title write Set_Title;
    property Ref: IXMLRefType read Get_Ref;
    property Author: UnicodeString read Get_Author write Set_Author;
  end;

{ IXMLEntryTypeList }

  IXMLEntryTypeList = interface(IXMLNodeCollection)
    ['{4CA3727D-89DA-4498-B617-48D413D63887}']
    { Methods & Properties }
    function Add: IXMLEntryType;
    function Insert(const Index: Integer): IXMLEntryType;

    function Get_Item(Index: Integer): IXMLEntryType;
    property Items[Index: Integer]: IXMLEntryType read Get_Item; default;
  end;

{ IXMLRefType }

  IXMLRefType = interface(IXMLNode)
    ['{0860418C-E35A-4315-8B1C-7C0D19C45740}']
    { Property Accessors }
    function Get_Href: UnicodeString;
    procedure Set_Href(Value: UnicodeString);
    { Methods & Properties }
    property Href: UnicodeString read Get_Href write Set_Href;
  end;

{ Forward Decls }

  TXMLAsxType = class;
  TXMLEntryType = class;
  TXMLEntryTypeList = class;
  TXMLRefType = class;

{ TXMLAsxType }

  TXMLAsxType = class(TXMLNode, IXMLAsxType)
  private
    FEntry: IXMLEntryTypeList;
  protected
    { IXMLAsxType }
    function Get_Version: UnicodeString;
    function Get_Title: UnicodeString;
    function Get_Entry: IXMLEntryTypeList;
    procedure Set_Version(Value: UnicodeString);
    procedure Set_Title(Value: UnicodeString);
  public
    procedure AfterConstruction; override;
  end;

{ TXMLEntryType }

  TXMLEntryType = class(TXMLNode, IXMLEntryType)
  protected
    { IXMLEntryType }
    function Get_Title: UnicodeString;
    function Get_Ref: IXMLRefType;
    function Get_Author: UnicodeString;
    procedure Set_Title(Value: UnicodeString);
    procedure Set_Author(Value: UnicodeString);
  public
    procedure AfterConstruction; override;
  end;

{ TXMLEntryTypeList }

  TXMLEntryTypeList = class(TXMLNodeCollection, IXMLEntryTypeList)
  protected
    { IXMLEntryTypeList }
    function Add: IXMLEntryType;
    function Insert(const Index: Integer): IXMLEntryType;

    function Get_Item(Index: Integer): IXMLEntryType;
  end;

{ TXMLRefType }

  TXMLRefType = class(TXMLNode, IXMLRefType)
  protected
    { IXMLRefType }
    function Get_Href: UnicodeString;
    procedure Set_Href(Value: UnicodeString);
  end;

{ Global Functions }

function Getasx(Doc: IXMLDocument): IXMLAsxType;
function Loadasx(const FileName: string): IXMLAsxType;
function Newasx: IXMLAsxType;

const
  TargetNamespace = '';

implementation

{ Global Functions }

function Getasx(Doc: IXMLDocument): IXMLAsxType;
begin
  Result := Doc.GetDocBinding('asx', TXMLAsxType, TargetNamespace) as IXMLAsxType;
end;

function Loadasx(const FileName: string): IXMLAsxType;
begin
  Result := LoadXMLDocument(FileName).GetDocBinding('asx', TXMLAsxType, TargetNamespace) as IXMLAsxType;
end;

function Newasx: IXMLAsxType;
begin
  Result := NewXMLDocument.GetDocBinding('asx', TXMLAsxType, TargetNamespace) as IXMLAsxType;
end;

{ TXMLAsxType }

procedure TXMLAsxType.AfterConstruction;
begin
  RegisterChildNode('entry', TXMLEntryType);
  FEntry := CreateCollection(TXMLEntryTypeList, IXMLEntryType, 'entry') as IXMLEntryTypeList;
  inherited;
end;

function TXMLAsxType.Get_Version: UnicodeString;
begin
  Result := AttributeNodes['version'].Text;
end;

procedure TXMLAsxType.Set_Version(Value: UnicodeString);
begin
  SetAttribute('version', Value);
end;

function TXMLAsxType.Get_Title: UnicodeString;
begin
  Result := ChildNodes['title'].Text;
end;

procedure TXMLAsxType.Set_Title(Value: UnicodeString);
begin
  ChildNodes['title'].NodeValue := Value;
end;

function TXMLAsxType.Get_Entry: IXMLEntryTypeList;
begin
  Result := FEntry;
end;

{ TXMLEntryType }

procedure TXMLEntryType.AfterConstruction;
begin
  RegisterChildNode('ref', TXMLRefType);
  inherited;
end;

function TXMLEntryType.Get_Title: UnicodeString;
begin
  Result := ChildNodes['title'].Text;
end;

procedure TXMLEntryType.Set_Title(Value: UnicodeString);
begin
  ChildNodes['title'].NodeValue := Value;
end;

function TXMLEntryType.Get_Ref: IXMLRefType;
begin
  Result := ChildNodes['ref'] as IXMLRefType;
end;

function TXMLEntryType.Get_Author: UnicodeString;
begin
  Result := ChildNodes['author'].Text;
end;

procedure TXMLEntryType.Set_Author(Value: UnicodeString);
begin
  ChildNodes['author'].NodeValue := Value;
end;

{ TXMLEntryTypeList }

function TXMLEntryTypeList.Add: IXMLEntryType;
begin
  Result := AddItem(-1) as IXMLEntryType;
end;

function TXMLEntryTypeList.Insert(const Index: Integer): IXMLEntryType;
begin
  Result := AddItem(Index) as IXMLEntryType;
end;

function TXMLEntryTypeList.Get_Item(Index: Integer): IXMLEntryType;
begin
  Result := List[Index] as IXMLEntryType;
end;

{ TXMLRefType }

function TXMLRefType.Get_Href: UnicodeString;
begin
  Result := AttributeNodes['href'].Text;
end;

procedure TXMLRefType.Set_Href(Value: UnicodeString);
begin
  SetAttribute('href', Value);
end;

end.

Bug: Will QC this soon.

这篇关于XML数据绑定向导不会正确绑定XSD的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆