c# - LINQ to XML: applying an XPath -
Can anyone tell me why this program does not calculate any items? Is it something to do with the RDF namespace?
Using the system; Using System.Xml.Linq; Using System.Xml.XPath; Class program {static zero main (string [] arg) {var doc = XDocument.Load ("http://seattle.craigslist.org/sof/index.rss"); Var item in foreach (doc.XPathSelectElements ("// item") {Console.WriteLine (item.Element ("link"). Value); } Console. Read (); }}
Yes, it is absolutely about namespace - although this RSS name location Is not RDF one you are trying to find objects without a namespace.
Using .NET's namespace in XPath is a bit tricky, but in this case, I only use LINQ to XML descendants
instead of the method:
Using the system; Using System.Linq; Using System.Xml.Linq; Class test {static zero major () {var doc = XDocument.Load ("http://seattle.craigslist.org/sof/index.rss"); X-namespace RSS = "http://purl.org/rss/1.0/"; Foreach (var item (RSS + "item") in doc.Descendants) {Console.WriteLine (item.Element (RSS + "link"). Value); } Console. Read (); }}
Comments
Post a Comment