Jump to content

Help Editing/Updating an XML Document


anarchyEric

Recommended Posts

Hello,

 

I need help figuring out how to do some XML editing with PHP. I'm writing software for an organization that offers recreational programs and I need to format the output into an XML file. The easy part is creating the XML file, as I can do that with the basic file operations in PHP. What I need to do now is edit specific nodes within the file without simply re-writing the whole thing.

 

Here is the example XML (slightly truncated):

 

<program>
     <program_id>4</program_id>
     <name>Some Program</name>
     ...
     <registration_end_date>05/25/2009</registration_end_date>
     <package_list>
          <package>
               <package_id>2</package_id>
               <package_name>T-Shirt</package_name>
          </package>
          <package>
               <package_id>5</package_id>
               <package_name>Food Pass</package_name>
          </package>
     </package_list>
</program>

 

What I'm having trouble doing is editing the <package_list> portion. Packages are added separately from editing the program, so I just want to update the package section whenever they are changed without touching the rest of the XML.

 

I've played around with simpleXML, but I'm still not sure exactly how to get down to just the <package_list> section and only update the packages. I don't mind recreating the <package_list> section by removing all packages and re-adding them every time there is an update, but I want to avoid recreating the entire file.

 

If you need further explanation or clarification, feel free to ask. Thanks in advance.

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.