{"id":201,"date":"2021-02-18T19:01:29","date_gmt":"2021-02-18T10:01:29","guid":{"rendered":"https:\/\/www.opentone.co.jp\/optonlabos\/?p=201"},"modified":"2025-05-12T10:06:26","modified_gmt":"2025-05-12T01:06:26","slug":"sgmlreader%e3%81%a7linq-to-html","status":"publish","type":"post","link":"https:\/\/www.opentone.co.jp\/ot-lab\/all\/uncategorized\/sgmlreader%e3%81%a7linq-to-html","title":{"rendered":"SGMLReader\u3067LINQ to HTML"},"content":{"rendered":"\n<p>\u4e00\u822c\u306b\u516c\u958b\u3055\u308c\u3066\u3044\u308bWEB\u30b5\u30a4\u30c8\u306e\u60c5\u5831\u3092\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306b\u6d3b\u7528\u3057\u305f\u3044\u5834\u5408\u3001<br>\u305d\u306e\u30b5\u30a4\u30c8\u304cWebAPI\u3092\u63d0\u4f9b\u3057\u3066\u304f\u3044\u308c\u3070\u4f55\u3082\u554f\u984c\u304c\u306a\u3044\u306e\u3067\u3059\u304c\u3001\u5927\u62b5\u306fHTML\u3067\u516c\u958b\u3057\u3066\u3044\u308b\u3060\u3051\u3067\u3059\u3002<br>\u3088\u304f\u3042\u308b\u89e3\u6c7a\u624b\u6bb5\u3068\u3057\u3066\u306f\u3001HTML Parser\u3092\u5229\u7528\u3059\u308b\u304b\u3001\u6b63\u898f\u8868\u73fe\u3092\u99c6\u4f7f\u3057\u3066\u81ea\u524d\u3067HTML\u89e3\u6790\u3092\u3059\u308b\u4e8b\u306b\u306a\u308b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>\u3055\u3066\u3001.NET Framework\u306b\u306fLINQ(\u7d71\u5408\u8a00\u8a9e\u30af\u30a8\u30ea)\u3068\u547c\u3070\u308c\u308b\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u304c\u5b58\u5728\u3057\u3001<br>\u305d\u306e\u306a\u304b\u306eLINQ to XML\u3068\u3044\u3046\u6280\u8853\u3092\u5229\u7528\u3059\u308b\u3053\u3068\u306b\u3088\u308aXML\u3092\u975e\u5e38\u306b\u30b9\u30de\u30fc\u30c8\u306a\u5f62\u3067\u6271\u3046\u3053\u3068\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u305d\u3053\u3067\u4eca\u56de\u306f\u3001<a href=\"http:\/\/developer.mindtouch.com\/en\/docs\/SgmlReader\" target=\"_blank\" rel=\"noreferrer noopener\">SGMLReader<\/a>\u3068\u3044\u3046\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u3044\u3001<br>LINQ to XML\u3068\u7d44\u307f\u5408\u308f\u305b\u305f\u30b9\u30af\u30ec\u30a4\u30d4\u30f3\u30b0\u306b\u3064\u3044\u3066\u7d39\u4ecb\u3057\u307e\u3059\u3002<br>\u6240\u8b02\u3001LINQ to HTML\u3063\u3066\u30e4\u30c4\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u307e\u305a\u306f\u7c21\u5358\u306a\u4f7f\u3044\u65b9\u3092\u898b\u3066\u3044\u305f\u3060\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">[csharp]\n        static void Main(string[] args)\n        {\n            XDocument xml;\n            using (var sgmlReader = new SgmlReader() { Href = \"http:\/\/www.opentone.co.jp\/\" })\n            {\n                xml = XDocument.Load(sgmlReader);\n            }\n            \/\/ \u305f\u3063\u305f\u306e3\u884c\u3067HTML to XML\u304c\u5b8c\u4e86\u3002\u5f8c\u306fLINQ to XML\u3067\u64cd\u4f5c\u3059\u308b\u3060\u3051\n\n            var ns = xml.Root.Name.Namespace;\u3000\/\/ XML\u540d\u524d\u7a7a\u9593\n            foreach (var item in xml.Descendants(ns + \"h4\"))\n            {\n                Console.WriteLine(item.Value); \/\/ OPENTONE\u306eTOP\u30da\u30fc\u30b8\u3088\u308a\u30b5\u30fc\u30d3\u30b9\u3092\u5217\u6319\n            }\n\n        }\n[\/csharp]<\/pre>\n\n\n\n<p>\u3054\u89a7\u306e\u3068\u304a\u308a\u3001\u975e\u5e38\u306b\u7c21\u5358\u3067\u3059\u3002<br>Html\u304cXDocument\u306b\u306a\u3063\u3066\u3057\u307e\u3048\u3070\u3001\u5f8c\u306fLINQ to XML\u306e\u51fa\u756a\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u4f8b\u306f\u3001\u5f0a\u793e(OPENTONE)\u306e\u30c8\u30c3\u30d7\u30b5\u30a4\u30c8\u306b\u30a2\u30af\u30bb\u30b9\u3057\u3066\u3001h4\u30bf\u30b0\u3067\u56f2\u307e\u308c\u305f\u30b5\u30fc\u30d3\u30b9\u60c5\u5831\u3092\u5217\u6319\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img fetchpriority=\"high\" decoding=\"async\" width=\"493\" height=\"203\" src=\"https:\/\/www.opentone.co.jp\/optonlabos\/wp-content\/uploads\/sites\/11\/2021\/02\/OT_20110403_P389_01.png\" alt=\"\" class=\"wp-image-202\" title=\"OPENTONE\u306f\u3053\u3093\u306a\u30b5\u30fc\u30d3\u30b9\u3092\u3084\u3063\u3066\u3044\u307e\u3059\u3002\" srcset=\"https:\/\/www.opentone.co.jp\/ot-lab\/wp-content\/uploads\/sites\/11\/2021\/02\/OT_20110403_P389_01.png 493w, https:\/\/www.opentone.co.jp\/ot-lab\/wp-content\/uploads\/sites\/11\/2021\/02\/OT_20110403_P389_01-300x124.png 300w\" sizes=\"(max-width: 493px) 100vw, 493px\" \/><\/figure><\/div>\n\n\n\n<p>\u7d9a\u3044\u3066\u3001\u3088\u308a\u4e00\u822c\u7684\u306a\u30b5\u30a4\u30c8\u304b\u3089\u60c5\u5831\u3092\u53d6\u5f97\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">[csharp]\n        static void Main(string[] args)\n        {\n            XDocument xml;\n            using (var sgmlReader = new SgmlReader() { Href = \"http:\/\/eki.jorudan.co.jp\/unk\/\" })\n            {\n                xml = XDocument.Load(sgmlReader);\n            }\n\n            var ns = xml.Root.Name.Namespace;\n            var query = xml.Descendants(ns + \"table\")\n                .First(x =&gt; x.Attribute(\"class\").Value.Equals(\"unktable\"))\n                .Descendants(ns + \"tr\")\n                .Skip(1)\n                .Select(e =&gt; e.Elements(ns + \"td\").ToList())\n                .Select(info =&gt; new\n                {\n                    Subject = info[1].Descendants(info[1].GetDefaultNamespace() + \"strong\").First().Value,\n                    Description = info[2].FirstNode.ToString()\n                });\n\n            foreach (var item in query)\n            {\n                Console.WriteLine(item.Subject + \" - \" + item.Description);\n            }\n        }\n[\/csharp]<\/pre>\n\n\n\n<p>\u4e0a\u306e\u4f8b\u3067\u306f\u3001\u904b\u884c\u60c5\u5831\u30b5\u30fc\u30d3\u30b9\u306e\u300c\u30b8\u30e7\u30eb\u30c0\u30f3\u300d\u3088\u308a\u3001\u904b\u884c\u60c5\u5831\u306e\u5217\u8eca\u540d\u3068\u72b6\u6cc1\u3092\u53d6\u5f97\u3057\u3066\u3044\u307e\u3059\u3002<br>\u6700\u8fd1\u3001\u8a08\u753b\u505c\u96fb\u306e\u5f71\u97ff\u3082\u3042\u3063\u3066\u9244\u9053\u904b\u884c\u72b6\u6cc1\u304c\u4e0d\u5b89\u5b9a\u3067\u3059\u3057\u3001\u3088\u304f\u8a2a\u554f\u3059\u308b\u3093\u3067\u3059\u3088\u306d\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"677\" height=\"222\" src=\"https:\/\/www.opentone.co.jp\/optonlabos\/wp-content\/uploads\/sites\/11\/2021\/02\/OT_20110403_P389_02.png\" alt=\"\" class=\"wp-image-203\" srcset=\"https:\/\/www.opentone.co.jp\/ot-lab\/wp-content\/uploads\/sites\/11\/2021\/02\/OT_20110403_P389_02.png 677w, https:\/\/www.opentone.co.jp\/ot-lab\/wp-content\/uploads\/sites\/11\/2021\/02\/OT_20110403_P389_02-300x98.png 300w\" sizes=\"(max-width: 677px) 100vw, 677px\" \/><\/figure><\/div>\n\n\n\n<p>WebAPI\u304c\u516c\u958b\u3055\u308c\u3066\u3044\u306a\u3044\u30b5\u30a4\u30c8\u3067\u3082\u3001\u3053\u308c\u306a\u3089\u7c21\u5358\u306b\u30b9\u30af\u30ec\u30a4\u30d4\u30f3\u30b0\u304c\u53ef\u80fd\u3067\u3059\u3002<br>\u5143\u3005HTML\u306a\u306e\u3067\u62bd\u51fa\u3092\u3059\u308b\u306b\u9069\u3057\u305fXML\u3067\u306f\u306a\u3044\u305f\u3081\u3001HTML Parser\u3092\u5229\u7528\u3057\u305f\u5834\u5408\u3068\u540c\u3058\u304f\u3001\u76ee\u7684\u306e\u60c5\u5831\u306b\u305f\u3069\u308a\u7740\u304f\u305f\u3081\u306b\u306f\u6c7a\u3081\u6253\u3061\u306e\u90e8\u5206\u304c\u5165\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u304c\u3001<br>LINQ to XML\u3068\u3044\u3046\u5f37\u529b\u306aXML\u6587\u66f8\u51e6\u7406\u304c\u4f7f\u3048\u308b\u306e\u306f\u5927\u304d\u306a\u30e1\u30ea\u30c3\u30c8\u3060\u3068\u601d\u3044\u307e\u3059\u3002<br>\u662f\u975e\u3001\u8a66\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002&nbsp;<\/p>\n<div class=\"opent-_2\" style=\"margin-top: 10px;margin-right: 10px;margin-bottom: 10px;margin-left: 10px;\" id=\"opent-2980495616\"><a href=\"https:\/\/www.opentone.co.jp\/backlog\/\" aria-label=\"twitter_backlogskt_new\"><img src=\"https:\/\/www.opentone.co.jp\/ot-lab\/wp-content\/uploads\/sites\/11\/2023\/02\/twitter_backlogskt_new.jpg\" alt=\"\"  srcset=\"https:\/\/www.opentone.co.jp\/ot-lab\/wp-content\/uploads\/sites\/11\/2023\/02\/twitter_backlogskt_new.jpg 1024w, https:\/\/www.opentone.co.jp\/ot-lab\/wp-content\/uploads\/sites\/11\/2023\/02\/twitter_backlogskt_new-300x157.jpg 300w, https:\/\/www.opentone.co.jp\/ot-lab\/wp-content\/uploads\/sites\/11\/2023\/02\/twitter_backlogskt_new-768x401.jpg 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" width=\"384\" height=\"200\"   \/><\/a><\/div>","protected":false},"excerpt":{"rendered":"<p>\u4e00\u822c\u306b\u516c\u958b\u3055\u308c\u3066\u3044\u308bWEB\u30b5\u30a4\u30c8\u306e\u60c5\u5831\u3092\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306b\u6d3b\u7528\u3057\u305f\u3044\u5834\u5408\u3001\u305d\u306e\u30b5\u30a4\u30c8\u304cWebAPI\u3092<\/p>\n","protected":false},"author":1,"featured_media":202,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_uag_custom_page_level_css":"","_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[1],"tags":[8],"class_list":["post-201","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","tag-blog",""],"acf":[],"aioseo_notices":[],"uagb_featured_image_src":{"full":["https:\/\/www.opentone.co.jp\/ot-lab\/wp-content\/uploads\/sites\/11\/2021\/02\/OT_20110403_P389_01.png",493,203,false],"thumbnail":["https:\/\/www.opentone.co.jp\/ot-lab\/wp-content\/uploads\/sites\/11\/2021\/02\/OT_20110403_P389_01-150x150.png",150,150,true],"medium":["https:\/\/www.opentone.co.jp\/ot-lab\/wp-content\/uploads\/sites\/11\/2021\/02\/OT_20110403_P389_01-300x124.png",300,124,true],"medium_large":["https:\/\/www.opentone.co.jp\/ot-lab\/wp-content\/uploads\/sites\/11\/2021\/02\/OT_20110403_P389_01.png",493,203,false],"large":["https:\/\/www.opentone.co.jp\/ot-lab\/wp-content\/uploads\/sites\/11\/2021\/02\/OT_20110403_P389_01.png",493,203,false],"1536x1536":["https:\/\/www.opentone.co.jp\/ot-lab\/wp-content\/uploads\/sites\/11\/2021\/02\/OT_20110403_P389_01.png",493,203,false],"2048x2048":["https:\/\/www.opentone.co.jp\/ot-lab\/wp-content\/uploads\/sites\/11\/2021\/02\/OT_20110403_P389_01.png",493,203,false],"engage-mag-carousel-img":["https:\/\/www.opentone.co.jp\/ot-lab\/wp-content\/uploads\/sites\/11\/2021\/02\/OT_20110403_P389_01.png",493,203,false],"engage-mag-carousel-img-landscape":["https:\/\/www.opentone.co.jp\/ot-lab\/wp-content\/uploads\/sites\/11\/2021\/02\/OT_20110403_P389_01.png",493,203,false],"engage-mag-carousel-large-img":["https:\/\/www.opentone.co.jp\/ot-lab\/wp-content\/uploads\/sites\/11\/2021\/02\/OT_20110403_P389_01.png",493,203,false],"engage-mag-carousel-large-img-landscape":["https:\/\/www.opentone.co.jp\/ot-lab\/wp-content\/uploads\/sites\/11\/2021\/02\/OT_20110403_P389_01.png",493,203,false],"engage-mag-large-thumb":["https:\/\/www.opentone.co.jp\/ot-lab\/wp-content\/uploads\/sites\/11\/2021\/02\/OT_20110403_P389_01.png",493,203,false],"engage-mag-small-thumb":["https:\/\/www.opentone.co.jp\/ot-lab\/wp-content\/uploads\/sites\/11\/2021\/02\/OT_20110403_P389_01-350x203.png",350,203,true]},"uagb_author_info":{"display_name":"ah106rx4o4","author_link":"https:\/\/www.opentone.co.jp\/ot-lab\/author\/ah106rx4o4"},"uagb_comment_info":1,"uagb_excerpt":"\u4e00\u822c\u306b\u516c\u958b\u3055\u308c\u3066\u3044\u308bWEB\u30b5\u30a4\u30c8\u306e\u60c5\u5831\u3092\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306b\u6d3b\u7528\u3057\u305f\u3044\u5834\u5408\u3001\u305d\u306e\u30b5\u30a4\u30c8\u304cWebAPI\u3092","_links":{"self":[{"href":"https:\/\/www.opentone.co.jp\/ot-lab\/wp-json\/wp\/v2\/posts\/201","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.opentone.co.jp\/ot-lab\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.opentone.co.jp\/ot-lab\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.opentone.co.jp\/ot-lab\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.opentone.co.jp\/ot-lab\/wp-json\/wp\/v2\/comments?post=201"}],"version-history":[{"count":1,"href":"https:\/\/www.opentone.co.jp\/ot-lab\/wp-json\/wp\/v2\/posts\/201\/revisions"}],"predecessor-version":[{"id":204,"href":"https:\/\/www.opentone.co.jp\/ot-lab\/wp-json\/wp\/v2\/posts\/201\/revisions\/204"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.opentone.co.jp\/ot-lab\/wp-json\/wp\/v2\/media\/202"}],"wp:attachment":[{"href":"https:\/\/www.opentone.co.jp\/ot-lab\/wp-json\/wp\/v2\/media?parent=201"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.opentone.co.jp\/ot-lab\/wp-json\/wp\/v2\/categories?post=201"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.opentone.co.jp\/ot-lab\/wp-json\/wp\/v2\/tags?post=201"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}