繁体   English   中英

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

[英]Parse the hexadecimal string to XDocument

我的密码

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所示的结果字符串?

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

输出:

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM