==[[C# LINQ使用例]]==
[[C Sharp]] | [[C Sharp サンプルコード]] |
*[http://iss.ndl.go.jp/information/api/ 国立国会図書館API]
using System.Linq;
using System.Net;
using System.Reflection[[R]]eflection;
using System.Text;
using System.Threading.Tasks;
{
var param = new List<KeyValuePair<string, string>>();
param.Add(new KeyValuePair<string, string>("title", "[[Python]]"));
xml = p.GetXml(param);
}
// 遅延評価
// books.ForEach(book => book.Title = book.Title.Replace("[[Python]]", "HOGE"));
foreach (string title in result)
XNamespace xmlns3 = "http://purl.org/dc/elements/1.1/";
var root = XElement.Load(new XmlTextReaderXmlText[[R]]eader(new StringReaderString[[R]]eader(xml)));
var records = from record in root.Elements(xmlns + "records")
public string GetUrl(List<KeyValuePair<string, string>> param)
{
string url = "http://iss.ndl.go.jp/api/sru?operation=searchRetrievesearch[[R]]etrieve&recordPacking=xml&query={0}"; string qp = string.Join(" OR O[[R]] ",
param.Select(kvp => WebUtility.UrlEncode(String.Format("{0}=\"{1}\"", kvp.Key, kvp.Value))));
return string.Format(url, qp);
using (var client = new WebClient())
{
using (var reader = new StreamReaderStream[[R]]eader(client.OpenReadOpen[[R]]ead(url)))
{
string xml = reader.ReadToEnd[[R]]eadToEnd();
Console.WriteLine(xml);
return xml;