我有一个以以下内容开头的XHTML文件:
<html xmlns="http://www.w3.org/1999/xhtml">
我加载它:
XmlDocument xml = new XmlDocument();
StringReader sr = new StringReader(html);
XmlTextReader xmltr = new XmlTextReader(sr);
xmltr.Namespaces = false;
xml.Load(xmltr);
当我调用 xml.InnerXml
时,总是会得到 The 'xmlns' attribute is bound to the reserved namespace 'http://www.w3.org/2000/xmlns/'.
的异常,无法访问我的 XmlDocument 的内部 xml。如何在加载过程中摆脱 xmlns?
解决方案是:
XmlNode xmln = xml.SelectSingleNode("//html");
if (xmln != null)
((XmlElement)xmln).RemoveAttribute("xmlns");