我的代码
string workflowIdRef="WorkflowUser_NEW Bình Thuận Copy"
string requestFileXml = HttpContext.Current.Server.MapPath("~/Admin/TS/requestXml/JobCreateReq.xml");
XmlDocument xmld = new XmlDocument();
xmld.Load(requestFileXml);
string requestXml = xmld.OuterXml;
requestXml = requestXml.Replace("WORKFLOW_ID", workflowIdRef);
//Parse string requestXml to xDocument Temp
XDocument xTemp = XDocument.Parse(requestXml);
我调试并查看以下结果
文本展示台模式:
和XML可视化工具:
XDocument
XTemp
的结果字符串如图2所示
如何让XTemp
拥有如图1中的结果字符串?
答案 0 :(得分:1)
&
是XML中的特殊字符,它是开始编码字符ì
的标记。如果您希望将其作为纯字符串而不是编码字符,那么您需要使用&
转义&
,例如ì
。
演示:
//notice that & are escaped to & in the following string :
string workflowIdRef="WorkflowUser_NEW Bình Thuận Copy"
string workflowIdRef = "WorkflowUser_NEW Bình Thuận Copy";
string xmlContent = @"<root workflowIdRef=""WORKFLOW_ID""/>";
xmlContent.Replace("WORKFLOW_ID", workflowIdRef);.Replace("WORKFLOW_ID", workflowIdRef);
XDocument xTemp = XDocument.Parse(xmlContent);
输出