我已经有这个问题很长一段时间了,我不能自己解决它。我也试过搜索谷歌,必应和stackOverflow吗?没有运气..。
我正在尝试使用Delphi2006的TXMLDocument组件手动构造soap标头:
... ... ... ... ... ... 我正在做的是构造一个新的元素,叫做'soap:Envelope‘。在这个新元素中,我创建了三个属性:'xmlns:soap','xmlns:xsd‘和'xmlns:xsi’。
当我试图在这三个属性中的任何一个中写一个值时,我会得到下面的错误:
尝试修改只读节点。
有人知道如何使用TXMLDocument完成这项任务吗?
/Brian
发布于 2011-01-12 22:14:30
下面的代码在这里运行良好:
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,它只是接口的一个组件包装器。
发布于 2011-01-12 23:05:12
这是我的解决方案,它使用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;基于How to set the prefix of a document element in Delphi中提供的代码
https://stackoverflow.com/questions/4667081
复制相似问题