Last active
February 10, 2018 19:57
-
-
Save dandohotaru/358da2bc01f7d869ef7a1adbe3e7a063 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//<?xml version="1.0"?> | |
//<catalog> | |
// <book id="bk101"> | |
// <author>Gambardella, Matthew</author> | |
// <title>XML Developer's Guide</title> | |
// <genre>Computer</genre> | |
// <price>44.95</price> | |
// <publish_date>2000-10-01</publish_date> | |
// <description>An in-depth look at creating applications | |
// with XML.</description> | |
// </book> | |
// <book id="bk102"> | |
// <author>Ralls, Kim</author> | |
// <title>Midnight Rain</title> | |
// <genre>Fantasy</genre> | |
// <price>5.95</price> | |
// <publish_date>2000-12-16</publish_date> | |
// <description>A former architect battles corporate zombies, | |
// an evil sorceress, and her own childhood to become queen | |
// of the world.</description> | |
// </book> | |
//</catalog> | |
void Main() | |
{ | |
var xml = @"<?xml version='1.0'?> | |
<catalog> | |
<book id='bk101'> | |
<author>Gambardella, Matthew</author> | |
<title>XML Developer's Guide</title> | |
<genre>Computer</genre> | |
<price>44.95</price> | |
<publish_date>2000-10-01</publish_date> | |
<description>An in-depth look at creating applications | |
with XML.</description> | |
</book> | |
<book id='bk102'> | |
<author>Ralls, Kim</author> | |
<title>Midnight Rain</title> | |
<genre>Fantasy</genre> | |
<price>5.95</price> | |
<publish_date>2000-12-16</publish_date> | |
<description>A former architect battles corporate zombies, | |
an evil sorceress, and her own childhood to become queen | |
of the world.</description> | |
</book> | |
</catalog>"; | |
var term = "rain"; | |
var document = XDocument.Parse(xml); | |
document.Dump("XDocument"); | |
var query = from element in document | |
.Descendants("catalog") | |
.Elements("book") | |
let book = new | |
{ | |
id = element.Attribute("id").Value, | |
author = element.Element("author").Value, | |
title = element.Element("title").Value, | |
genre = element.Element("genre").Value | |
} | |
where book.author.ToLower().Contains(term) | |
|| book.title.ToLower().Contains(term) | |
|| book.genre.ToLower().Contains(term) | |
select book; | |
query.Dump(); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment