2017-02-09 15 views
0

私はFIX(Financial Information Exchange)メッセージフォーマットを持っています。 35=U1 49=GEMI1 8=FIX.4.1 9=732または8=FIX.4.1 9=751 35=U1 34=3 49=GEMI2 52=20160125-10:52:21、これをXML形式に変換しました。C#でXML形式のメッセージをSOAPエンベロープ形式に変換または表示するにはどうすればよいですか?

<messageTags> 
<tag key="9" value="751" /> 
<tag key="8" value="FIX.4.1" /> 
<tag key="35" value="U1" /> 
<tag key="34" value="3" /> 
<tag key="49" value="GEMI2" /> 
<tag key="52" value="20160125-10:52:21" /> 
</messageTags> 

私は以下のようなSOAP形式でXMLのこのタイプを変換したり、表示したいです。

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:eu="http://client.ws.emx.co.uk"> 
<soapenv:Header></soapenv:Header> 
<soapenv:Body> 
<eu:processXmlMessageRequest> 
<sequenceNumber>1</sequenceNumber> 
<creationTime>2016-05-28T09:36:22.165</creationTime> 
<messageTags> 
     <tag key="8" value="FIX.4.1" /> 
     <tag key="9" value="751" /> 
     <tag key="35" value="U1" /> 
     <tag key="34" value="3" /> 
     <tag key="49" value="GEMI2" /> 
     <tag key="52" value="20160125-10:52:21" /> 
</messageTags> 
<payloadType>XmlFixMessageTags</payloadType> 
</eu:processXmlMessageRequest> 
</soapenv:Body> 
</soapenv:Envelope> 

Visual Studio C#でこれを行う方法は誰でも助けてください。

+0

オムませんが、あなたは一番下にXMLに上からXMLをオンにしたい場合は...ちょうど不足しているテキストを追加(文字列リテラルまたはXmlWriterのいずれかとして)。 –

答えて

0

次試してください:あなたが求めている正確に何をしてください...

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Xml; 
using System.Xml.Linq; 

namespace ConsoleApplication1 
{ 
    class Program 
    { 
     const string FILENAME = @"c:\temp\test.xml"; 
     static void Main(string[] args) 
     { 
      XElement messageTags = XElement.Load(FILENAME); 

      string header = 
       "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:eu=\"http://client.ws.emx.co.uk\">" + 
        "<soapenv:Header></soapenv:Header>" + 
        "<soapenv:Body>" + 
         "<eu:processXmlMessageRequest>" + 
         "</eu:processXmlMessageRequest>" + 
        "</soapenv:Body>" + 
       "</soapenv:Envelope>"; 

      XElement envelope = XElement.Parse(header); 
      XElement request = envelope.Descendants().Where(x => x.Name.LocalName == "processXmlMessageRequest").FirstOrDefault(); 

      int sequenceNumber = 1; 
      DateTime now = DateTime.Now; 
      request.Add(new object[] { 
       new XElement("sequenceNumber", sequenceNumber), 
       new XElement("creationTime", now.ToString("yyyy-MM-ddT" + now.TimeOfDay.ToString())), //>2016-05-28T09:36:22.165</creationTime> 
       messageTags 
      }); 
     } 
    } 
} 
+0

私は空白の出力を得ています.SOAP形式の出力はどこに表示されますか? – Bikash

+0

xmlは封筒に入っています。次のように文字列を取得できます:str envelopeStr = envelope.ToString() – jdweng

関連する問題