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

 

posted @ 2016-11-11 13:38  旗木卡卡赵赵  阅读(607)  评论(0编辑  收藏  举报