View Full Version : using a variable for xml node values

04-24-2012, 08:48 PM
I am using simpleXml and I am wondering if it is possible to do something like this with it:

$simpleXmlName = "'".$xmlName."'"; // sets up value for simple xml tag name
$newSimpleXML = new SimpleXMLElement($newValue);

$newSimpleXML->{$simpleXmlName} = $status;
//instead of:
$newSimpleXML->{'node-value'} = $status;

I have tried this as an educated guess, didnt work though and couldnt find anything online about this scenario either.

Any suggestions?

Thanks a lot

04-24-2012, 09:39 PM
you don’t need the quotes. these are only to denote a string ("node-value" may be a valid tag name, but not a valid variable name, hence the quotes), so $newSimpleXML->{$xmlName} should IMO suffice.