【发布时间】:2018-07-15 15:02:22
【问题描述】:
我有一个外部 CML 文件,我已将其保存在 Asp.Net mvc 项目的 Xml 文件夹中我正在尝试使用字符串编写器替换我写在方括号 [] 中的 xml 文件的字符串>
string lStrXMLRequest = System.Web.HttpContext.Current.Server.MapPath("/Xml/SoapAvailabilitySearch.xml");
StreamReader str = new StreamReader(lStrXMLRequest);
string XMLText = str.ReadToEnd();
str.Close();
XMLText.Replace("[orgname]",org);
但是我看到 orgname 没有被 org 变量中发送的值替换。谁能告诉我如何将值从 c# 发送到 XML 文件。
这是我的 XML 文件:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<AvailabilitySearch xmlns="http://www.reservwire.com/namespace/WebServices/Xml">
<xiRequest>
<Authority>
<Org>[orgname]</Org>
</Authority>
</xiRequest>
</AvailabilitySearch>
</soap:Body>
</soap:Envelope>
任何帮助将不胜感激。
【问题讨论】:
-
这会将文件内容替换为新字符串
string xml = File.ReadAllText(lStrXMLRequest); File.WriteAllText(lStrXMLRequest, xml.Replace("[orgname]", org));
标签: c# xml asp.net-mvc asp.net-mvc-4