#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    2
    Rep Power
    0

    Using PHP to grab xml from 2 sources and creating a new modified xml file


    Hello, So I need to build a tool that can take 2 separate xml flies, grab certain tags and its content from 1 xml file and insert it into a certain tag on the other. then create a new xml file from the both of them. Is this possible to do? any help would be very appreciated. Thanks
  2. #2
  3. Come play with me!
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,754
    Rep Power
    9397
    Sure: grab one file, grab the other file, and use whatever logic you need to merge the contents.

    It's a vague question, really. Exactly what kind of merging do you need to do? How about some examples?
  4. #3
  5. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,692
    Rep Power
    6351
    There is no pre-written solution for this nor will we write one for you. You have the basic outline of what you want, now give it a shot and let us know where you get stuck.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    2
    Rep Power
    0
    Code:
    <TASK>
    		<frontmatter></frontmatter>
    		<SUBTASK>
    			<PARA>Test text and stuff like that.</PARA>
    		</SUBTASK>
    		<SUBTASK>
    			<PARA>Test text and stuff like that1.</PARA>
    		</SUBTASK>
    		<SUBTASK>
    			<PARA>Test text and stuff like that2.</PARA>
    		</SUBTASK>
    	</TASK>
    Code:
    <TASK>
    		
    		<SUBTASK>
    			<PARA>New Different Content.</PARA>
    		</SUBTASK>
    		<SUBTASK>
    			<PARA>New Different Content</PARA>
    		</SUBTASK>
    		<SUBTASK>
    			<PARA>New Different Content.</PARA>
    		</SUBTASK>
    	</TASK>
    So here is an example of the two files i have. They contain completly different content. And notice the second file is missing the frontmatter tag. What I need to do is grab the task tags from the second xml and replace the content after the frontmatter tag in the first file. So the result would look like this:

    Code:
    <TASK>
    		<frontmatter></frontmatter>
    		<SUBTASK>
    			<PARA>New Different Content.</PARA>
    		</SUBTASK>
    		<SUBTASK>
    			<PARA>New Different Content</PARA>
    		</SUBTASK>
    		<SUBTASK>
    			<PARA>New Different Content.</PARA>
    		</SUBTASK>
    	</TASK>
    Im not expecting anyone to write this for me, I am still new to php and am looking for ideas on the logic and functions/libraries to use. Thanks so much!
  8. #5
  9. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,925
    Rep Power
    1045
    Hi,

    you need to parse both XML files. Then you select the elements of the second document (with XPath) and insert them into the first one.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".

IMN logo majestic logo threadwatch logo seochat tools logo