简单的问题,实际上。只是好奇,如果其他人认识到这个问题,并且可能有一个有效的解决方案......
我有一个简单的XSD文件,我用它来定义我的应用程序使用的配置文件。我需要将此架构绑定到我的项目,这是使用XDBW完成的。在Delphi 2007中,这个向导只会将XSD识别为模式,因此我会为我的模式获得完美的代码。 我最近升级到Delphi XE,我想再次重新创建这个代码,只是为了它的乐趣。我可以使用旧代码,所以没问题。我只是想看看D-XE是否增加了一些改进。 不幸的是,D-XE像任何其他文件一样解释文件,并生成有助于我从代码创建此模式的代码。铮铮! (那是我头撞墙的声音......)我不想那样!我希望代码生成模式描述的XML! 那么,这个问题对其他用户来说是否熟悉?还有什么解决方案吗?
一种解决方案是只使用D2007源文件。但这不是答案,因为我只需要从D-XE那里做到这一点。
另一种解决方案是将xsd文件重命名为.biz扩展名。但这是一个非常难看的黑客......
答案 0 :(得分:3)
这确实是Delphi XE中的一个错误。 它现在在Embarcadero错误跟踪系统中作为条目88893
我尝试使用XML数据绑定向导在Rad Studio XE中导入下面的ASX.XSD文件,它就像你描述的那样工作:它导入XSD就好像它是XML而不是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>
这让我觉得这个单位:
{*****************************************************************************************************}
{ }
{ 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.
但是当使用.BIZ扩展名时,它会生成正确的单位:
{*****************************************************************************************************}
{ }
{ 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:QC很快就会这样。