XML Data Binding-Assistent nicht binden XSD ist richtig
Frage
Einfache Frage, eigentlich. Einfach nur neugierig, wenn andere erkennen das Problem und vielleicht eine funktionierende Lösung für sie haben ...
Ich habe eine einfache XSD-Datei, die ich verwende, um eine Konfigurationsdatei zu definieren, die durch meine Anwendung verwendet wird. Ich brauche dieses Schema zu meinem Projekt zu binden, und dies wird mit dem XDBW getan. In Delphi 2007, würde dieser Assistent nur ein XSD als Schema erkennen und somit würde ich perfekt Code für mein Schema erhalten. Ich Delphi XE kürzlich aktualisiert und ich möchte wieder diesen Code erstellen, nur für den Spaß von ihm. Ich konnte den alten Code, also kein Problem dort verwenden. Ich will nur sehen, ob D-XE einige Verbesserungen hinzugefügt hatte. Leider interpretiert D-XE die Datei wie jede andere Datei und generiert Code, der mir helfen würde dieses Schema von Code zu erstellen. RASSELN! (Das ist der Klang meines Kopfes eine Wand schlagen ...) Ich will nicht, dass! Ich möchte Code die XML zu erzeugen, die durch das Schema beschrieben wird! So ist dieses Problem bekannt für andere Benutzer? Jede Lösung noch?
Eine Lösung besteht darin, nur die D2007-Quelldateien zu verwenden. Das ist keine Antwort, obwohl, da ich dies ausschließlich tun müssen, um aus D-XE.
Eine andere Lösung besteht darin, die XSD-Datei in eine .biz Erweiterung umbenennen. Aber das ist eine extrem hässliche Hack ...
Lösung
Dies ist in der Tat ein Fehler in Delphi XE. Es ist nun in dem Embarcadero Bug-Tracking-System als Eintrag 88.893
habe ich versucht, die ASX.XSD Datei unten in RAD Studio XE Import des XML-Datenbindung-Assistenten, und es funktioniert genau wie Sie beschreiben. Es importiert die XSD, als ob es XML war anstelle von 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>
Es wird mir dieses Gerät:
{*****************************************************************************************************}
{ }
{ 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.
Aber wenn die .BIZ-Erweiterung verwenden, erzeugt er die richtige Einheit:
{*****************************************************************************************************}
{ }
{ 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 dies bald