c# 讀取xml CDATA過濾

方法一: 

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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章