質問編集履歴
2
【追記】を追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -81,3 +81,147 @@
|
|
81
81
|
|
82
82
|
|
83
83
|
よろしくお願いします。
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
【追記】
|
88
|
+
|
89
|
+
正規
|
90
|
+
|
91
|
+
```C#
|
92
|
+
|
93
|
+
using System;
|
94
|
+
|
95
|
+
using System.Collections.Generic;
|
96
|
+
|
97
|
+
using System.Linq;
|
98
|
+
|
99
|
+
using System.Text;
|
100
|
+
|
101
|
+
using System.Threading.Tasks;
|
102
|
+
|
103
|
+
using System.IO;
|
104
|
+
|
105
|
+
using System.Xml.Serialization;
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
namespace ReadingXML
|
110
|
+
|
111
|
+
{
|
112
|
+
|
113
|
+
[System.Xml.Serialization.XmlRoot("XML")]
|
114
|
+
|
115
|
+
public class XML
|
116
|
+
|
117
|
+
{
|
118
|
+
|
119
|
+
[System.Xml.Serialization.XmlElement("Audit")]
|
120
|
+
|
121
|
+
public System.Collections.Generic.List<ReadingXML.Audit> Audit { get;set;}
|
122
|
+
|
123
|
+
}
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
/// <summary>
|
128
|
+
|
129
|
+
/// XMLファイル内のAudit内の各要素のクラス
|
130
|
+
|
131
|
+
/// </summary>
|
132
|
+
|
133
|
+
public class Audit
|
134
|
+
|
135
|
+
{
|
136
|
+
|
137
|
+
[System.Xml.Serialization.XmlElement("Version")]
|
138
|
+
|
139
|
+
public String Version { get; set; }
|
140
|
+
|
141
|
+
[System.Xml.Serialization.XmlElement("AuditRecord")]
|
142
|
+
|
143
|
+
public System.Collections.Generic.List<ReadingXML.AuditRecord> AuditRecord { get; set; }
|
144
|
+
|
145
|
+
}
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
/// <summary>
|
150
|
+
|
151
|
+
/// XMLファイル内のAuditRecord内の各要素のクラス
|
152
|
+
|
153
|
+
/// </summary>
|
154
|
+
|
155
|
+
public class AuditRecord
|
156
|
+
|
157
|
+
{
|
158
|
+
|
159
|
+
[System.Xml.Serialization.XmlElement("Audit_Type")]
|
160
|
+
|
161
|
+
public String Audit_Type { get; set; }
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
//以下12要素(略
|
166
|
+
|
167
|
+
}
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
class Program
|
172
|
+
|
173
|
+
{
|
174
|
+
|
175
|
+
static void Main(string[] args)
|
176
|
+
|
177
|
+
{
|
178
|
+
|
179
|
+
string filePath = @"test.xml";
|
180
|
+
|
181
|
+
//読み込み
|
182
|
+
|
183
|
+
FileStream inputStream = new FileStream(filePath, FileMode.Open);//ファイルストリームのインスタンス生成
|
184
|
+
|
185
|
+
XmlSerializer serializer = new XmlSerializer(typeof(ReadingXML.Audit)); // シリアライザーのインスタンスを生成
|
186
|
+
|
187
|
+
ReadingXML.Audit model = (ReadingXML.Audit)serializer.Deserialize(inputStream);
|
188
|
+
|
189
|
+
}
|
190
|
+
|
191
|
+
}
|
192
|
+
|
193
|
+
}
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
```
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
```xml
|
202
|
+
|
203
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
204
|
+
|
205
|
+
<Audit xmlns="http://~"
|
206
|
+
|
207
|
+
xmlns:xsi="http://~"
|
208
|
+
|
209
|
+
xsi:schemaLocation="~">
|
210
|
+
|
211
|
+
<Version>11.2</Version>
|
212
|
+
|
213
|
+
<AuditRecord><Audit_Type>1</Audit_Type>
|
214
|
+
|
215
|
+
</AuditRecord>
|
216
|
+
|
217
|
+
<AuditRecord><Audit_Type>1</Audit_Type></AuditRecord>//Audit_Type以外にも要素はあるが略
|
218
|
+
|
219
|
+
<AuditRecord><Audit_Type>1</Audit_Type></AuditRecord>
|
220
|
+
|
221
|
+
<AuditRecord><Audit_Type>1</Audit_Type></AuditRecord>
|
222
|
+
|
223
|
+
<AuditRecord><Audit_Type>1</Audit_Type></AuditRecord>
|
224
|
+
|
225
|
+
</Audit>
|
226
|
+
|
227
|
+
```
|
1
XML内の処理を詳細化
test
CHANGED
File without changes
|
test
CHANGED
@@ -42,9 +42,15 @@
|
|
42
42
|
|
43
43
|
<Version>11.2</Version>
|
44
44
|
|
45
|
-
|
45
|
+
<AuditRecord>
|
46
46
|
|
47
|
+
<hoge>1</hoge>//各要素
|
48
|
+
|
49
|
+
<huge>1</huge>//各要素
|
50
|
+
|
51
|
+
</AuditRecord>
|
52
|
+
|
47
|
-
/
|
53
|
+
</Audit>
|
48
54
|
|
49
55
|
```
|
50
56
|
|