I have a problem, I need to edit an xml file using php, based on a string variable it has been passed.
i.e., my php has a string variable which takes the value of either “true” or “false” and I need to alter the following xml file code:
<Parameter>
<ParameterName>Method1</ParameterName>
<ParameterDescription>description</ParameterDescription>
<ParameterValue type="bool">false</ParameterValue>
</Parameter>
<Parameter>
<ParameterName>Method2</ParameterName>
<ParameterDescription>description</ParameterDescription>
<ParameterValue type="bool">true</ParameterValue>
</Parameter>
<Parameter>
<ParameterName>Method3</ParameterName>
<ParameterDescription>description</ParameterDescription>
<ParameterValue type="float">0.025</ParameterValue>
</Parameter>
So that the first “ParameterValue” changes from it’s default “false” to whatever the value of the variable is (note that the variable in the php is a string, and in the xml is a boolean type). I have looked at suggestions involving awk, and sen and dom without much luck. I am hoping for the simplest way to change this one word in the XML!
James
You are making things too complicated. XML is just a string (text file) that has some formatiing requirements. Just create the string as any other but bear in mind those formatting rules.
This should do the trick in PHP.
You can then save the string to file (adding the other XML stuff that is required!), print it to STDOUT or load it into DOMDocument for further processing. Your choice.