forked from jeppeter/nsduilib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xmlfunc.vbs
62 lines (53 loc) · 1.42 KB
/
xmlfunc.vbs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
Option Explicit
Function XmlSetValueChilds(parent,xpath,value)
dim nodes,nd
set nodes = parent.selectNodes(xpath)
for each nd in nodes
nd.text = value
Next
End Function
Function XmlFindValueNode(parent,xpath,attrname,regexp)
dim nodes,nd,attrval
set nodes = parent.selectNodes(xpath)
set XmlFindValueNode=Nothing
For Each nd in nodes
attrval = nd.getAttribute(attrname)
if regexp.Test(attrval) Then
set XmlFindValueNode=nd
Exit Function
End If
Next
End Function
Function GetXmlns(xmldom)
dim root,attrname,attrval
set root = xmldom.documentElement
GetXmlns= root.getAttribute("xmlns")
End Function
Function CreateIfNoElement(xmldom,parent,nodename)
dim chlds,nd
For Each nd in parent.childnodes
if nd.nodename = nodename Then
set CreateIfNoElement=nd
Exit Function
End If
Next
set nd=xmldom.createNode(1, nodename,GetXmlns(xmldom))
parent.appendChild(nd)
set CreateIfNoElement=nd
End Function
Function SetPreCompileValue(xmldom,filename,value)
dim fnnode,nd,reg,root
set reg = new regexp
reg.IgnoreCase = true
reg.Pattern = filename &"$"
set root = xmldom.documentElement
set fnnode = XmlFindValueNode(root,"//Project/ItemGroup/ClCompile","Include",reg)
if fnnode is Nothing Then
Wscript.StdErr.WriteLine("can not find (" & filename & ")")
wscript.Quit(3)
Else
set nd=CreateIfNoElement(xmldom,fnnode,"PrecompiledHeader")
nd.text = value
SetPreCompileValue=0
End If
End Function