code_junkie

WPF - Searching an XML doc for values using XMLTextReader

Nov 12th, 2011
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. GetWeatherFeed("97229", "//weather//loc//dnam", "//weather//cc//tmp", "/weather/cc/icon");
  2.  
  3. System.Xml.XmlTextReader xtr = new System.Xml.XmlTextReader(Url that retuns xm);
  4. System.Collections.Hashtable ht = new System.Collections.Hashtable();
  5.  
  6. ht = FindTagsUsingXPthNaviatorAndXPathDocumentNew(xtr, location, temperature, iconid);
  7. lblLocation.Content = ht["Location"].ToString();
  8. lblWeatherCondition.Content = ht["Weather"].ToString();
  9.  
  10.  
  11. public System.Collections.Hashtable FindTagsUsingXPthNaviatorAndXPathDocumentNew(System.Xml.XmlTextReader xtr, string nodeToLocate1, string nodeToLocate2, string nodeToLocate3)
  12. {
  13. System.Xml.XPath.XPathDocument xpDoc = new System.Xml.XPath.XPathDocument(xtr);
  14. System.Xml.XPath.XPathNavigator xpNav = xpDoc.CreateNavigator();
  15. System.Xml.XPath.XPathExpression xpExpression = xpNav.Compile(nodeToLocate1);
  16.  
  17. System.Xml.XPath.XPathNodeIterator xpIter = xpNav.Select(xpExpression);
  18. System.Collections.Hashtable ht = new System.Collections.Hashtable();
  19.  
  20. while (xpIter.MoveNext())
  21. {
  22. ht.Add("Location", xpIter.Current.Value);
  23. }
  24.  
  25. xpExpression = xpNav.Compile(nodeToLocate2);
  26.  
  27. xpIter = xpNav.Select(xpExpression);
  28. while (xpIter.MoveNext())
  29. {
  30. ht.Add("Weather", xpIter.Current.Value);
  31. }
  32.  
  33. xpExpression = xpNav.Compile(nodeToLocate3);
  34.  
  35. xpIter = xpNav.Select(xpExpression);
  36. while (xpIter.MoveNext())
  37. {
  38. ht.Add("Icon", xpIter.Current.Value);
  39. }
  40.  
  41. return ht;
  42. }
  43.  
  44. System.Xml.XmlTextReader xtr = new System.Xml.XmlTextReader(my xml url);
  45. System.Xml.XPath.XPathDocument xdoc = new System.Xml.XPath.XPathDocument(xtr);
  46.  
  47. lblLocation.Content = getXmlNodeValue(xdoc, location);
  48. lblWeatherCondition.Content = getXmlNodeValue(xdoc, temperature);
Add Comment
Please, Sign In to add comment