Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6626013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:50:36+00:00 2026-05-25T21:50:36+00:00

$xml = ‘<?xml version=1.0?> <entries> <response> <category>client</category> <action>Greeting</action> <code>1000</code> <msg>Your Connection with API Server

  • 0
$xml = '<?xml version="1.0"?>
<entries>
    <response>
        <category>client</category>
        <action>Greeting</action>
        <code>1000</code> 
        <msg>Your Connection with API Server is Successful</msg> 
        <resData> 
            <data name="svDate">2010-10-10 02:27:14</data> 
        </resData>
    </response>

    <response>
        <category>client</category>
        <action>Login</action>
        <code>1000</code>
        <msg>Command completed successfully</msg>
        <value>L116:no value</value>
    </response>

    <response>
        <category>domain</category>
        <action>InfoDomain</action>
        <code>1000</code>
        <msg>Command completed successfully</msg>
        <value>L125:no value</value>
        <resData>
            <data name="domain">google.com</data>
            <data name="crDate">2004-12-16</data>
            <data name="exDate">2013-12-16</data>
        </resData>
    </response>
</entries>';

$xml = simplexml_load_string($xml);

$domain = $xml->response[2]->resData[0]->data[0];
$crdate = $xml->response[2]->resData[0]->data[1];
$exdate = $xml->response[2]->resData[0]->data[2];

With the above code i can get the values.
But how can i get the values by attribute value?

For example i want to get the values with something like this:

$domain = $xml->response[2]->resData[0]->data["domain"];
$crdate = $xml->response[2]->resData[0]->data["crdate"];
$exdate = $xml->response[2]->resData[0]->data["exdate"];

One more question.

If i have two elements with the same name?
For example i would like to parse the dns. How could i do it?

The xml code is like this:

    <?xml version="1.0"?>
<entries>
    <response>
        <category>client</category>
        <action>Greeting</action>
        <code>1000</code> 
        <msg>Your Connection with API Server is Successful</msg> 
        <resData> 
            <data name="svDate">2010-10-10 02:27:14</data> 
        </resData>
    </response>

    <response>
        <category>client</category>
        <action>Login</action>
        <code>1000</code>
        <msg>Command completed successfully</msg>
        <value>L116:no value</value>
    </response>

    <response>
        <category>domain</category>
        <action>InfoDomain</action>
        <code>1000</code>
        <msg>Command completed successfully</msg>
        <value>L125:no value</value>
        <resData>
            <data name="domain">google.com</data>
            <data name="crDate">2004-12-16</data>
            <data name="exDate">2013-12-16</data>
            <data name="dns">ns1.google.com</data>
          <data name="dns">ns2.google.com</data>
        </resData>
    </response>
</entries>

As you can see the ns1 and ns2 have the same name. name=”dns”.
How can i parse each one in a different variable?

Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T21:50:37+00:00Added an answer on May 25, 2026 at 9:50 pm

    With the element["attribute"] syntax, attribute is the name of an attribute on the element. It is not the value of some randomly chosen attribute belonging to an element.

    The example below creates an array containing a mapping for the data elements of name attribute value to text value.

    $data = array();
    foreach ($xml->response[2]->resData->data as $d) {
        $data[strtolower($d['name'])] = (string) $d;
    }
    
    // Now you can access the values via $data['domain'], $data['crdate'], etc.
    

    Nick, your code expects XML structured like:

    <resData>
        <data domain="google.com" crdate="2004-12-16" exdate="2013-12-16" />
    </resData>
    

    Edit due to question change

    In a marvelous dose of eating my own words, due to the change in the question an XPath approach would be more appropriate (don’t you love OPs who do that?).

    You can easily get an array of the name="dns" elements with a basic XPath expression.

    $xml = simplexml_load_string($xml);
    $dns = $xml->xpath('response[category="domain"]/resData/data[@name="dns"]');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My xml looks like: <kml xmlns=http://earth.google.com/kml/2.0> <Response> <name>90210</name> <Status> <code>200</code> <request>geocode</request> </Status> <Placemark id=p1>
XML : <?xml version=1.0 encoding=UTF-8?> <data> <ac code=B2 auto=1> <fee> <if country=RU>35e 50e 50e
XML: <?xml version=1.0 encoding=UTF-8?> <data> <ac code=JL auto=1> <fee>10e</fee> <comission> <if country=JP>5%</if> <else>7%</else> </comission>
My XML Looks like this: <?xml version=1.0 encoding=utf-8 ?> <projects> <project id=1 thumb=media/images/thumb.jpg >
My xml is like below <rat> <to>tt</to> <from>ggg</from> <heading>hhhhh</heading> <body>jjj</body> </rat> My AS3 code
XML: <Budget> <Table1> <AllocID>1</AllocID> <Amount>1000</Amount> </Table1> <Table1> <AllocID>2</AllocID> <Amount>2000</Amount> </Table1> <Table1> <AllocID>3</AllocID> <Amount>3000</Amount> </Table1>
xml version 1.0 encoding utf-8 in php, I have tried : echo '<?xml version=1.0
Xml response is like , but in one tag , the text is this:
XML element I am accessing: is here, if below sample is unreadable: http://api.petfinder.com/pet.find?&animal=dog&count=150&location=90605&key=a94884c2349b5b6975ec84fb51ac3ec4 <pets>
xml and logcat now added, now custom view code, unfortunately i am away from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.