2013-08-25 3 views
0

Мне нужно создать запрос с XMLDocument, который имеет определенные значения, и я не могу это сделать. Мой xml должен выглядеть так;Создание запроса как XML в Asp.Net

<?xml version="1.0" encoding="ISO-8859-9" ?> 
<ePaymentMsg VersionInfo="2.0" TT="Request" RM="Direct" CT="Money"> 
    <Operation ActionType="Sale"> 
    <OpData> 
     <MerchantInfo MerchantId="006100" MerchantPassword="123" /> 
     <ActionInfo> 
     <TrnxCommon TrnxID=""> 
      <AmountInfo Amount="1.00" Currency="949" /> 
     </TrnxCommon> 
     <PaymentTypeInfo> 
      <InstallmentInfo NumberOfInstallments="0"/> 
     </PaymentTypeInfo> 
     </ActionInfo> 
     <PANInfo PAN="402275******5574" ExpiryDate="201406" CVV2="***" BrandID="MASTER" /> 
     <OrgTrnxInfo /> 
     <CardHolderIP>127.0.0.1</CardHolderIP> 
    </OpData> 
    </Operation> 
</ePaymentMsg> 

Может кто-нибудь помочь мне, как создать этот XML с помощью C# XmlDocument, XmlNode

Я попробовал это,

XmlNode node = null; 
      XmlDocument _msgTemplate = new XmlDocument(); 
      _msgTemplate.LoadXml("<?xml version=\"1.0\" encoding=\"UTF-8\" ?><ePaymentMsg VersionInfo=\"2.0\" TT=\"Request\" RM=\"Direct\" CT=\"Money\">" + 
       "<Operation ActionType=\"Sale\"><OpData><MerchantInfo MerchantId=\"\" MerchantPassword=\"\" />" + 
       "<ActionInfo><TrnxCommon TrnxID=\"\" Protocol=\"156\"><AmountInfo Amount=\"0\" Currency=\"792\" /></TrnxCommon><PaymentTypeInfo>" + 
       "<InstallmentInfo NumberOfInstallments=\"0\" /></PaymentTypeInfo></ActionInfo><PANInfo PAN=\"\" ExpiryDate=\"\" CVV2=\"\" BrandID=\"\" />" + 
       "<OrderInfo><OrderLine>0</OrderLine></OrderInfo><OrgTrnxInfo /><CustomData></CustomData><CardHolderIp></CardHolderIp></OpData></Operation></ePaymentMsg>"); 
      node = _msgTemplate.SelectSingleNode("//ePaymentMsg/Operation/OpData/MerchantInfo"); 
      node.Attributes["MerchantId"].Value = "006100"; 
      node.Attributes["MerchantPassword"].Value = "123"; 
      node = _msgTemplate.SelectSingleNode("//ePaymentMsg/Operation/OpData/ActionInfo/TrnxCommon"); 
      node.Attributes["TrnxID"].Value = Guid.NewGuid().ToString(); 
      node = _msgTemplate.SelectSingleNode("//ePaymentMsg/Operation/OpData/ActionInfo/TrnxCommon/AmountInfo"); 
      string gonderilecekAmount = amount.ToString("####.00"); 
      gonderilecekAmount = gonderilecekAmount.Replace(",", "."); 
      node.Attributes["Amount"].Value = gonderilecekAmount; 
      node.Attributes["Currency"].Value = "949"; 
      node = _msgTemplate.SelectSingleNode("//ePaymentMsg/Operation/OpData/ActionInfo/PaymentTypeInfo/InstallmentInfo"); 
      node.Attributes["NumberOfInstallments"].Value = "0"; 
      node = _msgTemplate.SelectSingleNode("//ePaymentMsg/Operation/OpData/PANInfo"); 
      node.Attributes["PAN"].Value = "402275******5574"; 
      node.Attributes["ExpiryDate"].Value = "201406"; 
      node.Attributes["CVV2"].Value = "***"; 
      node.Attributes["BrandID"].Value = "VISA"; 
      node = _msgTemplate.SelectSingleNode("//ePaymentMsg/Operation/OpData/CardHolderIp"); 
      node.Attributes["CardHolderIp"].Value = "10.20.30.40"; 
      request = _msgTemplate.OuterXml; 
      return request; 

Я думаю, что что-то неправильно на CardHolderIp узле. Любая помощь будет полезна.

+0

И код, который вы попробовали это где? –

+0

Sory, я добавил код, который я пробовал. – Huseyinc

ответ

0

В строке

node.Attributes["CardHolderIp"].Value = "10.20.30.40"; 

, я изменил его на

node.InnerText= "10.20.30.40"; 
Смежные вопросы