PHP XML excerpt

Source: Internet
Author: User

Any HTML code here

My name is so value2 value3 value4 Test value value 1 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 of the sections 1 by 1 {echo ' section Attribute:-> '. $ Params->item ($k)->getattribute (' name '). "
"; Get section attribute $params 2 = $params->item ($k)->getelementsbytagname (' category '); Digg categories with $i = 0; Values are used to iterate categories foreach ($params 2 as $p) {echo "-Category Attribute Name:- > ". $params 2->item ($i)->getattribute (' name ')."
"; Get Category attributes $params 3 = $params 2->item ($i)->getelementsbytagname (' Arti '); Dig Arti into Categories $j =0;//values used to Interate Arti foreach ($params 3 as $p 2) {echo "-article Attribute Name:". $params 3->item ($j)->getattribute (' NA Me '). ""; Get Arti Atributesecho "Value:". $params 3->item ($j)->nodevalue. "
"; Get Node value; $j + +; } $i + +; } $k + +; }?>output:section Attribute:-> section1-category Attribute Name:-> google-article Attribute N Ame:article1 value:any HTML code heremy name is so so-article Attribute name:article2 Value:value 2-article Attribute name:article3 value:value3-article Attribute name:article4 Value: Value4-category Attribute Name:-> yahoo-article Attribute name:articlesection2 value:test Value Section Attribute:-> section2-category Attribute Name:-> msn-article Attribute name:article2 V Alue:value1-article Attribute name:article3 value:value2-category Attribute Name:-> webcare -Article Attribute name:param3 value:value4


  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

    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.