Jump to content

simpleXML - Search and replace type function...


elm0s

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

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.