【问题标题】:Creating concrete XML files with XML Data Binding Wizard in Delphi在 Delphi 中使用 XML 数据绑定向导创建具体的 XML 文件
【发布时间】:2020-08-10 13:10:39
【问题描述】:

我想在 Delphi 10.4 和 XML 数据绑定向导中使用编辑字段来创建具体数据。

我有 XML 模式,我用它在 Delphi 中创建了下面的代码。

你能帮我看看下面的代码如何创建具体的 XML 文件吗?

这是我从数据绑定向导中得到的:

function NewUnknown: IXMLGetBalance_Type;
begin
  Result := NewXMLDocument.GetDocBinding('Unknown', TXMLGetBalance_Type, TargetNamespace) as IXMLGetBalance_Type;
end;

{ TXMLGetBalance_Type }

procedure TXMLGetBalance_Type.AfterConstruction;
begin
  RegisterChildNode('consent', TXMLGetBalance_Type_consent);
  inherited;
end;

function TXMLGetBalance_Type.Get_Consent: IXMLGetBalance_Type_consent;
begin
  Result := ChildNodes['consent'] as IXMLGetBalance_Type_consent;
end;

{ TXMLGetBalance_Type_consent }

function TXMLGetBalance_Type_consent.Get_Type_: UnicodeString;
begin
  Result := ChildNodes['type'].Text;
end;

procedure TXMLGetBalance_Type_consent.Set_Type_(Value: UnicodeString);
begin
  ChildNodes['type'].NodeValue := Value;
end;

function TXMLGetBalance_Type_consent.Get_Target: UnicodeString;
begin
  Result := ChildNodes['target'].Text;
end;

procedure TXMLGetBalance_Type_consent.Set_Target(Value: UnicodeString);
begin
  ChildNodes['target'].NodeValue := Value;
end;

function TXMLGetBalance_Type_consent.Get_Id: UnicodeString;
begin
  Result := ChildNodes['id'].Text;
end;

procedure TXMLGetBalance_Type_consent.Set_Id(Value: UnicodeString);
begin
  ChildNodes['id'].NodeValue := Value;
end;

如何使用此代码创建包含来自编辑字段的数据的具体 XML 文件?

【问题讨论】:

  • 非常感谢!我现在明白了。我还有 1 个问题,我正在尝试连接到这样的 API,但它不起作用:request :=(HTTPRio1 as AccountInfo_PT).getBalance(Unk);因为 getBalance() 函数具有参数类型 getBalance ,它的定义在我导入的 WSDL 文件中,所以 getBalance() 函数需要 getBalance 类类型参数,它属于 getBalance_type 类,我如何从 Unk 创建这个 getBalance 参数,它是 IXMLGetBalance_Type ?

标签: xml delphi


【解决方案1】:

只需调用NewUnknown(),根据需要为返回的IXMLGetBalance_Type的属性赋值,然后保存到文件中。例如:

uses
  ..., UnitGeneratedByXMLWizard;

procedure TMyForm.DoSomething;
var
  Unk: IXMLGetBalance_Type;
begin
  Unk := NewUnknown;
  Unk.Consent.Type_ := ...;
  Unk.Consent.Target := ...;
  Unk.Consent.Id := ...;
  Unk.SaveToFile('path_to\myfile.xml');
end;

查看 Embarcadero 的文档了解更多详情:

Using Code That the XML Data Binding Wizard Generates

【讨论】:

  • 非常感谢!我现在明白了。
  • 我还有 1 个问题,我正在尝试连接到这样的 API,但它不起作用:request :=(HTTPRio1 as AccountInfo_PT).getBalance(Unk);因为 getBalance() 函数具有参数类型 getBalance ,它的定义在我导入的 WSDL 文件中,所以 getBalance() 函数需要 getBalance 类类型参数,它属于 getBalance_type 类,我如何从 Unk 创建这个 getBalance 参数,它是 IXMLGetBalance_Type跨度>
猜你喜欢
  • 1970-01-01
  • 2011-12-26
  • 2012-09-22
  • 1970-01-01
  • 1970-01-01
  • 2012-04-10
  • 1970-01-01
  • 1970-01-01
  • 2014-01-25
相关资源
最近更新 更多