简体   繁体   中英

PHP SimpleXML - Node as string

Im trying to get a XML node (with children) as string but had no success.

Here my xml

    <?xml version="1.0" encoding="UTF-8"?>
<params>
  <main_settings>
    <id>23</account_id>
    <test/>
    <logo_url/>
    <app appid="test_12">
      <d:tag xmlns:c="http://mypage.com/test2" id="mypage_id_256" type="mypage_type_test">
        <path-info value="show"/>
      </d:tag>
    </app>
  </main_settings>
</params>

This is not working.

    $var->params->main_settings->app;

Is there a way to get with simpleXML a nodes ("app") childs as sting?

You can call the asXml method on the child:

$var->params->main_settings->app->asXml();

It's also possible via typecasting:

(string)$var->params->main_settings->app

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM