关于VB6处理xml的问题~各位爷来看下吧~
我想对xml进行处理对xml中rec节点下
所有节点的x值乘以2
现在我遇到的问题是
同一层级的我可以理解
但是多层的我就不会了
求大家指点下~
程序代码:
<?xml version="1.0" encoding="UTF-8"?> <root> <element folder="activity"> <rec x="0" y="0"> <sprite x="1,2"/> <sprite x="20"/> <sprite key="allActivity" t="rec" x="30"> <sprite key="ever1" n="everyActivity" t="rec" x="2,4,6,8"> <sprite key="boxty" n="boxty" x="3"/> <sprite key="iconActivity" n="iconActivity" statelist="0,1,2,3" t="si" x="3"/> <sprite key="culeMC" n="cube64" t="cmc" fps="24" x="3"/> <sprite key="shbei" n="shbei" x="3"/> </sprite> <sprite key="ever2" n="boxvity" x="2"/> </sprite> <sprite key="hehe" n="hehe" statelist="0,1,2,3" x="15" /> </rec> </element> </root>
这是需要处理的xml
我希望涉及到x的地方,无论层级有多深~ 都将x的值乘以2.
如果x有多个值以“,”隔开的话,也要乘以2~~~~~
下面是我的一些代码,
太不完善了
无法达到我的效果
求大神拯救阿...
程序代码:
[color=#0000FF]PrivateSub Command1_Click() Dim Dom As New DOMDocument Dom.async = False Dim x As IXMLDOMNode Dim node As IXMLDOMNode Dim arr Dim brr '加载xml Add = "E:\ts.xml" Dom.Load Add Set node = Dom.selectSingleNode("root").selectSingleNode("element").selectSingleNode("rec") For Each x In node.childNodes '获取限定值 xvalue = x.Attributes.getNamedItem("x").Text '判断如果x存在多个值,将值x2 If InStr(xvalue, ",") Then arr = Split(xvlaue, ",") For i = LBound(arr) To UBound(arr) brr = arr(i) * 2 x.Attributes.getNamedItem("x").Text = brr(i) Next Else '输出双倍的x '并保存 x.Attributes.getNamedItem("x").Text = xvalue * 2 Dom.save (Add) End If Next Set Dom = Nothing MsgBox "双倍执行完毕" End Sub .
[/color]