xml - 在 Delphi 中使用 XML 数据绑定向导创建具体的 XML 文件
问题描述
我想在 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 文件?
解决方案
只需调用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 的文档了解更多详细信息:
推荐阅读
- javascript - 在 react.js 中单击时如何读取按钮中的值字段
- javascript - 当元素的大小减小并应用过渡时,滚动条推到顶部
- java - 使用文件和 json 正文提出请求
- hbase - HBase 2.0.0:区域链中的过渡洞中的区域
- php - Postgresql SQLSTATE[22021]: Character not in repertoire: Ö
- python - django分页过滤器-根据一行但出现错误
- linux - Move and copy text file in bash script
- c# - Progress bar does not update on separate form from VSTO addin
- android - App crashes with 'Unfortunately Age Calculator pro has stopped working' but there are no errors while compiling
- rest - NoTypeConversionAvailableException:骆驼休息 dsl