所以我需要做的任務是從 /root/userlist/user 中提取 sn & devid 值,然后根據每個設備的這 2 個值生成一個 url,我已經能夠達到所需的值,但它也是一個創建回圈的問題,以保證 sn 值與 devid 值的同一節點匹配
<ret value="0">
<stwebsvr url="ws://123.123.123:1234/login?user=admin,pwd=admin,type=1"/>
<power value="0"/>
<areaList>
<area name="office" id="1" pid="-1"/>
</areaList>
<userlist>
<user name="000001" personid="000001" areaid="2" videoip="123.123.123.123" videoport="22101" sid="1" devpoint="1" devid="2" sn="R101-00015" type="4" subtype="1">
<point pointid="0" bsid="0" bstype="10" pointName="workStatus"/>
<point pointid="5" bsid="0" bstype="11" pointName="talk"/>
<point pointid="1" bsid="1" bstype="8" pointName="channel1"/>
<point pointid="2" bsid="0" bstype="9" pointName="gps"/>
<point pointid="3" bsid="0" bstype="12" pointName="alarm"/>
<point pointid="6" bsid="0" bstype="13" pointName="callStatus"/>
<point pointid="7" bsid="0" bstype="14" pointName="videoRecordStatus"/>
<point pointid="8" bsid="0" bstype="15" pointName="audioRecordStatus"/>
<point pointid="4" bsid="0" bstype="16" pointName="voiceRecgStatus"/>
<point pointid="9" bsid="0" bstype="17" pointName="closeWindStatus"/>
<point pointid="10" bsid="0" bstype="18" pointName="batteryStatus"/>
<point pointid="11" bsid="0" bstype="19" pointName="powerOffStatus"/>
<point pointid="12" bsid="0" bstype="20" pointName="lowPowerStatus"/>
</user>
<user name="000006" personid="000006" areaid="2" videoip="123.123.123.123" videoport="22101" sid="1" devpoint="1" devid="3" sn="R101-00008" type="4" subtype="1">
<point pointid="0" bsid="0" bstype="10" pointName="workStatus"/>
<point pointid="5" bsid="0" bstype="11" pointName="talk"/>
<point pointid="1" bsid="1" bstype="8" pointName="channel1"/>
<point pointid="2" bsid="0" bstype="9" pointName="gps"/>
<point pointid="3" bsid="0" bstype="12" pointName="alarm"/>
<point pointid="6" bsid="0" bstype="13" pointName="callStatus"/>
<point pointid="7" bsid="0" bstype="14" pointName="videoRecordStatus"/>
<point pointid="8" bsid="0" bstype="15" pointName="audioRecordStatus"/>
<point pointid="4" bsid="0" bstype="16" pointName="voiceRecgStatus"/>
<point pointid="9" bsid="0" bstype="17" pointName="closeWindStatus"/>
<point pointid="10" bsid="0" bstype="18" pointName="batteryStatus"/>
<point pointid="11" bsid="0" bstype="19" pointName="powerOffStatus"/>
<point pointid="12" bsid="0" bstype="20" pointName="lowPowerStatus"/>
</user>
到目前為止我能做的
[xml]$van = Get-Content "C:\Users\Desktop\cam.xml"
$camers = @(Select-Xml -Path C:\Users\Desktop\cam.xml -XPath "//user")
$users = $van.ret.userlist
$CamID = $van.ret.userlist.user.sn
$DevID = $van.ret.userlist.user.devid
foreach ($camer in $camers)
{
write-host $user
$url = "BWC Name: " $CamID " " "rtsp://admin:[email protected]:22222/1_" $DevID "_1"
write-host $url
}
uj5u.com熱心網友回復:
嘗試 Xml Linq:
using assembly System.Xml
using assembly System.Xml.Linq
$inputFilename = "c:\temp\test.xml"
$table = [System.Collections.ArrayList]::new()
$xDoc = [System.Xml.Linq.XDocument]::Load($inputFilename)
$users = $xDoc.Descendants("user").Foreach([System.Xml.Linq.XElement])
foreach($user in $users)
{
$newRow = New-Object -TypeName psobject
$name = $user.Attribute("name").Value
$newRow | Add-Member -NotePropertyName name -NotePropertyValue $name
$devid = $user.Attribute("devid").Value
$newRow | Add-Member -NotePropertyName devid -NotePropertyValue $devid
$sid = $user.Attribute("sid").Value
$newRow | Add-Member -NotePropertyName sid -NotePropertyValue $sid
$table.Add($newRow) | out-Null
}
$table | Format-Table
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/529125.html
標籤:xml电源外壳
