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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:29:43+00:00 2026-06-06T09:29:43+00:00

I have loaded an XML file using simplexml_load_file($filePath,’SimpleXMLElement’, LIBXML_NOCDATA); And for most of the

  • 0

I have loaded an XML file using

simplexml_load_file($filePath,'SimpleXMLElement', LIBXML_NOCDATA);

And for most of the XML provided it works fine. However, for some of the elements in the XML the attributes are not converted into an ‘@attributes’ array, and are instead missing form the output. Here’s a sample:

<UI_DEFINITION>
<EDIT_PERMISSION>testPermission</EDIT_PERMISSION>
<DEFAULT_VALUES>
    <display>hidden</display>
    <css_class>generic_css_class</css_class>
    <title>{tag}</title>
    <type>string</type>
    <wrapper_format>{value}</wrapper_format>
    <full_path>false</full_path>
    <mandatory>false</mandatory>
    <edit_permission>testPermission</edit_permission>
    <max_length>0</max_length>
</DEFAULT_VALUES>
<LOOKUPS>
    <DB_LOOKUP name="test3">
        <VIEW>???</VIEW>
        <ID_FIELD>???</ID_FIELD>
        <DESCR_FIELD>???</DESCR_FIELD>
        <ORDER>??? asc</ORDER>
    </DB_LOOKUP>
    <DB_LOOKUP name="test1">
        <VIEW>???</VIEW>
        <ID_FIELD>???</ID_FIELD>
        <DESCR_FIELD>???</DESCR_FIELD>
        <ORDER>??? asc</ORDER>
    </DB_LOOKUP>
</LOOKUPS>
<AREA internal_name="main_details" title="" display="show">
    <FIELD lookup="test1" title="Title">Title</FIELD>
    <FIELD title="Name">Given_Name</FIELD>
    <FIELD title="Mid. Name(s)">Middle_Names</FIELD>
    <FIELD title="Family Name">Family_Name</FIELD>
    <FIELD title="Gender">Gender</FIELD>
    <FIELD title="Born" type="date">Date_of_Birth</FIELD>
    <FIELD max_length="20" title="ID">Unique_Identifier</FIELD>
</AREA>

This gives the following output from print_r (I’ve added a line break at the bit that’s the problem):

SimpleXMLElement Object ( [UI_DEFINITION] => SimpleXMLElement Object ( [EDIT_PERMISSION] => testPermission [DEFAULT_VALUES] => SimpleXMLElement Object ( [display] => hidden [css_class] => generic_css_class [title] => {tag} [type] => string [wrapper_format] => {value} [full_path] => false [mandatory] => false [edit_permission] => testPermission [max_length] => 0 ) [LOOKUPS] => SimpleXMLElement Object ( [DB_LOOKUP] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [name] => test3 ) [VIEW] => ??? [ID_FIELD] => ??? [DESCR_FIELD] => ??? [ORDER] => ??? asc ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [name] => test1 ) [VIEW] => ??? [ID_FIELD] => ??? [DESCR_FIELD] => ??? [ORDER] => ??? asc ) ) ) 
[AREA] => SimpleXMLElement Object ( [@attributes] => Array ( [internal_name] => main_details [title] => [display] => show ) [FIELD] => Array ( [0] => Title [1] => Given_Name [2] => Middle_Names [3] => Family_Name [4] => Gender [5] => Date_of_Birth [6] => Unique_Identifier ) ) ) )

As you can see, the attributes array is correctly added to most of the elements, but not to the FIELD elements. I’ve tried renaming them and it didn’t seem to make a difference.

EDIT:
I should also add that I’ve tried surrounding the FIELD tags with a FIELDS tag, also to no avail.

EDIT:

I’ve simplified the XML hugely, and it still doesn’t return anny attributes:

<UI_DEFINITION>
                            <FIELD lookup="test1" title="Title">Title</FIELD>
                    </UI_DEFINITION>

produces:

SimpleXMLElement Object ( [UI_DEFINITION] => SimpleXMLElement Object ( [FIELD] => Title ) )
  • 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-06T09:29:44+00:00Added an answer on June 6, 2026 at 9:29 am

    Sorry it’s taken so long to come back and answer this question!

    As MrCode suggested, the attributes were accessible. The problem I was in the serialisation of the SimpleXML object into another format. Using printr or json_convert on the while object resulted in the attributes not being available in the cases reported.

    I didn’t go far enough into this to find a code-based workaround for printing or converting these objects including the problematic cases, I simply worked around it as part of the XML data:

    <UI_DEFINITION>
            <FIELD lookup="test1" title="Title"><VALUEPATH>Title</VALUEPATH></FIELD>
     </UI_DEFINITION>
    

    Addint this extra level into the hierarchy resulted in the attributes being preserved at the top level, and the text value being available correctly at the sub-level.

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

Sidebar

Related Questions

I am using MSXML3 and have loaded an xml document which is a HTML
I have a function using $.ajax() to get values from an XML file, when
I have an XML file that is loaded into an XElement. I want to
I have an xml file that is loaded via jquery to populate a jQuery
I have a context loader class which loads an XML file with info on
I have a Spring Web application with an applicationContext.xml loaded through a ContextLoaderListener in
Im using c# .net windows form application. I have loaded names of all the
I have a xml file <text> <defalut>This file has the following features:</defalut> <value> <ul>
I have following piece of code which tries to load an XML file from
I am working on a C# application that involves using XML schema file as

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.