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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:08:22+00:00 2026-05-31T14:08:22+00:00

I wonder whether someone can help me please. I have the following xml file

  • 0

I wonder whether someone can help me please.

I have the following xml file which I need to pull the values from two of the file attributes, to be more precise, ‘userid’ and ‘locationid’ for each ‘file name’. Ultimately these values will be used to determine which folders and files the user will be presented with on page load.

 <?xml version="1.0" encoding="utf-8" ?> 
- <files>
  <file name="Test 1/Test Pic 2.jpg" source="Test_Pic_2.jpg" size="728573" originalname="Test Pic 2.jpg" thumbnail="Test_Pic_2.jpg" userid="1" locationid="1" description="No description provided" folder="Test_1" /> 
  <file name="Test 1/stags-snow_1544533c.jpg" source="stags-snow_1544533c.jpg" size="21341" originalname="stags-snow_1544533c.jpg" thumbnail="stags-snow_1544533c.jpg" userid="1" locationid="1" description="Deer head." folder="Test_1" /> 
        </files>

I must admit not not knowing a great deal about how to get this information, but after some searching I found a tutorial online, which I’ve adapted and have added below.

<?php 

    if( ! $xml = simplexml_load_file('UploadedFiles/files.xml') ) 
    { 
        echo 'unable to load XML file'; 
    } 
    else 
    { 
        foreach( $xml as $files ) 
        { 
            echo 'userid: '.$file_name->userid.'<br />'; 
            echo 'locationid: '.$file_name->locationid.'<br />'; 
        } 
    } 

?> 

The problem I’m having is that when I run this, I just get the following results:

userid:
locationid:
userid:
locationid:
userid:
locationid:

The number of rows corresponds with the number of records but what I was wanting to get is the value of the field as well.

I just wondered whether someone could perhaps take a look at this and let me know where I’m going wrong.

Many thanks

  • 1 1 Answer
  • 1 View
  • 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-31T14:08:23+00:00Added an answer on May 31, 2026 at 2:08 pm

    I think you require something like this. (An example found at http://php.net/manual/en/simplexmlelement.attributes.php )

    <?php
    $string = <<<XML
    <a>
     <foo name="one" game="lonely">1</foo>
    </a>
    XML;
    
    $xml = simplexml_load_string($string);
    foreach($xml->foo[0]->attributes() as $a => $b) {
        echo $a,'="',$b,"\"\n";
    }
    ?>
    

    Hope this helps and if not please post back.

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

Sidebar

Related Questions

I wonder whether someone can help me please. I have a mySQL database which
I wonder whether someone can help me please. I've put together the following which
I wonder whether someone can help me please. I have the following three tables:
I wonder whether someone can help me please. I'm using the following script to
wonder whether someone can help me with the following one... I have a struct
I wonder whether someone can help me please. I've created this form which allows
I wonder whether someone can help me please. I've put together this page, which
I wonder whether someone can help me please. I've put together this page which
I wonder whether someone can help me please. I'm using the following script to
I wonder whether someone could help me please. I'm using Image Uploader from Aurigma,

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.