We help IT Professionals succeed at work.
Get Started

Simple Parsing XML with PHP

Fezi asked
Last Modified: 2012-05-12
Hi Experts,

I need help with something that I am working on. I have an XML file, and I am trying to return the results into HTML format, using PHP (SimpleXML). Below is some of my code to show you what I am doing.

I want to get the Attributes under the <PageMap> and<DataObject> tag, how do I get to show the attributes from the PageMap > DataObject ?

All help appreciated.


Faraz Shafiq

<R N="6">
    <T>5g Klebfix Super Glue, 7811. test</T>
    <S>Wurth, Dated: June 14 2011, Reg: CHIP.</S>
        <DataObject type="document">
            <Attribute name="title">5g Klebfix Super Glue, 7811</Attribute>
            <Attribute name="author">Fezi</Attribute>
            <Attribute name="description">des - Wurth, Dated: June 14 2011, Reg: CHIP</Attribute>
        <C CID="MXP-AH12OxUJ" SZ="2k"/>


function writeSearchResults($xml) {
        if(empty($xml->RES->R)) {
            return false;

        foreach ($xml->RES->R as $key) {
            $output .= '<p class="wrapper"></p>';
            $output .= '<p class="iconwrapper"><a href=""><img src="sds_icon.png" alt="view" /></a><br/><a href=""><img src="add_icon.png" alt="add" /></a></p>';
            $output .= '<p class="search-result"><a href="'.$key->U.'">'.$key->T.'</a><br/>';
            $output .= $key->S.'<br />';
            //$output .= '<span>'.$key->U.'</span></p>';
            $output .= '</p>';

        echo $output;
        return true;

Open in new window

Watch Question
Most Valuable Expert 2011
Author of the Year 2014
This problem has been solved!
Unlock 1 Answer and 16 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE