2

Web サービスにアクセスするための xml ドキュメントを作成しようとしています。私が望むように結果のxml beeingを取得するのに問題があります。:-) これは、このドキュメントを作成するための私のデルフィ コードです。

  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 ファイルを作成するサンプル/チュートリアルを知っている人はいますか?

4

1 に答える 1

1

IXMLNode.AddChildの 2 番目のパラメーターを取るオーバーロードを使用しNameSpaceURIます。

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>
于 2014-12-23T19:54:34.227 に答える