{"id":2904,"date":"2012-01-18T12:02:55","date_gmt":"2012-01-17T18:02:55","guid":{"rendered":"http:\/\/www.moonmile.net\/blog\/archives\/2904"},"modified":"2012-07-08T13:53:28","modified_gmt":"2012-07-08T04:53:28","slug":"c-%e3%81%a7-xml-%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e3%82%92%e4%bd%9c%e6%88%90%e3%81%99%e3%82%8b%e3%81%a8%e3%81%8d%e3%81%ae%e6%af%94%e8%bc%83%ef%bc%88xmldocument-xdocument-exdoc%ef%bc%89","status":"publish","type":"post","link":"http:\/\/www.moonmile.net\/blog\/archives\/2904","title":{"rendered":"C# \u3067 XML \u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3059\u308b\u3068\u304d\u306e\u6bd4\u8f03\uff08XmlDocument, XDocument, ExDoc\uff09"},"content":{"rendered":"<p>\u300c\u30c4\u30a4\u30fc\u30c8\u30ad\u30e3\u30c3\u30c1\u2605\u2605\u2605\u300d\u3067 xml \u5f62\u5f0f\u3067\u30d5\u30a1\u30a4\u30eb\u306b\u51fa\u529b\u3059\u308b\u305f\u3081\u306b\u3001ExDoc \u3092\u62e1\u5f35\u3057\u3066\u3044\u308b\u9014\u4e2d\u3067\u3059\u3002ExDoc \u306e\u4e3b\u65e8\u3068\u3057\u3066\u300c\u30e6\u30fc\u30b6\u30fc\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u3092\u512a\u5148\u3059\u308b\u300d\u3068\u3044\u3046\u9805\u76ee\u304c\u3042\u308b\u306e\u3067\uff08\u52dd\u624b\u306b\u81ea\u5206\u3067\u4ed8\u3051\u305f\uff57\uff09\u3001\u30e6\u30fc\u30b6\u30fc\u304b\u3089\u4f7f\u3044\u3084\u3059\u3044\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u306e\u4ed5\u65b9\u306b\u5408\u308f\u305b\u3066\u62e1\u5f35\u3057\u3066\u3044\u304d\u307e\u3059\u3002\u30e6\u30fc\u30b6\u30fc\u3063\u3066\u306e\u306f\u3001\u300c\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u3092\u3059\u308b\u30d7\u30ed\u30b0\u30e9\u30de\u300d\u3063\u3066\u3053\u3068\u3067\u3059\u306d\u3001\u65b0\u3057\u3044 UIDD\uff08User Interface Developement Driven\uff09\u306e\u4e00\u74b0\u3067\u3059\uff08\u3068\u3044\u3046\u306e\u3082\u3001\u52dd\u624b\u306b\u81ea\u5206\u3067\u4ed8\u3051\u305f\uff57\uff09<\/p>\n<p>\u3068\u524d\u7f6e\u304d\u306f\u305d\u308c\u304f\u3089\u3044\u306b\u3057\u3066\u3001\u30b3\u30fc\u30c9\u3092\u6652\u3057\u3066\u304a\u304d\u307e\u3059\u3002<br \/>\nTwiCatchStar \u306e\u5185\u90e8\u30c7\u30fc\u30bf\u3092\u76f4\u63a5 xml \u306b\u66f8\u304d\u51fa\u3057\u307e\u3059\u3002<\/p>\n<p>\u25a0XmlDocument \u3092\u4f7f\u3046\u5834\u5408<\/p>\n<p>\u901a\u5e38\u306e XmlDocument \u3092\u4f7f\u3046\u5834\u5408\u3067\u3059\u3002\u307e\u3042\u3001\u65e7\u6765\u306e DOM \u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u3092\u77e5\u3063\u3066\u3044\u308c\u3070\u4f5c\u308c\u308b\u306e\u3067\u3001java \u306a\u3069\u306e\u4ed6\u8a00\u8a9e\u304b\u3089\u5165\u3063\u305f\u4eba\u306b\u306f\u3044\u3044\u306e\u3067\u3057\u3087\u3046\u304c\u3001\u7d50\u69cb\u624b\u9593\u3067\u3059\u3002<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\/\/ XmlDocument \u3092\u4f7f\u3046\u5834\u5408\r\nXmlDocument doc = new XmlDocument();\r\nXmlElement root = doc.CreateElement(&quot;TwiCatchStar&quot;);\r\nroot.SetAttribute(&quot;version&quot;, APPVERSION);\r\nroot.SetAttribute(&quot;created_at&quot;, DateTime.Now.ToString(&quot;yyyy\/MM\/dd HH:mm:ss&quot;));\r\ndoc.AppendChild(root);\r\nXmlElement user = doc.CreateElement(&quot;user&quot;);\r\nroot.AppendChild(user);\r\nuser.AppendChild(doc.CreateElement(&quot;screen_name&quot;)).InnerText= username;\r\nuser.AppendChild(doc.CreateElement(&quot;profile_image_url&quot;)).InnerText= profile_image_url;\r\nXmlElement statuses = doc.CreateElement(&quot;statuses&quot;);\r\nstatuses.SetAttribute(&quot;type&quot;, &quot;array&quot;);\r\nroot.AppendChild(statuses);\r\nforeach (Tweet twi in items)\r\n{\r\n\tXmlElement status = doc.CreateElement(&quot;status&quot;);\r\n\tstatuses.AppendChild(status);\r\n\tstatus.AppendChild(doc.CreateElement(&quot;id&quot;)).InnerText= twi.ID;\r\n\tstatus.AppendChild(doc.CreateElement(&quot;text&quot;)).InnerText= twi.text;\r\n\tstatus.AppendChild(doc.CreateElement(&quot;created_at&quot;)).InnerText= twi.CreatedAt.ToString(&quot;yyyy\/MM\/dd HH:mm:ss&quot;);\r\n}\r\n<\/pre>\n<p>\u25a0LINQ to XML \u3092\u4f7f\u3046\u5834\u5408<\/p>\n<p>\u4eca\u5f8c\u3001.NET \u8a00\u8a9e\u3067\u30c7\u30fc\u30bf\u30b9\u30c8\u30ec\u30fc\u30b8\u7d61\u307f\uff08XML\u5f62\u5f0f\u3082\u542b\u3080\uff09\u306e\u306f\u3001\u4e00\u62ec\u3057\u3066 LINQ \u304c\u63a8\u5968\u3001\u3063\u3066\u3053\u3068\u306b\u306a\u308b\u3093\u3067\u3057\u3087\u3046\u304c\u3001LINQ to XML \u3063\u3066\u3044\u307e\u3044\u3061\u4f7f\u3044\u3065\u3089\u3044\u3093\u3067\u3059\u3088\u306d\u3002\u305d\u308c\u3067\u3082\u3001XmlDocument \u3088\u308a\u306f\u76f4\u611f\u7684\u304b\u3082\u3002<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\/\/ LINQ to XML \u3092\u4f7f\u3046\u5834\u5408\r\nXDocument doc = new XDocument();\r\nXElement root = new XElement(&quot;TwiCatchStar&quot;);\r\ndoc.Add(root);\r\nroot.SetAttributeValue(&quot;version&quot;, APPVERSION);\r\nroot.SetAttributeValue(&quot;created_at&quot;, DateTime.Now.ToString(&quot;yyyy\/MM\/dd HH:mm:ss&quot;));\r\nXElement user = new XElement(&quot;user&quot;);\r\nroot.Add(user);\r\nuser.Add(new XElement(&quot;screen_name&quot;, username));\r\nuser.Add(new XElement(&quot;profile_image_url&quot;, profile_image_url));\r\nXElement statuses = new XElement(&quot;statuses&quot;);\r\nstatuses.SetAttributeValue(&quot;type&quot;, &quot;array&quot;);\r\nforeach (Tweet twi in items)\r\n{\r\n\tXElement status = new XElement(&quot;status&quot;);\r\n\tstatuses.Add(status);\r\n\tstatus.Add(new XElement(&quot;id&quot;, twi.ID));\r\n\tstatus.Add(new XElement(&quot;text&quot;, twi.text));\r\n\tstatus.Add(new XElement(&quot;created_at&quot;, twi.CreatedAt.ToString(&quot;yyyy\/MM\/dd HH:mm:ss&quot;)));\r\n}\r\n<\/pre>\n<p>\u25a0ExDoc \u3092\u4f7f\u3046\u5834\u5408<\/p>\n<p>ExDoc \u306f\u300c\u3082\u3046 LINQ to XML \u306f\u3044\u3089\u306a\u3044\u300d\u3092\u4e3b\u65e8\u306b\u3057\u3066\u4f5c\u3063\u3066\u3044\u308b\u306e\u3067\u3001+= \u6f14\u7b97\u5b50\u3084 []\u6f14\u7b97\u5b50\u3092\u9069\u5f53\u306b\u30aa\u30fc\u30d0\u30fc\u30e9\u30a4\u30c9\u3057\u3066\u4f5c\u6210\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002<br \/>\n\u672c\u6765\u306a\u3089\u3070\u3001CreateElement \u3068\u304b AppendElement \u3068\u3044\u3046\u300c\u540d\u524d\u300d\u3092\u4f7f\u308f\u305a\u306b\u3084\u308a\u305f\u3044\u306e\u3067\u3059\u304c\u3001\u3061\u3087\u3063\u3068\u6a21\u7d22\u4e2d\u3002<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nEXDocument doc = new EXDocument(&quot;TwiCatchStar&quot;);\r\ndoc.Root&#x5B;&quot;version&quot;] = APPVERSION;\r\ndoc.Root&#x5B;&quot;created_at&quot;] = DateTime.Now.ToString(&quot;yyyy\/MM\/dd HH:mm:ss&quot;);\r\nEXElement user = doc.Root.AppendElement(&quot;user&quot;);\r\nuser += doc.CreateElement(&quot;screen_name&quot;, username);\r\nuser += doc.CreateElement(&quot;profile_image_url&quot;, profile_image_url);\r\nEXElement statuses = doc.Root.AppendElement(&quot;statuses&quot;);\r\nstatuses&#x5B;&quot;type&quot;] = &quot;array&quot;;\r\nforeach (Tweet twi in items)\r\n{\r\n\tEXElement status = statuses.AppendElement(&quot;status&quot;);\r\n\tstatus += doc.CreateElement(&quot;id&quot;, twi.ID);\r\n\tstatus += doc.CreateElement(&quot;text&quot;, twi.text);\r\n\tstatus += doc.CreateElement(&quot;created_at&quot;, twi.CreatedAt.ToString(&quot;yyyy\/MM\/dd HH:mm:ss&quot;));\r\n}\r\n<\/pre>\n<p>LINQ to XML \u3067\u306f\u3001Add \u30e1\u30bd\u30c3\u30c9\u5185\u3067\u8981\u7d20\u3092\u4f5c\u6210\u3057\u3066\u3044\u307e\u3059\u304c\u3001\u5b9f\u306f\u9069\u5f53\u306a\u62e1\u5f35\u30e1\u30bd\u30c3\u30c9\u3092\u4f5c\u308c\u3070 AppendElement \u306e\u3088\u3046\u306a\u5f62\u3067\u30a2\u30af\u30bb\u30b9\u304c\u53ef\u80fd\u306a\u306e\u3067\u3001ExDoc \u306e\u512a\u4f4d\u6027\u3068\u3044\u3046\u306e\u306f\u3053\u306e\u5834\u5408\u306f\u3042\u307e\u308a\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\n<p>\u25a0VB \u3067\u4f5c\u308b\u5834\u5408<\/p>\n<p>\u5b9f\u306f\u3001VB \u3067\u4f5c\u308b\u306e\u304c\u4e00\u756a\u76f4\u611f\u7684\u306a\u3093\u3067\u3059\u3088\u306d\u3002XML \u7528\u306e\u62e1\u5f35\u6587\u6cd5\u304c VB \u306b\u5099\u308f\u3063\u3066\u3044\u308b\u306e\u3067\u3001\u3053\u308c\u3092\u4f7f\u3046\u3068&#8230;<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n&#039;&#039;&#039;\r\n&#039;&#039;&#039; \u30b3\u30ec\u30af\u30b7\u30e7\u30f3\r\n&#039;&#039;&#039;\r\n&#039;&#039;&#039;\r\nPublic _tweets As List(Of Tweet)\r\n&#039;&#039;&#039;\r\n&#039;&#039;&#039; \u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u30af\u30e9\u30b9\r\n&#039;&#039;&#039;\r\n&#039;&#039;&#039;\r\nPublic Class Tweet\r\n\tPublic Property ID As String\r\n\tPublic Property Text As String\r\n\tPublic Property Create_at As Date\r\nEnd Class\r\n\r\nPrivate Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click\r\n\tDim APPVERSION = &amp;quot;0.3&amp;quot;\r\n\tDim username = &amp;quot;moonmile&amp;quot;\r\n\tDim profile_image_url = &amp;quot;&amp;quot;\r\n\r\n\tDim root As XElement =\r\n\t &lt;TwiCatchStar version=&lt;%= APPVERSION %&gt; created_at=&lt;%= Date.Now.ToString(&amp;quot;yyyy\/MM\/dd HH:mm:ss&amp;quot;) %&gt;&gt;\r\n\t &lt;\/TwiCatchStar&gt;\r\n\r\n\tDim user As XElement =\r\n\t &lt;user&gt;\r\n\t\t &lt;screen_name&gt;&lt;%= username %&gt;&lt;\/screen_name&gt;\r\n\t\t &lt;profile_image_url&gt;&lt;%= profile_image_url %&gt;&lt;\/profile_image_url&gt;\r\n\t &lt;\/user&gt;\r\n\r\n\tDim statuses =\r\n\t &lt;statues&gt;\r\n\t\t &lt;%= From t In _tweets Select\r\n\t\t\t &lt;status&gt;\r\n\t\t\t\t &lt;id&gt;&lt;%= t.ID %&gt;&lt;\/id&gt;\r\n\t\t\t\t &lt;text&gt;&lt;%= t.Text %&gt;&lt;\/text&gt;\r\n\t\t\t\t &lt;create_at&gt;&lt;%= t.Create_at.ToString(&amp;quot;yyyy\/MM\/dd HH:mm:ss&amp;quot;) %&gt;&lt;\/create_at&gt;\r\n\t\t\t &lt;\/status&gt; %&gt;\r\n\t &lt;\/statues&gt;\r\n\r\n\troot.Add(user)\r\n\troot.Add(statuses)\r\n\r\n\tMe.TextBox1.Text = root.ToString()\r\n\r\nEnd Sub\r\n<\/pre>\n<p>\u306e\u3088\u3046\u306b\u3001\u306a\u3093\u3066\u76f4\u611f\u7684\u306b\u66f8\u3051\u308b\u3093\u3067\u3057\u3087\u3046\u30c3!!! \u307e\u308b\u3067\u3001ASP.NET \u306e\u57cb\u3081\u8fbc\u307f\u304b\u3001PHP \u306e\u3088\u3046\u306b\u8a18\u8ff0\u304c\u3067\u304d\u307e\u3059\u3002\u3053\u308c\u306b\u306f\u3001ExDoc \u3082\u8131\u5e3d orz<br \/>\n\u4e00\u898b\u3001VB \u306e\u307b\u3046\u304c\u884c\u6570\u304c\u9577\u3044\u306e\u3067\u975e\u52b9\u7387\u306b\u898b\u3048\u308b\u306e\u3067\u3059\u304c\u3001\u4fdd\u5b88\u6027\u306f\u629c\u7fa4\u3067\u3059\u3088\u306d\u3002\u4e00\u77a5\u3057\u305f\u3060\u3051\u3067\u5909\u66f4\u304c\u53ef\u80fd\u3067\u3059\u3002\u3053\u306e\u305f\u3081\u306b VB \u3092\u4f7f\u3046\u306e\u3082\u3044\u3044\u304b\u3082\uff08\u9055<\/p>\n<p>2012\/07\/08 \u8ffd\u8a18<\/p>\n<p>Egtra \u3055\u3093\u3088\u308a\u6559\u3048\u3066\u8cb0\u3063\u305f\u65b9\u6cd5\u3067\u3001LINQ to XML \u3092\u66f8\u304d\u76f4\u3059\u3068\u3053\u3093\u306a\u611f\u3058\u3002<br \/>\n\u3053\u306e\u8a18\u4e8b\u3092\u66f8\u3044\u305f\u3068\u304d\u306b\u3001XElement \u306b\u5b50\u306e\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u3092\u3069\u3046\u5165\u308c\u308c\u3070\u5206\u304b\u3089\u306a\u304b\u3063\u305f\u306e\u3067\u3059\u304c\u3001items.Select \u306a\u611f\u3058\u3067\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u3092\u6e21\u3059\u3068\u3001\u81ea\u52d5\u7684\u306b\u5b50\u306b\u914d\u5217\u3068\u3057\u3066\u4ed8\u3051\u52a0\u308f\u308b\u306e\u3067\u3059\u306d\u3002\u306a\u308b\u307b\u3069\u3002<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nXDocument doc = new XDocument(\r\n\tnew XElement(&amp;quot;TwiCatchStar&amp;quot;,\r\n\t\tnew XAttribute(&amp;quot;version&amp;quot;, APPVERSION),\r\n\t\tnew XAttribute(&amp;quot;created_at&amp;quot;, DateTime.Now.ToString(&amp;quot;yyyy\/MM\/dd HH:mm:ss&amp;quot;)),\r\n\t\tnew XElement(&amp;quot;user&amp;quot;,\r\n\t\t\tnew XElement(&amp;quot;screen_name&amp;quot;, username),\r\n\t\t\tnew XElement(&amp;quot;profile_image_url&amp;quot;, profile_image_url)),\r\n\t\tnew XElement(&amp;quot;statuses&amp;quot;,\r\n\t\t\tnew XAttribute(&amp;quot;type&amp;quot;, &amp;quot;array&amp;quot;),\r\n\t\t\titems.Select(twi =&gt;\r\n\t\t\t\tnew XElement(&amp;quot;status&amp;quot;,\r\n\t\t\t\t\tnew XElement(&amp;quot;id&amp;quot;, twi.ID),\r\n\t\t\t\t\tnew XElement(&amp;quot;text&amp;quot;, twi.Text),\r\n\t\t\t\t\tnew XElement(&amp;quot;created_at&amp;quot;, twi.CreatedAt.ToString(&amp;quot;yyyy\/MM\/dd HH:mm:ss&amp;quot;)))))));\r\n\r\n<\/pre>\n<p>\u5b9f\u306f\u4ee5\u524d\u3001XElement \u3092\u6271\u3063\u305f\u6642\u300c\u3053\u308c\u3063\u3066DOM\u306b\u6e96\u62e0\u3057\u3066\u3044\u306a\u3044\u300d\uff08Document\u304b\u3089Node\u3092\u4f5c\u6210\u3057\u306a\u3044\uff09\u3068\u3044\u3046\u70b9\u3067\u3061\u3087\u3063\u3068\u5acc\u3063\u3066\u3044\u305f\u306e\u3067\u3059\u304c\u3001\u3053\u3046\u3044\u3046\u66f8\u304d\u65b9\u304c\u3067\u304d\u308b\u3068\u3001VB \u306e\u3088\u3046\u306b XML \u306e\u69cb\u9020\u901a\u308a\u306b\u66f8\u3051\u308b\u304b\u3089\u3044\u3044\u3067\u3059\u3088\u306d\u3002<br \/>\nExDoc \u3082 doc.CreateElement \u306e\u3088\u3046\u306b\u305b\u305a\u306b\u3001\u3084\u3063\u3071\u308a doc += new EXElement(&#8230;) \u3068\u304b\u3001doc.Append( new EXElement(&#8230;), new EXElemnet(&#8230;)) \u306e\u3088\u3046\u306b\u7f85\u5217\u3067\u304d\u308b\u3088\u3046\u306b\u6539\u9020\u3057\u3088\u3046\u304b\u306a\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u300c\u30c4\u30a4\u30fc\u30c8\u30ad\u30e3\u30c3\u30c1\u2605\u2605\u2605\u300d\u3067 xml \u5f62\u5f0f\u3067\u30d5\u30a1\u30a4\u30eb\u306b\u51fa\u529b\u3059\u308b\u305f\u3081\u306b\u3001ExDoc \u3092\u62e1\u5f35\u3057\u3066\u3044\u308b\u9014\u4e2d\u3067\u3059\u3002ExDoc \u306e\u4e3b\u65e8\u3068\u3057\u3066\u300c\u30e6\u30fc\u30b6\u30fc\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u3092\u512a\u5148\u3059\u308b\u300d\u3068\u3044\u3046\u9805\u76ee\u304c\u3042\u308b\u306e\u3067\uff08\u52dd\u624b\u306b\u81ea\u5206\u3067\u4ed8\u3051\u305f\uff57\uff09\u3001\u30e6\u30fc\u30b6 &hellip; <a href=\"http:\/\/www.moonmile.net\/blog\/archives\/2904\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[26,23,33],"tags":[],"class_list":["post-2904","post","type-post","status-publish","format-standard","hentry","category-uidd","category-csharp","category-vb"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts\/2904","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/comments?post=2904"}],"version-history":[{"count":8,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts\/2904\/revisions"}],"predecessor-version":[{"id":2923,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts\/2904\/revisions\/2923"}],"wp:attachment":[{"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/media?parent=2904"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/categories?post=2904"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/tags?post=2904"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}