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
https://forums.phpfreaks.com/topic/245137-how-to-join-xml-data-based-on-an-id/
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

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.