2017-10-23 1 views
-3

Wie diese Seife Anfrage an Parse ihre Werte in Datensatz erhaltenwie diese Seife Anfrage zu analysieren und nehmen ihre Werte in Modal

<?xml version="1.0" encoding="utf-8"?> 
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soapenv:Body> 
     <ns3:initiateTransactionResponseType xmlns:ns2="http://dto.common.pg.systems.com/" xmlns:ns3="http://dto.transaction.partner.pg.systems.com/"><ns2:responseCode>0000</ns2:responseCode> 
      <orderId>test006</orderId> 
      <storeId>386</storeId> 
      <paymentToken>6588</paymentToken> 
      <transactionDateTime>2017-10-23T15:24:11.503+05:00</transactionDateTime> 
      <paymentTokenExiryDateTime>2017-10-27T15:24:11.503+05:00</paymentTokenExiryDateTime> 
     </ns3:initiateTransactionResponseType> 
    </soapenv:Body> 
</soapenv:Envelope> 

Antwort

0

xml Linq Mit

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

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

      XDocument doc = XDocument.Load(FILENAME); 
      XElement root = doc.Root; 
      XNamespace ns = root.GetDefaultNamespace(); 

      DataTable dt = new DataTable(); 
      dt.Columns.Add("OrderID", typeof(string)); 
      dt.Columns.Add("storeID", typeof(int)); 
      dt.Columns.Add("paymentToken", typeof(int)); 
      dt.Columns.Add("transactionDateTime", typeof(DateTime)); 
      dt.Columns.Add("paymentTokenExiryDateTime", typeof(DateTime)); 

      dt.Rows.Add(new object[] { 
       (string)root.Descendants(ns + "orderId").FirstOrDefault(), 
       (int)root.Descendants(ns + "storeId").FirstOrDefault(), 
       (int)root.Descendants(ns + "paymentToken").FirstOrDefault(), 
       (DateTime)root.Descendants(ns + "transactionDateTime").FirstOrDefault(), 
       (DateTime)root.Descendants(ns + "paymentTokenExiryDateTime").FirstOrDefault() 
      }); 


     } 
    } 
}