我有XHTML文件,該文件開頭:的XmlDocument忽略的xmlns
<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/'.
異常,無法訪問的內部XML我XmlDocument的。如何在加載過程中擺脫xmlns?
的解決方案是:
XmlNode xmln = xml.SelectSingleNode("//html");
if (xmln != null)
((XmlElement)xmln).RemoveAttribute("xmlns");
您的XHTML聲明會討論'http:// www.w3.org/1999/xhtml',但您描述的錯誤是關於'http:// www.w3.org/2000/xmlns'的討論 - 您是肯定他們都是正確的? – 2012-01-27 11:24:04
是的,我的第三方XHTML有1999年,異常說2000年。 – Denis 2012-01-27 11:34:58
更重要的是「xhtml」和「xmlns」位... – 2012-01-27 11:36:25