4 ms·
Maybe someone can chime in but parsing XML seems very much more difficult than parsing JSON.
by staticassertion 5y ago
Maybe someone can chime in but parsing XML seems very much more difficult than parsing JSON.
- oaiey 5y agoParsing XML is just grammar like JSON is ... that is not more or less difficult. JavaScript just has a built-in JSON Parser (which translate JSON into JavaScript object). As a consequence, JSON in JavaScript is super easy. Using XML is medium-hard. In .NET using XML or JSON is easy (not super easy). In C++ using XML or JSON is medium-hard. Do not know the state of the art for Go, Rust, Java, ... As a consequence, JSON is - from a JavaScript developer perspective - the holy grail. From a .NET/Java/C++ developer perspective it is just another format.
- radomir_cernoch 5y agoIn can't agree more. In Java, there's the JAXB ”parser“ which translates an XML schema into (mostly) straightforward classes. Correct initial setup is the only hard part.
- diroussel 5y agoThe key difference is that there are no options when you parse json. You just parse it and get some lists and maps back. In XML you have to decide if you want DTD or schema enabled (which could provide default values, and could be a security risk) and where abs how you resolve the DTDs from etc. Do you resolve references? And many option options. So JSON benefits not just from a simpler structure, but also from less optionality.
- oaiey 5y agoYou do not pull schemas dynamically. Schemalocation beyond editors is a pure theory thing. It is not default, it cannot be fast. Any serious developer has the schemas as files in their code when checking the data for compliance. Basically, in a static typed language you decide for schema checking or not - like for Json -, serializing in structures or access in an API - like for Json. It is just that JavaScript maps json directly in their dynamic object, array and native types. For xml that is an mismatch. For static languages both are an mismatch.
- staticassertion 5y ago> Parsing XML is just grammar like JSON is ... that is not more or less difficult. My understanding is that that's not the case. XML parsers are Pull or SAX based and it's weird as fuck. You can abstract that out, but parser complexity isn't something to sneeze out. For one thing, parsing XML is notoriously dangerous - tons of vulns both at a design and memory management level.
- dgb23 5y agoJust the raw parsing is a solved problem from a user's perspective, the issue arises when you ask yourself "into what" you parse or rather what the semantics of the tree is. It even might not matter whether you parse it programmatically or not in some cases. Typically when looking at a given XML (or other data structure text representations) you can pattern match the semantics of what you see, but that is not always true, because everyone uses it in a different way, relying almost completely on schema and documentation to convey semantics, which in turn makes the format strictly inferior to JSON, which also doesn't have rich semantics but is simpler.