摘要: 蝈蝈俊给出的解决办法,是基于XmlNamespaceManager 的。实际上,我本人更喜欢直接在Xpath里搞定:
以蝈蝈文中的Sample为例:
string ww = @"<item rdf:about=""http://ncsp.forum.nokia.com/download/?asset_id=10357"" xmlns:rdf=""http://www.w3.org/1999/02/22-rdf-syntax-ns#"" xmlns: dc=""http://purl.org/dc/elements/1.1/"" xmlns:ncsp=""http://ncsp.forum.nokia.com/""> <title>Advanced Audio Support v1.0</title><link>http://ncsp.forum.nokia.com/download/?asset_id=10357</link> <description>Media Server Audio Streaming plug-in installation file for Nokia 9200 Series Communicators. Deprecated - use the official audio stream plug-in instead, available from SDK v1.2 and later.</description> <dc:title xmlns: dc=""http://purl.org/dc/elements/1.1/"">Advanced Audio Support v1.0</dc:title> <dc:identifier xmlns: dc=""http://purl.org/dc/elements/1.1/"">10357</dc:identifier> <dc:language xmlns: dc=""http://purl.org/dc/elements/1.1/"">English</dc:language> <ncsp:filesize xmlns:ncsp=""http://ncsp.forum.nokia.com/"">7 kB</ncsp:filesize> <ncsp:class xmlns:ncsp=""http://ncsp.forum.nokia.com/"">Toolkit</ncsp:class></item>";XmlReader read = new XmlTextReader(new StringReader(ww));XPathDocument doc = new XPathDocument(read);XPathNavigator nav = doc.CreateNavigator();string strXPath = "/item/*[local-name(.) = 'identifier' and namespace-uri(.) = 'http://purl.org/dc/elements/1.1/']";
XPathExpression expr = nav.Compile(strXPath);.......
...[
阅读全文]