我尝试创建一个xml文档来访问xml服务。我在获得我想要的xml结果时遇到了麻烦。:-)这是我用来创建此文档的delphicode。
xmlQuery.Active := true;
xmlQuery.Version := '1.0';
xmlQuery.Encoding := 'UTF-8';
lEnvelope := xmlQuery.AddChild('soap:Envelope');
lEnvelope.Attributes['xmlns:soap'] := 'http://schemas.xmlsoap.org/soap/envelope/';
lHeader := lEnvelope.AddChild('soap:Header');
lBruker := lHeader.AddChild('brukersesjon:Brukersesjon');
lValue := lBruker.AddChild('distribusjonskanal');
lValue.Text := 'PTP';
lValue := lBruker.AddChild('systemnavn');
lValue.Text := 'infotorgEG';生成的xml如下所示。
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<brukersesjon:Brukersesjon>
<brukersesjon:distribusjonskanal>PTP</brukersesjon:distribusjonskanal>
<brukersesjon:systemnavn>infotorgEG</brukersesjon:systemnavn>
</brukersesjon:Brukersesjon>
</soap:Header>
</soap:Envelope>我想让它看起来像这样。
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<brukersesjon:Brukersesjon>
<distribusjonskanal>PTP</distribusjonskanal>
<systemnavn>infotorgEG</systemnavn>
</brukersesjon:Brukersesjon>
</soap:Header>
</soap:Envelope>我不知道我做错了什么。你们有人能帮我吗?你们当中有没有人知道有一个示例/教程可以创建一个完整的xml文件,包括头文件和正文文件?
发布于 2014-12-24 03:54:34
使用接受NameSpaceURI的第二个参数的重载IXMLNode.AddChild
xmlQuery.Active := true;
xmlQuery.Version := '1.0';
xmlQuery.Encoding := 'UTF-8';
lEnvelope := xmlQuery.AddChild('soap:Envelope');
lEnvelope.Attributes['xmlns:soap'] := 'http://schemas.xmlsoap.org/soap/envelope/';
lHeader := lEnvelope.AddChild('soap:Header');
lBruker := lHeader.AddChild('brukersesjon:Brukersesjon');
lValue := lBruker.AddChild('distribusjonskanal', ''); // <<<-- Here
lValue.Text := 'PTP';
lValue := lBruker.AddChild('systemnavn', ''); // <<<-- And here
lValue.Text := 'infotorgEG';这将生成您显示为所需输出的输出。
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header><brukersesjon:Brukersesjon>
<distribusjonskanal>PTP</distribusjonskanal>
<systemnavn>infotorgEG</systemnavn>
</brukersesjon:Brukersesjon>
</soap:Header>
</soap:Envelope>https://stackoverflow.com/questions/27626613
复制相似问题