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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:36:52+00:00 2026-06-17T18:36:52+00:00

I am loading an XML string using simplexml_load_string and if the node doesn’t have

  • 0

I am loading an XML string using simplexml_load_string and if the node doesn’t have any child nodes of it’s own then the attributes of that node don’t seem to be mapped to the array correctly. Is there any way around this? Please see the CUSTOM_PROPERTY sections below:

Suppose I have the following XML:

<WEBSITE NAME="www.example.co.uk">
    <CATEGORY ID="35702" NAME="CatName" FILE_NAME="" LONG_DESC="" SHORT_DESC="">
        <CUSTOM>
            <CUSTOM_PROPERTY NAME="CATTYPE_INDEX">6</CUSTOM_PROPERTY>
            <CUSTOM_PROPERTY NAME="TEMPLATE_ID">0</CUSTOM_PROPERTY>
            <CUSTOM_PROPERTY NAME="DISPLAY_LIMIT">10</CUSTOM_PROPERTY>
            <CUSTOM_PROPERTY NAME="HIDE_ON_MENU">0</CUSTOM_PROPERTY>
            <CUSTOM_PROPERTY NAME="CAT_COLOUR">#01b2a8</CUSTOM_PROPERTY>
        </CUSTOM>
    </CATEGORY>

When I use the following code:

$Xml = simplexml_load_string($Str);
print_r($Xml);

It returns this:

SimpleXMLElement Object
(
    [@attributes] => Array
        (
            [NAME] => www.example.co.uk
        )

    [CATEGORY] => Array
        (
            [0] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [ID] => 35702
                            [NAME] => CatName
                            [FILE_NAME] => 
                            [LONG_DESC] => 
                            [SHORT_DESC] => 
                        )

                    [CUSTOM] => SimpleXMLElement Object
                        (
                            [CUSTOM_PROPERTY] => Array
                                (
                                    [0] => 6
                                    [1] => 0
                                    [2] => 10
                                    [3] => 0
                                    [4] => #01b2a8
                                )

                        )

                )
        )
)

CUSTOM_PROPERTY should have an attribute NAME mapped but it doesn’t.

  • 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-17T18:36:53+00:00Added an answer on June 17, 2026 at 6:36 pm

    Your attributes are there but are not shown by print_r(). Be aware that print_r() is not a reliable way of viewing the entire SimpleXML structure.

    Example:

    Demo

    $obj = simplexml_load_string($xml);
    
    foreach($obj->CATEGORY->CUSTOM->CUSTOM_PROPERTY as $custom_property)
    {
      echo $custom_property->attributes()->NAME . "\n";
    }
    

    Outputs

    CATTYPE_INDEX
    TEMPLATE_ID
    DISPLAY_LIMIT
    HIDE_ON_MENU
    CAT_COLOUR
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have descriptions being displayed within an XML document and then loading it into
I have an XML string which contains Dates formatted dd/MM/yyyy hh:mm:ss. I'm loading this
when loading an xml document and converting to an array using json_decode(json_encode(simplexml_load_string($xml)), 1); All
While loading an XML file in SSIS using an XML source component , i
I'm loading an XML in SQL using OpenXML while declaring the variable the max
I am loading an XML file using jQuery $.get. after loading the content, i
I am loading an XML file then I will display the contents of it
I have a flash file that is loading data from XML file. After I
I have following code for loading image from url in xml parsing endElement method
I have a jqPlot pie chart that I am loading by reading an XML

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.