parsing XML with ampersand

后端 未结 9 1392
孤城傲影
孤城傲影 2020-11-30 12:21

I have a string which contains XML, I just want to parse it into Xelement, but it has an ampersand. I still have a problem parseing it with HtmlDecode. Any suggestions?

9条回答
  •  旧巷少年郎
    2020-11-30 12:47

    Filip's answer is on the right track, but you can hijack the System.Xml.XmlDocument class to do this for you without an entire new utility function.

    XmlDocument doc = new XmlDocument();
    string xmlEscapedString = (doc.CreateTextNode("Unescaped '&' containing string that would have broken your xml")).OuterXml;
    

提交回复
热议问题