XML数据绑定向导和使用多个名称空间
我正在尝试使用Delphi西雅图中的XML数据绑定向导为给定的一组XSD文件生成接口。我知道在XML向导中使用多个名称空间存在问题,但我无法让自己理解确切的问题/解决方案 在向您提供大量详细信息之前,简单地说,我的问题是:如何修改生成的代码,使其能够像在XSD定义中一样解释结果XML中不同的名称空间前缀 生成代码的XSD如下所示XML数据绑定向导和使用多个名称空间,xml,delphi,xsd,xml-parsing,Xml,Delphi,Xsd,Xml Parsing,我正在尝试使用Delphi西雅图中的XML数据绑定向导为给定的一组XSD文件生成接口。我知道在XML向导中使用多个名称空间存在问题,但我无法让自己理解确切的问题/解决方案 在向您提供大量详细信息之前,简单地说,我的问题是:如何修改生成的代码,使其能够像在XSD定义中一样解释结果XML中不同的名称空间前缀 生成代码的XSD如下所示 <?xml version="1.0" encoding="UTF-8"?> <schema targetNamespace="application
<?xml version="1.0" encoding="UTF-8"?>
<schema targetNamespace="application/registration/2014/04" elementFormDefault="qualified"
xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:rmrds="datamodel/canonical/datastructures/2014/01/">
<import schemaLocation="CanonicalDataModel/CanonicalDataModel_DataStructures.xsd" namespace="datamodel/canonical/datastructures/2014/01/">
</import>
<element name="ApplicationInstanceRegistrationResponse">
<complexType>
<sequence>
<element name="registrationResponse" type="rmrds:AppInstanceRegistrationType" />
</sequence>
</complexType>
</element>
</schema>
REST服务为我提供了以下答案XML:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns10:ApplicationInstanceRegistrationResponse
xmlns="datamodel/financial/modelobjects/2014/01/"
xmlns:ns3="canonical/basetypes/2014/01/"
xmlns:ns5="datamodel/canonical/datastructures/2014/01/"
xmlns:ns6="datamodel/canonical/simpletypes/2014/01/"
xmlns:ns10="application/registration/2014/04"
<ns10:registrationResponse>
<ns5:key>cac7bacc</ns5:key>
<ns5:secret>NzY2MDkwNzliNjJkZTE1MWRjNGViNTI4MTk4MmZjZDkzYzhmY2UwNDA5YmJhMjlhYzVlY2JjZGFmNWE1NDg2OA==</ns5:secret>
</ns10:registrationResponse>
</ns10:ApplicationInstanceRegistrationResponse>
type
IXMLApplicationInstanceRegistrationResponse = interface;
IXMLAppInstanceRegistrationType_rmrds = interface;
IXMLApplicationInstanceRegistrationResponse = interface(IXMLNode)
['{045B5E7C-83E2-4DB3-B7CD-7C2C28E0E387}']
{ Property Accessors }
function Get_RegistrationResponse: IXMLAppInstanceRegistrationType_rmrds;
{ Methods & Properties }
property RegistrationResponse: IXMLAppInstanceRegistrationType_rmrds read Get_RegistrationResponse;
end;
IXMLAppInstanceRegistrationType_rmrds = interface(IXMLNode)
['{2C1869A9-8B9E-4EC1-9320-5F6683BCB20E}']
{ Property Accessors }
function Get_Key: String;
function Get_Secret: String;
procedure Set_Key(Value: String);
procedure Set_Secret(Value: String);
{ Methods & Properties }
property Key: String read Get_Key write Set_Key;
property Secret: String read Get_Secret write Set_Secret;
end;
TXMLApplicationInstanceRegistrationResponse = class;
TXMLAppInstanceRegistrationType_rmrds = class;
TXMLApplicationInstanceRegistrationResponse = class(TXMLNode, IXMLApplicationInstanceRegistrationResponse)
protected
{ IXMLApplicationInstanceRegistrationResponse }
function Get_RegistrationResponse: IXMLAppInstanceRegistrationType_rmrds;
public
procedure AfterConstruction; override;
end;
{ TXMLAppInstanceRegistrationType_rmrds }
TXMLAppInstanceRegistrationType_rmrds = class(TXMLNode, IXMLAppInstanceRegistrationType_rmrds)
protected
{ IXMLAppInstanceRegistrationType_rmrds }
function Get_Key: String;
function Get_Secret: String;
procedure Set_Key(Value: String);
procedure Set_Secret(Value: String);
end;
{ Global Functions }
function GetApplicationInstanceRegistrationResponse(Doc: IXMLDocument): IXMLApplicationInstanceRegistrationResponse;
function LoadApplicationInstanceRegistrationResponse(const FileName: string): IXMLApplicationInstanceRegistrationResponse;
function NewApplicationInstanceRegistrationResponse: IXMLApplicationInstanceRegistrationResponse;
const
TargetNamespace = 'application/registration/2014/04';
implementation
{ Global Functions }
function GetApplicationInstanceRegistrationResponse(Doc: IXMLDocument): IXMLApplicationInstanceRegistrationResponse;
begin
Result := Doc.GetDocBinding('ApplicationInstanceRegistrationResponse', TXMLApplicationInstanceRegistrationResponse, TargetNamespace) as IXMLApplicationInstanceRegistrationResponse;
end;
function LoadApplicationInstanceRegistrationResponse(const FileName: string): IXMLApplicationInstanceRegistrationResponse;
begin
Result := LoadXMLDocument(FileName).GetDocBinding('ApplicationInstanceRegistrationResponse', TXMLApplicationInstanceRegistrationResponse, TargetNamespace) as IXMLApplicationInstanceRegistrationResponse;
end;
function NewApplicationInstanceRegistrationResponse: IXMLApplicationInstanceRegistrationResponse;
begin
Result := NewXMLDocument.GetDocBinding('ApplicationInstanceRegistrationResponse', TXMLApplicationInstanceRegistrationResponse, TargetNamespace) as IXMLApplicationInstanceRegistrationResponse;
end;
{ TXMLApplicationInstanceRegistrationResponse }
procedure TXMLApplicationInstanceRegistrationResponse.AfterConstruction;
begin
RegisterChildNode('registrationResponse', TXMLAppInstanceRegistrationType_rmrds);
inherited;
end;
function TXMLApplicationInstanceRegistrationResponse.Get_RegistrationResponse: IXMLAppInstanceRegistrationType_rmrds;
begin
Result := ChildNodes['registrationResponse'] as IXMLAppInstanceRegistrationType_rmrds;
end;
{ TXMLAppInstanceRegistrationType_rmrds }
function TXMLAppInstanceRegistrationType_rmrds.Get_Key: String;
begin
Result := ChildNodes['key'].NodeValue;
end;
procedure TXMLAppInstanceRegistrationType_rmrds.Set_Key(Value: String);
begin
ChildNodes['key'].NodeValue := Value;
end;
function TXMLAppInstanceRegistrationType_rmrds.Get_Secret: String;
begin
Result := ChildNodes['secret'].NodeValue;
end;
procedure TXMLAppInstanceRegistrationType_rmrds.Set_Secret(Value: String);
begin
ChildNodes['secret'].NodeValue := Value;
end;
end.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns10:ApplicationInstanceRegistrationResponse
xmlns="datamodel/financial/modelobjects/2014/01/"
xmlns:ns3="canonical/basetypes/2014/01/"
xmlns:ns5="datamodel/canonical/datastructures/2014/01/"
xmlns:ns6="datamodel/canonical/simpletypes/2014/01/"
xmlns:ns10="application/registration/2014/04"
<ns10:registrationResponse>
<ns5:key>cac7bacc</ns5:key>
<ns5:secret>NzY2MDkwNzliNjJkZTE1MWRjNGViNTI4MTk4MmZjZDkzYzhmY2UwNDA5YmJhMjlhYzVlY2JjZGFmNWE1NDg2OA==</ns5:secret>
</ns10:registrationResponse>
</ns10:ApplicationInstanceRegistrationResponse>