5 ms·
Ironically, php provides a way to access XML data almost as easily as JASON data - SimpleXML. Do other languages/frameworks really have nothing similar?
by stephenr 15y ago
Ironically, php provides a way to access XML data almost as easily as JASON data - SimpleXML. Do other languages/frameworks really have nothing similar?
- zachanker 15y agoWhile SimpleXML gives you an easy way to walk the tree, it still requires you to actually do it. All 3 of those examples would require slightly different calls to SimpleXML to handle.
- SigmundA 15y agowhat else do you do with a data structure besides walk it at some point? JSON comes out as an acyclic object graph in javascript, so what it still needs to be walked to actually do something with the data. The difference between walking JSON and XML is simply the syntax of the parser library your are using. The problem with XML is it has things that don't map directly to most OO languages, like node order matters, and attributes and elements are similar but different things, and mixed content. So JSON is nice simply because it's close the the OO style everyone is used to today, and is in fact a subset of one of those languages. IMO either way we need to settle on a way to interchange structured data, and agree on data types, but I would prefer some binary format, text encoding all this data such a waste of space/time.
- zachanker 15y agoReiterating the point the blog post makes, but: It's very very easy to structure the same data in different ways in XML. While JSON has the same issue, it's a lot harder to do and you have less flexibility in making bad storage decisions. You are absolutely right on walking the structure. JSON just tends to be easier (in my experience), even when working with XML libraries that make it less of a pain.
- nowarninglabel 15y agoI'll give the opposing opinion that I find working with XML easier than JSON, but mostly because of QueryPath.
- mythz 15y agoXSLT Parser is that you?
- yahelc 15y agoThe moment I realized I could do json_decode(json_encode($simple_xml_object),true); to turn a complex SimpleXML object into an array was the happiest moment of my life.
- tintin 15y agoOnly problem with SimpleXML is that it needs to have the complete file in memory. This isn't a problem for small XML files. But reading a file of lets say 100MB will produce tons of objects an thus a large amount of used memory.
- jasonlotito 15y agoI'd argue that any chance of having a large XML file where you'd use SAX, you'd need to deal with JSON in the same manner. Then the problem is solved with XML (use SAX), but with JSON, what do I use?