Lossless JSON encoding/decoding of XML in PHP????

So I got some XML and thought “well, simplexml looks like an easy way to parse the xml.” Then serialized it with json_encode and json_decode. BUT it loses the attributes on some of the nodes!!!

Someone reported this as a bug:

“Description:
————
If you json encode a simplexml object, any xml leaf nodes will lose
their attributes

The attached script has two small xml strings. One with attributes
on the leaf node, one without.

When you run the script, attribute values disappear for the second
json string”

Here’s the reply they got, that it’s not a bug!! Why does it keep some attributes, but not others, why is it not lossless??? If it DOESN’T WORK, why is it available? It’s not a bug because it wasn’t supposed to keep all the attributes, only some, randomly? Defective design doesn’t count as a bug? I don’t get it…

“[20 Oct 2008 11:10pm UTC] iliaa@php.net

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

You cannot do a lossless (loss of attributes) on an object of a certain

type such as SimpleXML.”

You can put simplexml data into session variables by casting it to string first (string), could that be one way of getting around the attribute loss by not having to use json?

Advertisements

The Best 80s and 90s R&B: Stevie Wonder–That Girl, Michael Jackson–Remember The Time


Stevie Wonder–That Girl (1982)


Michael Jackson–Remember the Time (1991)

Ah, so good! Some of the best and most distinctive songs of the 1980s and the 1990s. Well, Remember the Time is so close to being cheesy, but….

Understanding Euclid’s Greatest Common Divisor Algorithm

Some quick notes on explaining how Euclid’s greatest common divisor algorithm works: if a=bq + r, and a=d(gq + h), where dg=b and dh=r, then d is a divisor of a, as well as of b and of r. So d|a and d|b and d|r. The recursion in the algorithm (here are the details) finds the greatest value of d satisfying d|a and d|b and d|r. I think.

internal tag: math