Xml Parse in php

Hi I am trying to make code for parse xml in php but didn’t get solution or might be i am wrong somewhere

$url="";
$dom=simplexml_load_file($url);
$dom->Metadata->@attribute->keywords // we need output New Car Loan New

SimpleXMLElement Object
(
    [MetaData] => SimpleXMLElement Object
        (
            [@attributes] => Array
                (
                    [keywords] => New Car Loan New
                )

            [Market] => in
            [CategoryRating] => clean
            [Label] => Yes
        )

    [PageStatus] => SimpleXMLElement Object
        (
            [StatusItem] => OK
        )

    [ResultSet] => Array
        (
            [0] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [id] => adListings
                            [numResults] => 3
                        )

                    [Listing] => Array
                        (
                            [0] => SimpleXMLElement Object
                                (
                                    [@attributes] => Array
                                        (
                                            [rank] => 1
                                            [title] => Buying a new car?
                                            [description] => Invest with Principal MF kyonki apne dad ki maruti kab tak chaloge
                                            [siteHost] => www.principalindia.com
                                            [biddedListing] => true
                                        )

                                    [ClickUrl] => http://0.r.msn.com/?ld=DvX_oqthqPCPYaraY0mBzOYzVUCUxVW1UeJRbKtha6zY0gA59KPpZZcQv0Zc0u0WmcHXAqU0uYrQ-CTdzipnYsvM3mGlXNUt_4DjcdCmZ-fc8bLQ0dTKcyrImSVVxPgT_Lm-gFjA&u=principalindia.orionadeas.com%2fpmf-IEbolly%2fvisit.asp%3fIE-Bolly_car_yahoo-bing_text_ad
                                )

                            [1] => SimpleXMLElement Object
                                (
                                    [@attributes] => Array
                                        (
                                            [rank] => 2
                                            [title] => Car Loan Calculator
                                            [description] => Calculate Your Monthly Car Loan Payment w/ Free Car Loan Calculator
                                            [siteHost] => CarCalculator.Bankrate.com
                                            [biddedListing] => true
                                        )

                                    [ClickUrl] => http://11372.r.msn.com/?ld=Dv5wS7MX7KTUpIO4Ld6a7xpjVUCUzZSCBVc7n1kAMyrCmSdPWYcbAwRbmZ1mVeszjKoc1ch9KzCxet5xv9k5HWCQeZmpLhNizyo3v3mN2DoJfVktX8_jPx3tidYGml00XbKTC7Gw&u=http%3a%2f%2fpixel.everesttech.net%2f1325%2fcq%3fev_sid%3d10%26ev_ltx%3d%26ev_lx%3d20581378696%26ev_crx%3d4263677231%26ev_mt%3dp%26ev_dvc%3dc%26url%3dhttp%253A%2f%2fwww.bankrate.com%2fcalculators%2findex-of-auto-calculators.aspx%253Fpid%253Dp%3asem_bs%2526ec_id%253Dm1176606%2526s_kwcid%253DAL%25211325%252110%25214263677231%252120581378696
                                )

                            [2] => SimpleXMLElement Object
                                (
                                    [@attributes] => Array
                                        (
                                            [rank] => 3
                                            [title] => Looking to Buy a New Car?
                                            [description] => OLX.in Sab kuch bikta hain. 100% FREE Classified. Post Your Ad
                                            [siteHost] => www.OLX.in/Cars
                                            [biddedListing] => true
                                        )

                                    [ClickUrl] => http://1348940.r.msn.com/?ld=DvGAMOap4YGw-rpEjRLeTMDDVUCUxvLI3yeYRoUO4StfJm-cLP74OC3sJGuLV-kLUTYA2Yo9ttcjCqgujqjiBGtMum5GkgQ-JuENgP7gnfkz5eY6mOhBfSaAaecyT8vZfFBS_W4A&u=www.olx.in%2fcars-cat-378%3finvite%3dysm-in_Search_New_Cars_Oct13%26utm_source%3dYSM%26utm_medium%3dCPC%26utm_content%3dSearch_New_Cars_Oct13%26utm_campaign%3dYSM_Search_OLX_Cars
                                )

                        )

                )

            [1] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [id] => searchBox
                            [queryParams] => qs=06oENya4ZG1YS6vOLJwpLiFdjG91IC5fjJvO7uny1mKMONfD6NBfD7_Nc1hQlYP0RdFkPDXePNHCEQkEuEq_Fy6u1xuEO8NR4PQBX00f3-RkiHCW4F9IB_y5nKk_2uEROgSm9uWoplOYRS8OoTNkFJyHey2SqqhbOu_7Jxwf0FpS7v6yYyu6WtWNm76mHqtwb2YtA5vfsDUcFnLvWrwDjRlpB5icwbFDTiPIsIxs1mDuFacViNYZI5HCBgG5_FYBwxkPaNO4olaNROjK6TNMWkV2599PodCwrNedHqwwZQDf9CNWOR3BonrR6sFGr7GeOJNQY.,YT0zO2s9NTtoPTM0NTUyYjViNmY5NjNkZWQ.
                            [numResults] => 0
                        )

                )

        )

    [NextArgs] => qs=06oENya4ZGM2qEjAyqVAwH9kTIhmx0scq8mtrUZw1fiD9lYwAMyvDH_G0LRXOodvNK0DeZwnzpVAdrtI1S0tCOAmYRb6hF1Zva5jjqiYb4cQCYF1zeE8IGTnPsxobRLRShAsdKzOASDhzPHEmHBb5870FxGf5CWEiVIHr_fTu4MtYgrgfw6UKYNI-_0GJFM03E2RE3sL01DDgZi2e_d9sOtPVXKImFpAUnN-7A3nfJnMBVsaVZO3yefk-reMDzFHM5NltK0e92utiXHZINw5UThyvjogHgsBkH9SuQ04gqXzJcYWhatCskUb-PtGgI5Wvudfaac8E-0aMKLFGuIG_CIGu87mifjQnCwYbcbVrQNrNdEs4zuDMSfCHW1uRxFlqJwzmbD8YNdjsHPxecSfNZmGEWTSAL297olKIGaUtCkQr2EgW45kWowdTQbq5MukSxaY5CXT1D8LUgC4gTOcb28xGMs9LRn0YJr9MfGpifOKXsRh9cJrEspJr8BkKpqbowk5-9BV3M5ZEaQIsOVrcEGEKJqF1MFtOYCC4m4UzlQzn1Tge0vc9pfLpp19DAVHr6gGRL
)

Related posts

Leave a Reply

2 comments

  1. You need to use the method ->attributes() to access them: Example:

    $xml = simplexml_load_file($xml_string);
    // php 5.4 dereference
    $keywords = (string) $xml->MetaData->attributes()['keywords'];