0

is there a way to get the xml value by curly brackets?

For example I want to get the value of test->test_test and want to archieve this with the xml object variable. The path of the value inside the xml object comes from the database.

$xml_path = 'test->test_test';
    
echo $xml_obj->{$xml_path}; 

Also not working:

$xml_path = '{test}->{test_test}';
            
echo $xml_obj->{$xml_path};

Here I got the following error:

Serialization of 'SimpleXMLElement' is not allowed
yfain
  • 509
  • 7
  • 23
  • I think we will need to see at least some sample data to be able to understand whats goin gon here. – RiggsFolly Nov 08 '21 at 11:08
  • to improve your experience on SO please [take the tour](http://stackoverflow.com/tour) and read [how to ask](https://stackoverflow.com/help/how-to-ask), an [On Topic question](https://stackoverflow.com/help/on-topic), then look at the [Question Check list](https://meta.stackoverflow.com/questions/260648/stack-overflow-question-checklist), the [perfect question](http://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/) and how to create a [Minimal, Complete and Verifiable Example](http://stackoverflow.com/help/mcve) – RiggsFolly Nov 08 '21 at 11:08
  • Added a better example. – yfain Nov 08 '21 at 11:18
  • You might have to cast it to a string. Try echo (String) $xml_obj->{$xml_path}; – lukas.j Nov 08 '21 at 11:23
  • Makes no differences, because this is only then for the result. – yfain Nov 08 '21 at 11:44
  • The curly bracket syntax allows you to access _one_ property by its name put inside a variable, but it does not allow you to "jump" multiple `->` in one go. – CBroe Nov 08 '21 at 11:49
  • You probably want a solution similar to https://stackoverflow.com/questions/9628176/using-a-string-path-to-set-nested-array-data, only for objects instead of arrays. – CBroe Nov 08 '21 at 11:50
  • @CBroe Yes, I need to jumpe over multiple -> .. I will look at the solution. Thanks. – yfain Nov 08 '21 at 11:56

0 Answers0