Last active
December 11, 2015 20:09
-
-
Save aoi0308/4653311 to your computer and use it in GitHub Desktop.
xml.GetElementById("hoge") 相当のことを LINQ to XML でする。
This file contains hidden or 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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Xml.Linq; | |
namespace ConsoleApplication1 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
const string xmlstr = "<root><p>aaa</p><p id=\"hoge\">bbb</p><p>ccc</p></root>"; | |
//Console.WriteLine(xmlstr); | |
XDocument xml = XDocument.Parse(xmlstr); | |
//Console.WriteLine(xml); | |
var ps = from el in xml.Descendants() where (string)el.Attribute("id") == "hoge" select el; | |
Console.WriteLine(ps.First()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment