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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:36:31+00:00 2026-06-13T13:36:31+00:00

XML: <?xml version=1.0 encoding=ISO-8859-1?> <lessons> <lesson level=1 course=2> <name type=Dog category=Animals>Dog name</name> </lesson> </lessons>

  • 0

XML:

<?xml version="1.0" encoding="ISO-8859-1"?>
<lessons>
    <lesson level="1" course="2">
                 <name type="Dog" category="Animals">Dog name</name>
          </lesson>
</lessons>

I want to get the values saved like this:

$type = "Dog";
$category = "Animals";
$name = "dog name";

This is what I’ve done:

    foreach($xml->name as $name){
        $type = $name['type'];
        $category = $name['category'];

        echo "Type: $type Category: $category<br>";
        // AND TO get the text, haven't figuered it out yet.. <name ..="" ..="">text</name>
    }

But it doesn’t work. Don’t get any errors neither any output. Any ideas?

EDIT:
OK. I changed foreach($xml->name as $name)

to foreach($xml->lesson->name as $name)

so I get the values of the attribute. But now I don’t know how to get the value of the children.
I’ve tried this: $xml->lesson->children()

It prints children()

SOLVED: $text = $xml->lesson->children();
echo $text;

PROBLEM WAS: I’m using utf-8 in my other code but didn’t change it.

  • 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-06-13T13:36:32+00:00Added an answer on June 13, 2026 at 1:36 pm

    Edit : this part related to a question typo. If you copied your xml directly from where you were editting it, then part of the problem might be that it is malformed. You have an opening <lessons> but you appear to wrongly try to close it with </lesson>.

    Also, depending on your root node settings, ->name may or may not be a child of the $xml object. Can you post a var_dump() of it and get some clues?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following XML <?xml version=1.0 encoding=ISO-8859-1 ?> - <DEVICEMESSAGES> <VERSION xml=1 checksum=
assuming I got following XML file : <?xml version=1.0 encoding=ISO-8859-1 ?> <MyCarShop> <Car gender=Boy>
Consider the following XML: <?xml version=1.0 encoding=ISO-8859-1?> <CATALOG> <CD> <TITLE>Empire Burlesque</TITLE> <ARTIST>Bob Dylan</ARTIST> <COUNTRY>USA</COUNTRY>
I have an XML file like the following : <?xml version=1.0 encoding=ISO-8859-1 ?> <mylist
I have created a string <?xml version='1.0' encoding='ISO-8859-1'?> <response> <content>Question - aa.Reply the option
Below you will find my xml document: <?xml version=1.0 encoding=ISO-8859-1?> <app> <version>0925</version> <humanVersion>0.9.25</humanVersion> </app>
I tried some simple examples like the following one: <?xml version=1.0 encoding=ISO-8859-1 standalone=no?> <!DOCTYPE
i have following xml file as input .... <?xml version=1.0 encoding=ISO-8859-1?> <T0020 xsi:schemaLocation=http://www.safersys.org/namespaces/T0020V1 T0020V1.xsd
I have an XML file with its encoding set within it: <?xml version=1.0 encoding=ISO-8859-15?>
I have an XML file that looks like <?xml version='1.0' encoding='UTF-8'?> <root> <node name=foo1

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.