1

好的,我确实对这个 XML / php 脚本有一些问题

我有以下要通过 http 加载的 xml

<WowzaMediaServer>
<ConnectionsCurrent>3</ConnectionsCurrent>
<ConnectionsTotal>26</ConnectionsTotal>
<ConnectionsTotalAccepted>20</ConnectionsTotalAccepted>
<ConnectionsTotalRejected>6</ConnectionsTotalRejected>
<MessagesInBytesRate>3248.0</MessagesInBytesRate>
<MessagesOutBytesRate>1054.0</MessagesOutBytesRate>
<VHost>
<Name>_defaultVHost_</Name>
<TimeRunning>28752.989</TimeRunning>
<ConnectionsLimit>0</ConnectionsLimit>
<ConnectionsCurrent>3</ConnectionsCurrent>
<ConnectionsTotal>26</ConnectionsTotal>
<ConnectionsTotalAccepted>20</ConnectionsTotalAccepted>
<ConnectionsTotalRejected>6</ConnectionsTotalRejected>
<MessagesInBytesRate>3248.0</MessagesInBytesRate>
<MessagesOutBytesRate>1054.0</MessagesOutBytesRate>
<Application>
<Name>zahlio</Name>
<Status>loaded</Status>
<TimeRunning>3339.479</TimeRunning>
<ConnectionsCurrent>3</ConnectionsCurrent>
<ConnectionsTotal>14</ConnectionsTotal>
<ConnectionsTotalAccepted>14</ConnectionsTotalAccepted>
<ConnectionsTotalRejected>0</ConnectionsTotalRejected>
<MessagesInBytesRate>31595.0</MessagesInBytesRate>
<MessagesOutBytesRate>32045.0</MessagesOutBytesRate>
<ApplicationInstance>
<Name>_definst_</Name>
<TimeRunning>3339.478</TimeRunning>
<ConnectionsCurrent>3</ConnectionsCurrent>
<ConnectionsTotal>14</ConnectionsTotal>
<ConnectionsTotalAccepted>14</ConnectionsTotalAccepted>
<ConnectionsTotalRejected>0</ConnectionsTotalRejected>
<MessagesInBytesRate>31594.0</MessagesInBytesRate>
<MessagesOutBytesRate>32045.0</MessagesOutBytesRate>
<Stream>
<Name>zahlio</Name>
<SessionsFlash>2</SessionsFlash>
<SessionsCupertino>0</SessionsCupertino>
<SessionsSanJose>0</SessionsSanJose>
<SessionsSmooth>0</SessionsSmooth>
<SessionsRTSP>0</SessionsRTSP>
<SessionsTotal>2</SessionsTotal>
</Stream>
</ApplicationInstance>
</Application>
</VHost>
</WowzaMediaServer>

我要加载的数据是<SessionsFlash>来自2<stream>x 为名称且 x 为变量的数据,在本例中为 zahlio。

我使用这个http加载它:http://username:pwd@mydomian.com:8086/connectioncounts

这是我当前的 php 脚本:

$sxe = new SimpleXMLElement('http://username:pwd@mydomian.com:8086/connectioncounts');
    $propNode = $sxe->xpath('/WowzaMediaServer/VHost/Application/ApplicationInstance/Stream');
    $count = $propNode->getChildren("SessionsFlash");

它不起作用,我不知道如何从名为 x 的孩子那里选择 trh 数据

4

2 回答 2

0

如果我理解正确,您正试图从您发布的 XML 中提取数据。以下代码从提供的 XML中获取Nameand :SessionsFlash

$dom = new DOMDocument();
@$dom->loadXML($xml);
$xpath = new DOMXPath($dom);
$search_name = 'zahlio';
$items = $xpath->query('/WowzaMediaServer/VHost/Application[Name="' . $search_name . '"]/ApplicationInstance/Stream[Name="' . $search_name . '"]');
for ($i = 0; $i < $items->length; $i++)
{
    $temp = $xpath->query('SessionsFlash', $items->item($i));
    $SessionsFlash = $temp->item(0)->nodeValue;
    echo $SessionsFlash;
}

您的服务器正在使用Digest身份验证,您的浏览器会自动处理它,PHP 需要一些帮助。这是有效的代码:

$ch = curl_init('http://user:pwd@website.net:8086/connectioncounts');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
$xml = curl_exec($ch);
于 2013-02-09T20:57:07.450 回答
0

我也为 Wowza 媒体服务器构建脚本。这就是我在 php 中读取 XML 的方式,也许它可以帮助

        $dom=new DOMDocument;
        $dom->preserveWhiteSpace = false;
        $dom->load('/home/vichea/wowza_visitor/wowza_serverinfo.xml');
        $date=date("d/m/Y");
        $date_file=date('mY');

        $dataset0=$dom->getElementsByTagName("VHost");
        foreach($dataset0 as $row){
            $xmlC=$row->getElementsByTagName("ConnectionsTotal");
            $xmlConn=$xmlC->item(0)->nodeValue;

            $st[]=$xmlConn;
        }
于 2013-11-20T07:30:40.883 回答