XML 怎么排序
<NMenu Version="1.0"><Computer Name="124" MAC="00:0C:76:25:B6:4D" Flag="0050" IP="192.168.0.101" Netmask="255.255.255.0" Gateway="192.168.0.254" BootFile="boot.bin"/>
<Computer Name="002" MAC="50:E5:49:C3:DE:3F" Flag="0000" IP="192.168.0.102" Netmask="255.255.255.0" Gateway="192.168.0.254" BootFile="boot.bin"/>
<Computer Name="001" MAC="50:E5:49:C3:DE:75" Flag="0050" IP="192.168.0.103" Netmask="255.255.255.0" Gateway="192.168.0.254" BootFile="boot.bin"/>
<Computer Name="003" MAC="50:E5:49:C3:DD:20" Flag="0050" IP="192.168.0.104" Netmask="255.255.255.0" Gateway="192.168.0.254" BootFile="boot.bin"/>
<Computer Name="004" MAC="50:E5:49:C1:DE:00" Flag="0050" IP="192.168.0.105" Netmask="255.255.255.0" Gateway="192.168.0.254" BootFile="boot.bin"/>
<Computer Name="005" MAC="50:E5:49:C1:DE:4B" Flag="0050" IP="192.168.0.106" Netmask="255.255.255.0" Gateway="192.168.0.254" BootFile="boot.bin"/>
<Computer Name="006" MAC="50:E5:49:C1:DE:6A" Flag="0051" IP="192.168.0.107" Netmask="255.255.255.0" Gateway="192.168.0.254" BootFile="boot.bin"/>
<Computer Name="007" MAC="50:E5:49:C1:DE:0F" Flag="0050" IP="192.168.0.108" Netmask="255.255.255.0" Gateway="192.168.0.254" BootFile="boot.bin"/>
<Computer Name="008" MAC="50:E5:49:C1:DE:02" Flag="0050" IP="192.168.0.109" Netmask="255.255.255.0" Gateway="192.168.0.254" BootFile="boot.bin"/>怎么按Computer Name 排序!!! udf中无这功能,只能 "取出"后,再排列,再"倒入"... 可以排列不 回复 3# hyl821
"取出">>>"排列">>>>>>"倒入"XML 本帖最后由 绿色风 于 2012-9-2 02:12 编辑
回复 4# 绿色风
大家试的时候,直接 复制下面的,楼主的直接复制会让 xm格式变形,那样会认不到的。检测XML是否正常的方法:存为1.txt后,再右键用ie打开看能否显示。显示为格式正常。。
<NMenu Version="1.0">
<Computer Name="124" MAC="00:0C:76:25:B6:4D" Flag="0050" IP="192.168.0.101" Netmask="255.255.255.0" Gateway="192.168.0.254" BootFile="boot.bin"/>
<Computer Name="002" MAC="50:E5:49:C3:DE:3F" Flag="0000" IP="192.168.0.102" Netmask="255.255.255.0" Gateway="192.168.0.254" BootFile="boot.bin"/>
<Computer Name="001" MAC="50:E5:49:C3:DE:75" Flag="0050" IP="192.168.0.103" Netmask="255.255.255.0" Gateway="192.168.0.254" BootFile="boot.bin"/>
<Computer Name="003" MAC="50:E5:49:C3:DD:20" Flag="0050" IP="192.168.0.104" Netmask="255.255.255.0" Gateway="192.168.0.254" BootFile="boot.bin"/>
<Computer Name="004" MAC="50:E5:49:C1:DE:00" Flag="0050" IP="192.168.0.105" Netmask="255.255.255.0" Gateway="192.168.0.254" BootFile="boot.bin"/>
<Computer Name="005" MAC="50:E5:49:C1:DE:4B" Flag="0050" IP="192.168.0.106" Netmask="255.255.255.0" Gateway="192.168.0.254" BootFile="boot.bin"/>
<Computer Name="006" MAC="50:E5:49:C1:DE:6A" Flag="0051" IP="192.168.0.107" Netmask="255.255.255.0" Gateway="192.168.0.254" BootFile="boot.bin"/>
<Computer Name="007" MAC="50:E5:49:C1:DE:0F" Flag="0050" IP="192.168.0.108" Netmask="255.255.255.0" Gateway="192.168.0.254" BootFile="boot.bin"/>
<Computer Name="008" MAC="50:E5:49:C1:DE:02" Flag="0050" IP="192.168.0.109" Netmask="255.255.255.0" Gateway="192.168.0.254" BootFile="boot.bin"/>
</NMenu>
带详细解说直接的方法我没想到,目前只有这样的方法
#include<_XMLDomWrapper.au3>
#include<array.au3>
_XMLFileOpen("1.xml");打开 xml
$items = _XMLSelectNodes("/NMenu/Computer");获取相同节点的个数$items = 相同节点的数量
;~ MsgBox(0,@error,$items)
Dim $a,$b ;先定义节点的属性与值数组,数组个数可以不限
Dim $var[$items];导出数据的容器 【一步】
For $i = 0 To $items-1
$ad = _XMLGetAllAttribindex("/NMenu/Computer", $a, $b, "", $i);根据节点的item ID获取节点的属性与值 $a $b必须先声明为一个数组(反正我觉得这是个bug来的)
;返回的是个二维数组$ad 属性名与$a值一样,
; $ad 属性名与$b值一样,
$var[$i] = $ad&"|"&$ad&"|"&$ad&"|"&$ad&"|"&$ad&"|"&$ad&"|"&$ad
Next
;~ _ArrayDisplay($ad,"测试显示 节点中属性名")
;~ _ArrayDisplay($var,"效果测试,前")
_arraysort($var);对数据排序 【二步】
;~ _ArrayDisplay($var,"效果测试-后")
_XMLDeleteNode("/NMenu/Computer");删除Computer 节点
For $i = 0 To $items-1 ;【三步 -倒入数据】
$c = StringSplit($var[$i],"|",2)
_XMLCreateChildNodeWAttr("NMenu", "Computer", $a, $c) ;建立带有属性的 item节点
Next
Run(@ProgramFilesDir&"\Internet Explorer\iexplore.exe"&@ScriptDir&"\1.xml") ;用 IE 打开xml
页:
[1]