Jump to content

Parse the nested variables in XML using PHP


raaks

Recommended Posts

I have been playing with XML and PHP, I have googled to get the requirement which I am working on but still Im not getting the things the way I wanted.

 

I have got a XML file with nested variables, I need to parse the variables such as user_id, name and store it in an array, so that I need to use them to change the details in another config file.

 

For ex: if the user is logged in, using the user_id, i need to parse the all the data of the particular user from the XML file (where the details of the various users are stored).

 

Until now I could only parse the data and echo all of it but could not find a way to store this parsed information.

 

This is my "test.xml" file:

 

<?xml version="1.0" encoding="ISO-8859-1"?>
<document>
    <user>
        <user_id>0121</user_id>
        <name>Tim</name>
        <file>0121.file</file>
    </user>

    <user>
        <user_id>0178</user_id>
        <name>Henry</name>
        <file>0178.file</file>
    </user>

    <user>
        <user_id>0786</user_id>
        <name>Martin</name>
        <file>0786.file</file>
    </user>

    <user>
        <user_id>1239</user_id>
        <name>Jan</name>
        <file>1239.file</file>
    </user>
</document>

 

Any valuable information would be greatly helpful

 

Thanks Raaks

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.