Jump to content

How to: Join XML data based on an ID?


FredPenner

Recommended Posts

What is the best approach to merge/join XML data via PHP?

 

File#1:

 

<users>

<user>

    <name>Mark</name>

    <id>100</id>

</user>

<user>

    <name>Fred</name>

    <id>100</id>

</user>

 

</users>

 

File#2:

 

<users>

<user>

    <id>100</id>

    <lat>50</lat>

    <lon>122</lon>

        </user>

</users>

 

Desired output (only keep records where a match is found):

 

<users>

<user>

  <id>100</id>

  <lat>50</lat>

  <lon>122</lon>

      <name>Mark</name>

  </user>

</users>

 

Thanks in advance!

 

M

 

Link to comment
Share on other sites

I have not used much xml and php but simplexml might be what you need.  As it can create an array out of the xml tags and you can use the array to step through the data you need.  But not sure as it looks here you are tryin to compare two xml files and match them up with what is found in each.

 

edit: for got the link http://php.net/manual/en/book.simplexml.php

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.