質問編集履歴

1

質問を具体化

2017/07/25 11:22

投稿

ykkchak
ykkchak

スコア15

test CHANGED
File without changes
test CHANGED
@@ -1,137 +1,81 @@
1
- 2つのxmlファイルをマージするvbscriptを作成しました。
1
+ 2つのxmlをマージしたいで。以下のPGMを作成しましたがマージできませんご教示願います。
2
2
 
3
- index3.xmlがマージ後になりますが「<channel>」が不要なんですが
4
-
5
- どのように取り除ければよろしいでしょうか
6
-
7
- ⇒Set nodeRoot2 = dom2.getElementsByTagName("item")を指定てしましけどうまくとれませんでした
3
+ myfiletagAに対してC:\にあるファイルの特定のタグ(tagB)を移植するPGMを作成したいです。構文的には問題ないよに思いすが「appendChild」がうまいきません。。。
8
4
 
9
5
 
10
6
 
7
+ Sub Loadfile(myfile)
8
+
9
+ 'tag追加
10
+
11
+ dim fso
12
+
11
- それとフォルダ内に複数のxmlが存在しているときにファイル数分マージする方法がありましたらご教示願います。今は2ファイル・固定でしかできていないです。
13
+ set fso = createObject("Scripting.FileSystemObject")
12
14
 
13
15
 
14
16
 
15
- ■xml_add.vbs
17
+ dim folder
16
18
 
17
- ' DOM Object 作成
18
-
19
- Set dom1 = Wscript.CreateObject("Msxml2.DOMDocument")
19
+ set folder = fso.getFolder("C:\")
20
20
 
21
21
 
22
22
 
23
- ' 既存 XML 入力
23
+ ' DOM Object 作成
24
24
 
25
- dom1.load( "index.xml" )
25
+ Set dom1 = Wscript.CreateObject("Msxml2.DOMDocument")
26
26
 
27
27
 
28
28
 
29
+ ' 既存 XML 入力
30
+
29
- Set nodeRoot1 = dom1.documentElement
31
+ dom1.load( myfile )
32
+
33
+ Wscript.Echo myfile
30
34
 
31
35
 
32
36
 
33
- ' DOM Object 作成
37
+ Dim nodeList
34
38
 
35
- Set dom2 = Wscript.CreateObject("Msxml2.DOMDocument")
39
+ Set nodeList = dom1.getElementsByTagName("tagA")
36
40
 
37
41
 
38
42
 
39
- ' 既存 XML 入力
43
+ dim file
40
44
 
45
+ dim i
46
+
47
+ i=0
48
+
49
+ for each file in folder.files
50
+
51
+ ' DOM Object 作成
52
+
53
+ Set dom2 = Wscript.CreateObject("Msxml2.DOMDocument")
54
+
55
+
56
+
57
+ ' XML Load
58
+
41
- dom2.load( "index2.xml" )
59
+ dom2.load( file.name )
42
60
 
43
61
 
44
62
 
45
- Set nodeRoot2 = dom2.documentElement
63
+ '対象Node
46
64
 
47
- 'マージ
48
-
49
- nodeRoot1.appendChild( nodeRoot2 )
65
+ Set nodeRoot2 = dom2.getElementsByTagName("tagB").Item(0)
50
66
 
51
67
 
52
68
 
53
- ' 保存
69
+ 'マージ
54
70
 
55
- dom1.save( "index3.xml" )
71
+ nodeList(0).appendChild( nodeRoot2 )
56
72
 
57
73
 
58
74
 
59
- index.xml
75
+ i = i + 1
60
76
 
61
- <?xml version="1.0" encoding="UTF-8"?>
62
-
63
- <channel>
64
-
65
- <item>
77
+ next
66
-
67
- <title>タイトル</title>
68
-
69
- <link>対象URL</link>
70
-
71
- <description>内容の説明</description>
72
-
73
- <date>2011-12-14</date>
74
-
75
- </item>
76
-
77
- </channel>
78
78
 
79
79
 
80
80
 
81
- ■index2.xml
81
+ End Sub
82
-
83
- <?xml version="1.0" encoding="UTF-8"?>
84
-
85
- <channel>
86
-
87
- <item>
88
-
89
- <title>★title★</title>
90
-
91
- <link>対象URL</link>
92
-
93
- <description>内容の説明</description>
94
-
95
- <date>2011-12-14</date>
96
-
97
- </item>
98
-
99
- </channel>
100
-
101
-
102
-
103
- ■index3.xml
104
-
105
- <?xml version="1.0" encoding="UTF-8"?>
106
-
107
- <channel>
108
-
109
- <item>
110
-
111
- <title>タイトル</title>
112
-
113
- <link>対象URL</link>
114
-
115
- <description>内容の説明</description>
116
-
117
- <date>2011-12-14</date>
118
-
119
- </item>
120
-
121
- <channel>
122
-
123
- <item>
124
-
125
- <title>★title★</title>
126
-
127
- <link>対象URL</link>
128
-
129
- <description>内容の説明</description>
130
-
131
- <date>2011-12-14</date>
132
-
133
- </item>
134
-
135
- </channel>
136
-
137
- </channel>