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 7704943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:47:29+00:00 2026-05-31T23:47:29+00:00

there is a xml document that i’m parsing to array.. how can i access

  • 0

there is a xml document that i’m parsing to array..
how can i access those array objects and save them in new variables..?
this is piece of php code that is parsing

$contents = file_get_contents('test.xml');
$xml = simplexml_load_string($contents);
print_r($xml);

here is the xml that is being parsed

<?xml version='1.0'?>
<document>
<txtmsg>
    <smstel>1234567</smstel>
    <smstxt></smstxt>
    <smsdir>Send</smsdir>
    <smstime>06/01/2010 7:54:48 am</smstime>
</txtmsg>
<txtmsg>
    <smstel>33333333</smstel>
    <smstxt>Test sms hhTes12222222</smstxt>
    <smsdir>Send</smsdir>
    <smstime>06/01/2010 7:54:48 am</smstime>
</txtmsg>

<Contacts>
    <conttime>06/01/2010 8:19:05 am</conttime>
        <cnt>
            <fn>Abc</fn>
            <ln>Def</ln>
            <cnttel>123456</cnttel>
            <cntmtel>3333333</cntmtel>
            <cntemail>abc@hotmail.com</cntemail>
        </cnt>
        <cnt>
            <fn>def</fn>
            <ln>ghi</ln>
            <cnttel>234234</cnttel>
            <cntmtel>2424</cntmtel>
            <cntemail>df@hotmail.com</cntemail>
        </cnt>
</Contacts>
</document>

and this is output.

SimpleXMLElement Object ( [txtmsg] => Array ( [0] => SimpleXMLElement Object ( [smstel] => 1234567 [smstxt] => SimpleXMLElement Object ( ) [smsdir] => Send [smstime] => 06/01/2010 7:54:48 am ) [1] => SimpleXMLElement Object ( [smstel] => 33333333 [smstxt] => Test sms hhTes12222222 [smsdir] => Send [smstime] => 06/01/2010 7:54:48 am ) ) [Contacts] => SimpleXMLElement Object ( [conttime] => 06/01/2010 8:19:05 am [cnt] => Array ( [0] => SimpleXMLElement Object ( [fn] => Abc [ln] => Def [cnttel] => 123456 [cntmtel] => 3333333 [cntemail] => abc@hotmail.com ) [1] => SimpleXMLElement Object ( [fn] => def [ln] => ghi [cnttel] => 234234 [cntmtel] => 2424 [cntemail] => df@hotmail.com ) ) ) ) 

how can i access each element of xml individually.. like smstel,smstxt,smsdir etc

  • 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-31T23:47:30+00:00Added an answer on May 31, 2026 at 11:47 pm

    this is the best way you can do that..

    foreach($xml->txtmsg as $txtmsg) {
      echo $txtmsg->smstel;
      // more elements...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anybody suggest how can I solve this, there is XML document that I'm
Are there any Code Generators that would take a well-formed XML document, and write
Assume there exists an XML instance document that looks like this: <root> <object type=foo>
I have an XML document that has several <item> elements. Inside each, there might
I have an XML document that I am parsing that does not follow any
There seem to be many options to create an XML document in .NET. What's
Is there anyway to change the content-type of an XML document, in the XML
Is there a free XML formatting (indent) tool available where I can past an
I've got an xml document that filled with people (parent node is students, and
I have written a xml/php document that is pulling from a Magento Commerce database,

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.