Jump to content

simpleXML - Search and replace type function...


Recommended Posts

hey, I'm trying to do a search and replace type function using simpleXML. How would I go about this?

I have a php file that catches values from an html form and puts them into variables like this...
[code]
$buildingName = $_POST["buildingName"]; //value is the Building Name
$buildingStatus = $_POST["buildingStatus"]; //value either 1,2,3, or 4
$elevator = $_POST["elevator"]; //value is either true or false
$electricity = $_POST["electricity"]; //value is either true or false
$gas = $_POST["gas"]; //value is either true or false
$hazMat = $_POST["hazmat"]; //value is either true or false
$hvac = $_POST["hvac"]; //value is either true or false
$sewer = $_POST["sewer"]; //value is either true or false
$water = $_POST["water"]; //value is either true or false
$lan = $_POST["lan"]; //value is either true or false
$phone = $_POST["phone"]; //value is either true or false
[/code]

The whole purpose of these variables is to update the values of this xml file..

I have an xml file with the following kind of structure...
[code]
<building status="1" name="Kell Hall">
<problem elevator="false" electricity="false" gas="false" haz_mat="false" hv_ac="false" sewer="false" water="false" lan="false" phone="false">
<comment>This is a comment</comment>
</problem>
</building>

<building status="1" name="Sparks Hall">
<problem elevator="false" electricity="false" gas="false" haz_mat="false" hv_ac="false" sewer="false" water="false" lan="false" phone="false">
<comment>This is a comment</comment>
</problem>
... etc
[/code]

ok so with the values that I've recieved from the html form, I want to search through the xml file, find the matching building node section, and replace those values with the updated ones from the html form.

Could someone help me create some kinda of function that does this type of thing?


[b]$buildingName ="kell hall";[/b]

<building status="1" [b]name="kell hall"[/b]>...

the [b]$buildingName[/b] is the same value as the attribute "[b]name[/b]" of the building node so I thought I could just try and match them up or something?

EDIT: i found something and got it to work....
  • 6 months later...
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.