php處理復(fù)雜xml數(shù)據(jù)示例
本文實(shí)例講述了php處理復(fù)雜xml數(shù)據(jù)的方法。分享給大家供大家參考,具體如下:
<?php
$xml = <<< XML
<?xml version="1.0" encoding="utf-8"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd">
<response>
<result code="1000">
<msg>Command completed successfully</msg>
</result>
<resData>
<domain:chkData xmlns:domain="urn:ietf:params:xml:ns:domain-1.0" xsi:schemaLocation="urn:ietf:params:xml:ns:domain-1.0 domain-1.0.xsd">
<domain:cd>
<domain:name avail="0">qq.com</domain:name>
<domain:reason>Domain exists</domain:reason>
</domain:cd>
<domain:cd>
<domain:name avail="1">baidu.com</domain:name>
<domain:reason>Domain exists</domain:reason>
</domain:cd>
</domain:chkData>
</resData>
<trID>
<clTRID>REQ-001-0000000074</clTRID>
<svTRID>649334436-1440642163169</svTRID>
</trID>
</response>
</epp>
XML;
$x = simplexml_load_string($xml);
echo intval($x->response->result["code"]), "\n";
echo strval($x->response->result->msg), "\n";
$ns = $x->response->resData->getNamespaces(true);
$cds = $x->response->resData->children($ns["domain"])->chkData->cd;
foreach ($cds as $key => $value) {
echo intval($value->name->attributes()["avail"]), strval($value->name), strval($value->reason), "\n";
}
更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《PHP針對(duì)XML文件操作技巧總結(jié)》、《PHP錯(cuò)誤與異常處理方法總結(jié)》、《php字符串(string)用法總結(jié)》、《PHP數(shù)組(Array)操作技巧大全》、《PHP運(yùn)算與運(yùn)算符用法總結(jié)》、《PHP網(wǎng)絡(luò)編程技巧總結(jié)》、《PHP基本語法入門教程》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》
希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。
- PHP實(shí)現(xiàn)動(dòng)態(tài)添加XML中數(shù)據(jù)的方法
- PHP解析xml格式數(shù)據(jù)工具類示例
- PHP操作XML作為數(shù)據(jù)庫的類
- PHP中使用xmlreader讀取xml數(shù)據(jù)示例
- PHP生成和獲取XML格式數(shù)據(jù)的方法
- php操作XML、讀取數(shù)據(jù)和寫入數(shù)據(jù)的實(shí)現(xiàn)代碼
- php中實(shí)現(xiàn)xml與mysql數(shù)據(jù)相互轉(zhuǎn)換的方法
- PHP XML備份Mysql數(shù)據(jù)庫
- php操作xml并將其插入數(shù)據(jù)庫的實(shí)現(xiàn)方法
- PHP XML數(shù)據(jù)解析代碼
- PHP實(shí)現(xiàn)動(dòng)態(tài)刪除XML數(shù)據(jù)的方法示例
相關(guān)文章
php基礎(chǔ)知識(shí):類與對(duì)象(5) static
php基礎(chǔ)知識(shí):類與對(duì)象(5) static...2006-12-12
php getimagesize 上傳圖片的長度和寬度檢測代碼
getimagesize — 取得圖像大小2010-05-05
windows環(huán)境下php配置memcache的具體操作步驟
本篇文章是對(duì)windows環(huán)境下php配置memcache的具體操作步驟進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06
ie與session丟失(新窗口cookie丟失)實(shí)測及解決方案
正如標(biāo)題所言測試結(jié)果為:如果cookie設(shè)置是延后定時(shí)失效,而非進(jìn)程級(jí)的,那在open后也能看到,所以,針對(duì)此情況,防止用戶在使用ie內(nèi)核出現(xiàn)登錄狀態(tài)丟失,可以配合cookie來使用2013-07-07
php 301轉(zhuǎn)向?qū)崿F(xiàn)代碼
php對(duì)全站的所有內(nèi)頁進(jìn)行域名301轉(zhuǎn)向2008-09-09
php使用Header函數(shù),PHP_AUTH_PW和PHP_AUTH_USER做用戶驗(yàn)證
這篇文章主要介紹了php使用Header函數(shù),PHP_AUTH_PW和PHP_AUTH_USER做用戶驗(yàn)證的方法,結(jié)合實(shí)例形式分析了PHP使用Header函數(shù)調(diào)用登錄驗(yàn)證及PHP_AUTH_PW和PHP_AUTH_USER進(jìn)行驗(yàn)證處理的相關(guān)技巧,需要的朋友可以參考下2016-05-05

