php xml 摘抄

來源:互聯網
上載者:User
        

any html code here

my name is so so value2 value3 value4 Test value value1 value2 value4 EOT;$dom = new DomDocument;$dom->preserveWhiteSpace = FALSE;$dom->loadXML($xml);$params = $dom->getElementsByTagName('section'); // Find Sections $k=0;foreach ($params as $param) //go to each section 1 by 1 { echo "Section Attribute :-> ".$params->item($k)->getAttribute('name')."
"; //get section attribute $params2 = $params->item($k)->getElementsByTagName('category'); //digg categories with in Section $i=0; // values is used to iterate categories foreach ($params2 as $p) { echo " - Category Attribute Name :-> ".$params2->item($i)->getAttribute('name')."
"; //get Category attributes $params3 = $params2->item($i)->getElementsByTagName('arti'); //dig Arti into Categories $j=0;//values used to interate Arti foreach ($params3 as $p2) { echo " - Article Attribute Name : ".$params3->item($j)->getAttribute('name').""; //get arti atributesecho " Value : ".$params3->item($j)->nodeValue."
"; //get Node value ; $j++; } $i++; }$k++; }?>output : Section Attribute :-> Section1 - Category Attribute Name :-> google - Article Attribute Name : article1 Value : any html code heremy name is so so - Article Attribute Name : article2 Value : value2 - Article Attribute Name : article3 Value : value3 - Article Attribute Name : article4 Value : value4 - Category Attribute Name :-> yahoo - Article Attribute Name : articleSection2 Value : Test valueSection Attribute :-> Section2 - Category Attribute Name :-> msn - Article Attribute Name : article2 Value : value1 - Article Attribute Name : article3 Value : value2 - Category Attribute Name :-> webcare - Article Attribute Name : param3 Value : value4


摘抄:php.net

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.