回答編集履歴

5

追記&訂正

2019/04/21 01:34

投稿

退会済みユーザー
test CHANGED
@@ -30,7 +30,7 @@
30
30
 
31
31
 
32
32
 
33
- DatSset.WriteXml メソッド、XmlDocument.Load メソッド、引数に Stream を取るオーバーロードを使って、MemoryStream 経由で「DB からデータを取得し XmlDocument オブジェクトを生成」をオンメモリで行うサンプルです。DB は MySQL のサンプル world の country テーブルです。
33
+ DatSset.WriteXml メソッド、XmlDocument.Load メソッド、引数に Stream を取るオーバーロードを使って、MemoryStream 経由で「DB からデータを取得し XmlDocument オブジェクトを生成」をオンメモリで行うサンプルです。DB は MySQL のサンプル world の country テーブルです。
34
34
 
35
35
 
36
36
 

4

追記&訂正

2019/04/21 01:34

投稿

退会済みユーザー
test CHANGED
@@ -26,7 +26,7 @@
26
26
 
27
27
 
28
28
 
29
- 【追伸2】
29
+ **【追伸2】**
30
30
 
31
31
 
32
32
 

3

追記

2019/04/21 01:32

投稿

退会済みユーザー
test CHANGED
@@ -23,3 +23,191 @@
23
23
 
24
24
 
25
25
  ユーザーに返すものとかではではなく、内部処理の話ですか?
26
+
27
+
28
+
29
+ 【追伸2】
30
+
31
+
32
+
33
+ DatSset.WriteXml メソッド、XmlDocument.Load メソッドは、引数に Stream を取るオーバーロードを使って、MemoryStream 経由で「DB からデータを取得し XmlDocument オブジェクトを生成」をオンメモリで行うサンプルです。DB は MySQL のサンプル world の country テーブルです。
34
+
35
+
36
+
37
+ コードは C# ですが読めなければ変換サービス [http://converter.telerik.com/](http://converter.telerik.com/) を使ってみてください。
38
+
39
+
40
+
41
+ ```
42
+
43
+ using System;
44
+
45
+ using System.Collections.Generic;
46
+
47
+ using System.Linq;
48
+
49
+ using System.Text;
50
+
51
+ using System.Threading.Tasks;
52
+
53
+ using System.Data;
54
+
55
+ using System.Data.SqlClient;
56
+
57
+ using System.IO;
58
+
59
+ using System.Xml;
60
+
61
+ using MySql.Data.MySqlClient;
62
+
63
+
64
+
65
+ namespace ConsoleApplication2
66
+
67
+ {
68
+
69
+ class Program
70
+
71
+ {
72
+
73
+ static void Main(string[] args)
74
+
75
+ {
76
+
77
+ string connectionString = @"接続文字列";
78
+
79
+ string commandText = "SELECT Code, Name, Continent, SurfaceArea, IndepYear, Population " +
80
+
81
+ "FROM country WHERE Region='North America'";
82
+
83
+ DataSet dataset = new DataSet();
84
+
85
+ using (MySqlConnection connection = new MySqlConnection(connectionString))
86
+
87
+ {
88
+
89
+ using (MySqlCommand command = new MySqlCommand(commandText, connection))
90
+
91
+ {
92
+
93
+ MySqlDataAdapter adapter = new MySqlDataAdapter();
94
+
95
+ adapter.SelectCommand = command;
96
+
97
+ adapter.Fill(dataset);
98
+
99
+ }
100
+
101
+ }
102
+
103
+ MemoryStream stream = new MemoryStream();
104
+
105
+ dataset.WriteXml(stream, XmlWriteMode.WriteSchema);
106
+
107
+ XmlDocument xmlDocument = new XmlDocument();
108
+
109
+ stream.Position = 0L;
110
+
111
+ xmlDocument.Load(stream);
112
+
113
+
114
+
115
+ Console.WriteLine(xmlDocument.OuterXml);
116
+
117
+
118
+
119
+ }
120
+
121
+ }
122
+
123
+ }
124
+
125
+ ```
126
+
127
+ 結果は以下の通りです。(見やすくなるよう改行とインデントを入れてます)
128
+
129
+
130
+
131
+ ```
132
+
133
+ <NewDataSet>
134
+
135
+ <xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
136
+
137
+ <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
138
+
139
+ <xs:complexType>
140
+
141
+ <xs:choice minOccurs="0" maxOccurs="unbounded">
142
+
143
+ <xs:element name="Table">
144
+
145
+ <xs:complexType>
146
+
147
+ <xs:sequence>
148
+
149
+ <xs:element name="Code" type="xs:string" minOccurs="0" />
150
+
151
+ <xs:element name="Name" type="xs:string" minOccurs="0" />
152
+
153
+ <xs:element name="Continent" type="xs:string" minOccurs="0" />
154
+
155
+ <xs:element name="SurfaceArea" type="xs:float" minOccurs="0" />
156
+
157
+ <xs:element name="IndepYear" type="xs:short" minOccurs="0" />
158
+
159
+ <xs:element name="Population" type="xs:int" minOccurs="0" />
160
+
161
+ </xs:sequence>
162
+
163
+ </xs:complexType>
164
+
165
+ </xs:element>
166
+
167
+ </xs:choice>
168
+
169
+ </xs:complexType>
170
+
171
+ </xs:element>
172
+
173
+ </xs:schema>
174
+
175
+ <Table>
176
+
177
+ <Code>BMU</Code>
178
+
179
+ <Name>Bermuda</Name>
180
+
181
+ <Continent>North America</Continent>
182
+
183
+ <SurfaceArea>53</SurfaceArea>
184
+
185
+ <Population>65000</Population>
186
+
187
+ </Table>
188
+
189
+ <Table>
190
+
191
+ <Code>CAN</Code>
192
+
193
+ <Name>Canada</Name>
194
+
195
+ <Continent>North America</Continent>
196
+
197
+ <SurfaceArea>9970610</SurfaceArea>
198
+
199
+ <IndepYear>1867</IndepYear>
200
+
201
+ <Population>31147000</Population>
202
+
203
+ </Table>
204
+
205
+
206
+
207
+ ・・・中略・・・
208
+
209
+
210
+
211
+ </NewDataSet>
212
+
213
+ ```

2

追記&訂正

2019/04/21 01:29

投稿

退会済みユーザー
test CHANGED
@@ -22,4 +22,4 @@
22
22
 
23
23
 
24
24
 
25
- ユーザーに返すものとはではなく、内部処理の話ですか?
25
+ ユーザーに返すものとかではではなく、内部処理の話ですか?

1

追記

2019/04/18 23:54

投稿

退会済みユーザー
test CHANGED
@@ -7,3 +7,19 @@
7
7
 
8
8
 
9
9
  お試しください。試してダメなら連絡ください(その際はどのように試したかの詳細情報も連絡ください)。
10
+
11
+
12
+
13
+ **【追伸】**
14
+
15
+
16
+
17
+ ASP.NET ということで、ブラウザでアクセスしてくるユーザーに .xml ファイルを返すと思っていましたが、違うのでしょうか?
18
+
19
+
20
+
21
+ 質問に書かれたメソッドをよく見てみると XmlDocument を返してますが、ASP.NET Web アプリでユーザーにそれを返すということはないはずですけど。
22
+
23
+
24
+
25
+ ユーザーに返すものとはではなく、内部処理の話ですか?