将十六进制字符串解析为XDocument

时间:2015-05-21 05:05:12

标签: c# xml visual-studio hex

我的代码

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);

我调试并查看以下结果

文本展示台模式:

enter image description here

和XML可视化工具:

enter image description here

XDocument XTemp的结果字符串如图2所示

如何让XTemp拥有如图1中的结果字符串?

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);

输出

enter image description here