|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2008-08-21 20:49 UTC] jani@php.net
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 10:00:01 2025 UTC |
Description: ------------ Hi: I am a new gur for PHP program, Recently when I write a program that use php function json_encode() to translate a simpleXML object into json code, I found the attributes of the XML leafage node was lose. Wait to solve :). Thank you. Reproduce code: --------------- <? $xml_str = "<root><node attr='node attribute'>node value</node></root>"; $xml_obj = simplexml_load_string($xml_str); $json = json_encode($xml_obj); echo $json; // so where is node's attribute echo "\n=======================================\n"; $xml_str = "<root><node attr='node attribute'></node></root>"; $xml_obj = simplexml_load_string($xml_str); $json = json_encode($xml_obj); echo $json; // found it, but why? ?> Expected result: ---------------- {"node":"node value"} ======================================= {"node":{"@attributes":{"attr":"node attribute"}}} Actual result: -------------- inlude node's value and attributes