c# 处理带namespace 的 xml

XmlDocument doc = new XmlDocument();
doc.Load(localxml + "\" + Path.GetFileName(xinhuaxml));
System.Xml.XmlElement root = doc.DocumentElement;
string namespaces = root.NamespaceURI;
System.Xml.XmlNamespaceManager nsMgr = new System.Xml.XmlNamespaceManager(doc.NameTable);
nsMgr.AddNamespace("apxh", "http://www.w3.org/1999/xhtml");
nsMgr.AddNamespace("apcm", "http://ap.org/schemas/03/2005/apcm");
nsMgr.AddNamespace("ns", namespaces);
string creattime = root.SelectSingleNode(@"//ns:updated", nsMgr).InnerText;
string headlinetxt = root.SelectSingleNode(@"//apcm:SlugLine", nsMgr).InnerText;
string category = root.SelectSingleNode(@"//ns:category", nsMgr).InnerText;
XmlNode content = root.SelectSingleNode(@"//ns:content", nsMgr);

原文地址:https://www.cnblogs.com/ssjsk/p/6053952.html