Guest User

Untitled

a guest
Jan 17th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. List<PriceDetail> prices =
  2. (from item in xmlDoc.Descendants(shop.DescendantXName)
  3. select new PriceDetail
  4. {
  5. Price = GetPrice(item.Element(shop.PriceXPath).Value),
  6. GameVersion = GetGameVersion(((IEnumerable)item.XPathEvaluate(shop.TitleXPath)).Cast<XAttribute>().First<XAttribute>().Value, item.Element(shop.PlatformXPath).Value),
  7. Shop = shop,
  8. Link = item.Element(shop.LinkXPath).Value,
  9. InStock = InStock(item.Element(shop.InStockXPath).Value)
  10. }).ToList<PriceDetail>();
  11.  
  12. ((IEnumerable)item.XPathEvaluate(shop.TitleXPath)).Cast<XAttribute>().First<XAttribute>().Value
  13.  
  14. someXPathExpression
  15.  
  16. string(someXPathExpression)
  17.  
  18. string result = item.XPathEvaluate(shop.TitleXPath) as string;
  19.  
  20. using System;
  21. using System.IO;
  22. using System.Xml.Linq;
  23. using System.Xml.XPath;
  24.  
  25. class TestXPath
  26. {
  27. static void Main(string[] args)
  28. {
  29.  
  30. string xml1 =
  31. @"<t>
  32. <a b='attribute value'/>
  33. <c>
  34. <b>element value</b>
  35. </c>
  36. <e b='attribute value'/>
  37. </t>";
  38.  
  39. string xml2 =
  40. @"<t>
  41. <c>
  42. <b>element value</b>
  43. </c>
  44. <e b='attribute value'/>
  45. </t>";
  46.  
  47. TextReader sr = new StringReader(xml1);
  48. XDocument xdoc = XDocument.Load(sr, LoadOptions.None);
  49.  
  50. string result1 = xdoc.XPathEvaluate("string(/*/*/@b | /*/*/b)") as string;
  51.  
  52. TextReader sr2 = new StringReader(xml2);
  53. XDocument xdoc2 = XDocument.Load(sr2, LoadOptions.None);
  54.  
  55. string result2 = xdoc2.XPathEvaluate("string(/*/*/@b | /*/*/b)") as string;
  56.  
  57. Console.WriteLine(result1);
  58. Console.WriteLine(result2);
  59.  
  60.  
  61. }
  62. }
  63.  
  64. attribute value
  65. element value
  66.  
  67. XElement e = item as XElement;
  68. XAttribute a = item as XAttribute;
  69.  
  70. if(e != null)
  71. //item is of type XElement
  72. else
  73. //item is of type XAttribute
Add Comment
Please, Sign In to add comment