質問編集履歴
2
【追記】を追記
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -39,4 +39,76 @@
|
|
|
39
39
|
XMLファイルのAudit VersionをXMLファイル内から削除すると正常に読み込むことが出来るのですが、
|
|
40
40
|
コード内で、Audit Versionを無視するような処理は可能でしょうか?
|
|
41
41
|
|
|
42
|
-
よろしくお願いします。
|
|
42
|
+
よろしくお願いします。
|
|
43
|
+
|
|
44
|
+
【追記】
|
|
45
|
+
正規
|
|
46
|
+
```C#
|
|
47
|
+
using System;
|
|
48
|
+
using System.Collections.Generic;
|
|
49
|
+
using System.Linq;
|
|
50
|
+
using System.Text;
|
|
51
|
+
using System.Threading.Tasks;
|
|
52
|
+
using System.IO;
|
|
53
|
+
using System.Xml.Serialization;
|
|
54
|
+
|
|
55
|
+
namespace ReadingXML
|
|
56
|
+
{
|
|
57
|
+
[System.Xml.Serialization.XmlRoot("XML")]
|
|
58
|
+
public class XML
|
|
59
|
+
{
|
|
60
|
+
[System.Xml.Serialization.XmlElement("Audit")]
|
|
61
|
+
public System.Collections.Generic.List<ReadingXML.Audit> Audit { get;set;}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/// <summary>
|
|
65
|
+
/// XMLファイル内のAudit内の各要素のクラス
|
|
66
|
+
/// </summary>
|
|
67
|
+
public class Audit
|
|
68
|
+
{
|
|
69
|
+
[System.Xml.Serialization.XmlElement("Version")]
|
|
70
|
+
public String Version { get; set; }
|
|
71
|
+
[System.Xml.Serialization.XmlElement("AuditRecord")]
|
|
72
|
+
public System.Collections.Generic.List<ReadingXML.AuditRecord> AuditRecord { get; set; }
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/// <summary>
|
|
76
|
+
/// XMLファイル内のAuditRecord内の各要素のクラス
|
|
77
|
+
/// </summary>
|
|
78
|
+
public class AuditRecord
|
|
79
|
+
{
|
|
80
|
+
[System.Xml.Serialization.XmlElement("Audit_Type")]
|
|
81
|
+
public String Audit_Type { get; set; }
|
|
82
|
+
|
|
83
|
+
//以下12要素(略
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
class Program
|
|
87
|
+
{
|
|
88
|
+
static void Main(string[] args)
|
|
89
|
+
{
|
|
90
|
+
string filePath = @"test.xml";
|
|
91
|
+
//読み込み
|
|
92
|
+
FileStream inputStream = new FileStream(filePath, FileMode.Open);//ファイルストリームのインスタンス生成
|
|
93
|
+
XmlSerializer serializer = new XmlSerializer(typeof(ReadingXML.Audit)); // シリアライザーのインスタンスを生成
|
|
94
|
+
ReadingXML.Audit model = (ReadingXML.Audit)serializer.Deserialize(inputStream);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
```xml
|
|
102
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
103
|
+
<Audit xmlns="http://~"
|
|
104
|
+
xmlns:xsi="http://~"
|
|
105
|
+
xsi:schemaLocation="~">
|
|
106
|
+
<Version>11.2</Version>
|
|
107
|
+
<AuditRecord><Audit_Type>1</Audit_Type>
|
|
108
|
+
</AuditRecord>
|
|
109
|
+
<AuditRecord><Audit_Type>1</Audit_Type></AuditRecord>//Audit_Type以外にも要素はあるが略
|
|
110
|
+
<AuditRecord><Audit_Type>1</Audit_Type></AuditRecord>
|
|
111
|
+
<AuditRecord><Audit_Type>1</Audit_Type></AuditRecord>
|
|
112
|
+
<AuditRecord><Audit_Type>1</Audit_Type></AuditRecord>
|
|
113
|
+
</Audit>
|
|
114
|
+
```
|
1
XML内の処理を詳細化
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -20,8 +20,11 @@
|
|
|
20
20
|
xmlns:xsi="http://~"
|
|
21
21
|
xsi:schemaLocation="http~">
|
|
22
22
|
<Version>11.2</Version>
|
|
23
|
+
<AuditRecord>
|
|
24
|
+
<hoge>1</hoge>//各要素
|
|
25
|
+
<huge>1</huge>//各要素
|
|
26
|
+
</AuditRecord>
|
|
23
|
-
/
|
|
27
|
+
</Audit>
|
|
24
|
-
//略
|
|
25
28
|
```
|
|
26
29
|
|
|
27
30
|
こんな感じでコードを組んで、デバッグをするとReading.Audit model内にはプロパティが格納され、各要素が格納され、値の取得が出来ているのが確認できたのですが、
|