我很难解析这个XML。我需要提取任何给定扩展名的IP地址。 XML将按原样发回:
<response method="switchvox.status.phones.getList">
<result>
<sip_phones page_number="1" total_pages="1" items_per_page="50" total_items="29">
<sip_phone id="1113" extension="220" caller_id="A" user_agent="PolycomSoundPointIP-SPIP_330-UA/3.2.6.0314" ip_address="192.168.6.86" state="registered" />
<sip_phone id="1359" extension="204" caller_id="B" user_agent="PolycomSoundPointIP-SPIP_330-UA/3.2.6.0314" ip_address="192.168.6.41" state="registered" />
<sip_phone id="1354" extension="203" caller_id="C" user_agent="PolycomSoundPointIP-SPIP_330-UA/3.3.4.0085" ip_address="173.10.52.177" state="registered" />
</sip_phones>
</result>
</response>
它从API返回并作为XElement进行解析。
Public Function GetInfo() As XElement
Dim xml As XElement = <request method="switchvox.status.phones.getList">
</request>
Const url As String = "https://pbx/xml"
Dim webRequest__1 As HttpWebRequest = DirectCast(WebRequest.Create(url), HttpWebRequest)
webRequest__1.Method = "POST"
webRequest__1.Credentials = New NetworkCredential("user", "pass")
webRequest__1.ContentType = "text/xml"
webRequest__1.ContentLength = xml.ToString().Length
Using requestWriter2 As New StreamWriter(webRequest__1.GetRequestStream())
requestWriter2.Write(xml.ToString())
End Using
Using resp As HttpWebResponse = DirectCast(webRequest__1.GetResponse(), HttpWebResponse)
Using responseStream = resp.GetResponseStream()
Return (XElement.Load(responseStream))
End Using
End Using
End Function