Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    May 2008
    Posts
    446
    Thanks
    23
    Thanked 5 Times in 5 Posts

    using a variable for xml node values

    I am using simpleXml and I am wondering if it is possible to do something like this with it:

    PHP Code:
    $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

  • #2
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,473
    Thanks
    13
    Thanked 361 Times in 357 Posts
    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.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •