0

我需要使用具有一些特定值的 XMLDocument 创建一个请求,但我无法做到。我的 xml 应该是这样的;

<?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>

谁能帮助我如何使用 C# XmlDocument, XmlNode 创建这个 xml

我试过这个,

 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 节点有问题。任何帮助都会很有用。

4

1 回答 1

0

在里面

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

线,我把它改成

 node.InnerText= "10.20.30.40";
于 2013-08-26T07:50:00.490 回答