如何使用 TXMLDocument 手动构造 Soap Envelope (Delphi 2006)

发布于 2024-10-11 17:55:35 字数 379 浏览 4 评论 0原文

我已经被这个问题困扰很长时间了,但我自己无法解决。我也尝试过搜索 Google、Bing 和 stackOverflow?不走运...

我正在尝试使用 Delphi 2006 的 TXMLDocument 组件手动构造一个肥皂头:

... ... ... ... ... ...

我正在做的是构建一个名为“soap:Envelope”的新元素。在这个新元素中,我创建了三个属性:“xmlns:soap”、“xmlns:xsd”和“xmlns:xsi”。

当我尝试在三个属性中的任何一个中写入值时,我收到以下错误:

尝试修改只读节点。

有谁知道如何使用 TXMLDocument 完成这项任务?

/布莱恩

I've been having this problem for a long time now and I cannot solve it my self. I've tried searching Google, Bing and stackOverflow too? No luck...

I'm trying to construct a soap header manually using the TXMLDocument component of Delphi 2006:

...
...
...

...
...
...

What I'm doing is that I'm constructing a new Element called 'soap:Envelope'. In this new element I'm creating three attribtues called: 'xmlns:soap', 'xmlns:xsd' and 'xmlns:xsi'.

When I'm trying to write a value in any of the three attributes then I'm getting the error below:

Attempt to modify a read-only node.

Does any one know how to do this task using the TXMLDocument?

/Brian

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

沩ん囻菔务 2024-10-18 17:55:35

以下代码在这里工作正常:

procedure WriteSoapFile;
var
  Document: IXMLDocument;
  Envelope: IXMLNode;
  Body: IXMLNode;
begin
  Document := NewXMLDocument;
  Envelope := Document.AddChild('soap:Envelope');
  Envelope.Attributes['xmlns:soap'] := 'schemas.xmlsoap.org/soap/envelope/';
  Envelope.Attributes['xmlns:xsd']  := 'w3.org/2001/XMLSchema';
  Envelope.Attributes['xmlns:xsi']  := 'w3.org/2001/XMLSchema-instance';
  Body := Envelope.AddChild('soap:Body');
  Document.SaveToFile('Test.xml');
end;

您应该能够使用 TXMLDocument 而不是 IXMLDocument,它只是接口周围的组件包装器。

The following code works fine here:

procedure WriteSoapFile;
var
  Document: IXMLDocument;
  Envelope: IXMLNode;
  Body: IXMLNode;
begin
  Document := NewXMLDocument;
  Envelope := Document.AddChild('soap:Envelope');
  Envelope.Attributes['xmlns:soap'] := 'schemas.xmlsoap.org/soap/envelope/';
  Envelope.Attributes['xmlns:xsd']  := 'w3.org/2001/XMLSchema';
  Envelope.Attributes['xmlns:xsi']  := 'w3.org/2001/XMLSchema-instance';
  Body := Envelope.AddChild('soap:Body');
  Document.SaveToFile('Test.xml');
end;

You should be able to use TXMLDocument instead of IXMLDocument, it is just a component wrapper around the interface.

旧梦荧光笔 2024-10-18 17:55:35

这是我的解决方案,它使用 DeclareNamespace 来声明命名空间:

procedure WriteSoapFile;
const
  NS_SOAP = 'schemas.xmlsoap.org/soap/envelope/';
var
  Document: IXMLDocument;
  Envelope: IXMLNode;
  Body: IXMLNode;
begin
  Document := NewXMLDocument;
  Envelope := Document.CreateElement('soap:Envelope', NS_SOAP);
  Envelope.DeclareNamespace('soap', NS_SOAP);
  Envelope.DeclareNamespace('xsd', 'w3.org/2001/XMLSchema');
  Envelope.DeclareNamespace('xsi', 'w3.org/2001/XMLSchema-instance');
  Body := Envelope.AddChild('Body');
  Document.DocumentElement := Envelope;
  Document.SaveToFile('Test.xml');
end;

基于 如何在Delphi中设置文档元素的前缀

Here is my solution, it uses DeclareNamespace to declare namespaces:

procedure WriteSoapFile;
const
  NS_SOAP = 'schemas.xmlsoap.org/soap/envelope/';
var
  Document: IXMLDocument;
  Envelope: IXMLNode;
  Body: IXMLNode;
begin
  Document := NewXMLDocument;
  Envelope := Document.CreateElement('soap:Envelope', NS_SOAP);
  Envelope.DeclareNamespace('soap', NS_SOAP);
  Envelope.DeclareNamespace('xsd', 'w3.org/2001/XMLSchema');
  Envelope.DeclareNamespace('xsi', 'w3.org/2001/XMLSchema-instance');
  Body := Envelope.AddChild('Body');
  Document.DocumentElement := Envelope;
  Document.SaveToFile('Test.xml');
end;

Based on the code provided in How to set the prefix of a document element in Delphi

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文