uses
ActiveX,
Xml.XMLIntf,
Xml.XMLDoc;
...
procedure TForm1.Button1Click(Sender: TObject);
var
Document: IXMLDocument;
Envelope: IXMLNode;
Body: IXMLNode;
HeaderItem: IXMLNode;
DataNode: IXMLNode;
MessageState: IXMLNode;
sl: TStringList;
begin
CoInitialize(
nil);
Document := NewXMLDocument;
Document.Encoding := '
utf-8';
Document.Options := [doNodeAutoIndent];
Envelope := Document.AddChild('
soap:Envelope');
Envelope.Attributes['
xmlns:xsi'] := '
http://www.w3.org/2001/XMLSchema-instance';
Envelope.Attributes['
xmlns:xsd'] := '
http://www.w3.org/2001/XMLSchema';
Envelope.Attributes['
xmlns:soap'] := '
http://schemas.xmlsoap.org/soap/envelope/';
Body := Envelope.AddChild('
soap:Header');
HeaderItem := Body.AddChild('
HeaderItem');
HeaderItem.Attributes['
xmlns'] := '
http://tempuri.org/';
DataNode := HeaderItem.AddChild('
User');
DataNode.NodeValue := '
Username';
DataNode := HeaderItem.AddChild('
Code');
DataNode := HeaderItem.AddChild('
Message');
DataNode := HeaderItem.AddChild('
Gender');
Body := Envelope.AddChild('
soap:Body');
MessageState := Body.AddChild('
MessageState');
MessageState.Attributes['
xmlns'] := '
http://tempuri.org/';
DataNode := MessageState.AddChild('
NewState');
DataNode.NodeValue := '
123456789';
Memo1.Lines.Append(Document.Xml.Text);
Memo1.Lines.Append('
####################################################');
Document.Xml.Clear;
sl := TStringList.Create;
try
sl.Add('
<?xml version="1.0"?>');
sl.Add('
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">');
sl.Add('
<soap:Header>');
sl.Add('
<HeaderItem xmlns="http://tempuri.org/">');
sl.Add('
<User>Username</User>');
sl.Add('
<Code></Code/>');
sl.Add('
<Message></Message>');
sl.Add('
<Gender></Gender>');
sl.Add('
</HeaderItem>');
sl.Add('
</soap:Header>');
sl.Add('
<soap:Body>');
sl.Add('
<MessageState xmlns="http://tempuri.org/">');
sl.Add('
<NewState>123456789</NewState>');
sl.Add('
</MessageState>');
sl.Add('
</soap:Body>');
sl.Add('
</soap:Envelope>');
Document.Xml.AddStrings(sl);
finally
sl.Free;
end;
Memo1.Lines.Append(Document.Xml.Text);
CoUninitialize;
end;