c# 讀取xml CDATA過濾
阿新 • • 發佈:2018-11-10
方法一:
string NewString=Regex.Replace("<![CDATA[你好]]>","[^\u4e00-\u9fa5]","");
方法二:
一個簡單的xml,如下所示:
<?xml version="1.0" encoding="GBK"?>
<Document>
<ChiefComplaint>
<![CDATA[右眼視力進行性下降2年餘]]>
</ChiefComplaint>
</Document>
讀取
private int ReadXml() { string responseInfo = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + @"<Document> <ChiefComplaint> <![CDATA[右眼視力進行性下降2年餘]]> </ChiefComplaint> </Document>"; XmlDocument doc = new XmlDocument(); doc.LoadXml(responseInfo); string xpathChiefComplaint = "/Document/ChiefComplaint"; XmlNode xnChiefComplaint = doc.SelectSingleNode(xpathChiefComplaint); string nodeValue = xnChiefComplaint.InnerText; }