//--------------------%Rem中的为JS的应用方法————————————————————————————
Sub Initialize
On Error Goto a
Dim session As New NotesSession
Path ="D:\Test.xml"
Dim ObjDom As Variant
Set ObjDom = createObject("msxml2.domdocument")
ObjDom.async = False
ObjDom.resolveExternals = False
Call ObjDom.Setproperty("SelectionLanguage","XPath") '解析Xpath语言,区分大小写
If ObjDom.load(Path) Then
'-------------delNode--------------begin
'找到xml中的第一个WorkList
'Set delNodes =ObjDom.getElementsByTagName("WorkList")(0)
'删除所找到的节点包括其子节点
'delNodes.parentNode.removeChild(delNodes)
%REM
var delNodes = o.getElementsByTagName("WorkList")[0];
delNodes.parentNode.removeChild(delNodes);
%END REM
'-------------delNode--------------end
'-------------inserNode--------------begin
'找到xml中的第一个Phase节点
'Set phaseNode = ObjDom.getElementsByTagName("Phase")(0)
'创建一个WorkList节点
'Set workListNode = ObjDom.createElement("WorkList")
'将创建的WorkList节点加入到Phase节点下
'phaseNode.appendChild(workListNode)
%REM
var phaseNode = o.getElementsByTagName("Phase")[0];
var workListNode = o.createElement("WorkList");
phaseNode.appendChild(workListNode);
%END REM
'-------------inserNode--------------end
'-------------inserChildNode--------------begin
'找到xml中的第一个WorkList节点
'Set workListNode = ObjDom.getElementsByTagName("WorkList")(0)
'创建一个Work节点
'Set workNode = ObjDom.createElement("Work")
'将创建的Work节点加入到WorkList节点下
'workListNode.appendChild(workNode)
'向Work节点中插入值
'workNode.text="工作内容"
%REM
var phaseNode = o.getElementsByTagName("Phase")[0];
var workListNode = o.createElement("WorkList");
phaseNode.appendChild(workListNode);
%END REM
'-------------inserChildNode--------------end
'-------------inserAtt插入属性--------------begin
'找到xml中的第一个Work节点
'Set workNode = ObjDom.getElementsByTagName("Work")(0)
'想work节点添加属性
'Call workNode.setAttribute("属性","属性的值")
%REM
var workNode = o.getElementsByTagName("Work")[0];
workNode.setAttribute("属性","属性的值");
%END REM
'-------------inserAtt插入属性--------------end
Call ObjDom.save(Path)
End If
Exit Sub
a:
Msgbox "错误在代理agent_CreateXml的第" & Erl & "行:" & Error
End Sub
---------------------------------------------------------------XML样例文件------------------------------------------------------------------------------------------------------------
<?xml version='1.0' encoding='GBK' ?><PhaseList><Phase name='A1'><WorkList><Work name='1.1'><WorkName>A1-1.1</WorkName></Work><Work name='1.2'><WorkName>A1-1.2</WorkName></Work></WorkList></Phase><Phase name='B1'><WorkList><Work name='2.1'><WorkName>B1-2.1</WorkName></Work><Work name='2.2'><WorkName>B1-2.2</WorkName></Work></WorkList></Phase></PhaseList>