Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- List<PriceDetail> prices =
- (from item in xmlDoc.Descendants(shop.DescendantXName)
- select new PriceDetail
- {
- Price = GetPrice(item.Element(shop.PriceXPath).Value),
- GameVersion = GetGameVersion(((IEnumerable)item.XPathEvaluate(shop.TitleXPath)).Cast<XAttribute>().First<XAttribute>().Value, item.Element(shop.PlatformXPath).Value),
- Shop = shop,
- Link = item.Element(shop.LinkXPath).Value,
- InStock = InStock(item.Element(shop.InStockXPath).Value)
- }).ToList<PriceDetail>();
- ((IEnumerable)item.XPathEvaluate(shop.TitleXPath)).Cast<XAttribute>().First<XAttribute>().Value
- someXPathExpression
- string(someXPathExpression)
- string result = item.XPathEvaluate(shop.TitleXPath) as string;
- using System;
- using System.IO;
- using System.Xml.Linq;
- using System.Xml.XPath;
- class TestXPath
- {
- static void Main(string[] args)
- {
- string xml1 =
- @"<t>
- <a b='attribute value'/>
- <c>
- <b>element value</b>
- </c>
- <e b='attribute value'/>
- </t>";
- string xml2 =
- @"<t>
- <c>
- <b>element value</b>
- </c>
- <e b='attribute value'/>
- </t>";
- TextReader sr = new StringReader(xml1);
- XDocument xdoc = XDocument.Load(sr, LoadOptions.None);
- string result1 = xdoc.XPathEvaluate("string(/*/*/@b | /*/*/b)") as string;
- TextReader sr2 = new StringReader(xml2);
- XDocument xdoc2 = XDocument.Load(sr2, LoadOptions.None);
- string result2 = xdoc2.XPathEvaluate("string(/*/*/@b | /*/*/b)") as string;
- Console.WriteLine(result1);
- Console.WriteLine(result2);
- }
- }
- attribute value
- element value
- XElement e = item as XElement;
- XAttribute a = item as XAttribute;
- if(e != null)
- //item is of type XElement
- else
- //item is of type XAttribute
Add Comment
Please, Sign In to add comment