![]() ![]() ![]() You could use xmltodict but you will have to pay the penalty of parsing the XML again. Mainly I love to share knowledge.When I do anything with XML in python I almost always use the lxml package. I love hacking together code to make awesome things, and I love understanding theoretical computer science to aid the former. Have a look at the code in full at my GitHub account. A JSON instance is clear about whether an element is an object, or a list of object because this can be inferred from the use of either ) This will be solved by converting attributes into elements. Likewise, JSON has no concept of an attribute, only elements. An XML element can be made of sub-elements and also attributes e.g. To simplify the conversion property, namespaces shall be ignored.Īttributes. ![]() Namespaces are used to allow the same element names to be used in the same document from differing origins e.g. An XML element may have an optional namespace element e.g. ![]() So that we might create a method of converting XML to JSON, the following issues will be dealt with by: There are three concepts in a block of XML that have no counterpart in JSON. Neither of these makes a compelling case for a software library.īut regardless, I’ve made one that solves at least one of the use cases. A lack of bijective one-to-one mapping means that no-one will create a library because it will be either a narrow solution good for only a subset of all use cases, or it will require extensive configuration to map the grey areas. There are too many grey areas where a choice needs to be made about how the conversion should be done. Quite simply, because you cannot express XML as JSON and vice versa. “Why isn’t there a library to do this?” I thought. So when I recently needed to convert XML to JSON, I didn’t even think about the structure of XML, I simply looked for a library to do it. XML and JSON are the two most common generic standards for passing representation state information in web APIs. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |