I wonder if there might be a DOM-like JSON/XML parser + generator library which allows one to search the in-memory nodes (after parsing / before unparsing) by name in an efficient way (better than linear). That is, having at least logarithmic time such as that in Bynary Search Trees and the like (so analogous to Map implementations in Java).

This is because I'll have a multi-level hierarchy with on-the-fly/dynamic names (data based), kept in memory during whole program execution (basically for a Spring server), that are subject to be updated at any time originating from client requests. And so that I wouldn't have to use some Map object for holding the in-memory tree instead before generating the JSON/XML files that would imply converting the data to the library, in an effort to avoid the usual impedance missmatch.

Searching for DOM-like libraries that use logarithmic or efficient time access (for the in-memory nodes) I can't find anything mentioning that.

EDIT: JSON is preferred.

  • Saxon's XML tree models index nodes by name. But XML and JSON are very different, so asking about both in the same breath isn't constructive. Mar 26, 2022 at 14:56
  • I initially preferred XML as that's the file format we have been using due to some official specifications, but I realized the dynamic data keys/tags might start with a number, which isn't valid to XML and I had thought of prepending an underscore, which isn't convenient when having JSON instead. But accepting that workaround, both formats are fine to me in order to maximize the chances of finding a library with my requirement (efficient name based key lookups in memory for replacing/updating their values when needed, that is).
    – Adrián
    Mar 26, 2022 at 19:14
  • Indexing, and in-situ modification, don't sit well together because of course in-situ modification can affect the indexes. Mar 27, 2022 at 21:27
  • Incidentally, some PhD student once published a paper asserting that Saxon used indexing for path selections, based purely on measurement. He didn't actually look at the code. It actually does a serial search; it's just that the search is so blazingly fast, his measurement methodology couldn't cope. So when you ask for indexing, it might be better to say what your actual required performance metrics are, not how you think they might be achieved. Mar 29, 2022 at 15:17


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.