XML Parsing/Serializing

Posted on
  • I just got asked about this on Patreon. Is there much interest in having a code library that'd handle this in Espruino? Any thoughts about what it might look like?

    I guess realistically this might be the best bet: https://developer.mozilla.org/en-US/docs­/Web/Guide/Parsing_and_serializing_XML

    I could add a (very simple) DOM implementation in JS to allow the XML to be created/interacted with. Realistically XPath isn't going to happen though :)

  • I played with WebDAV implementation where the requests are XML parsed in JS and made it working on linux but got into 'too much recursion' on actual boards (available here https://github.com/opichals/refresh/tree­/testing). Also UPnP mostly exposes XML stuff.

    I think a non-recursive implementation of XML parse/serialization (into JS objects and back) might be an interesting feature. IMO there is no need to any XML tailored DOM implementation, plain JS objects should suffice.

    Some exclude/include filtering in the parse method may be handy so that it is possible to just grab part of the XML content somehow and not eat all the available memory.

  • Thr 2018.11.29

    While I could see a use with simple file saves, serialization, and de-serialization to read, won't this just add to the library bloat where just using the existing JSON and base64 encoding would basically do (single string file write) the same thing?

    Should memory allow, and if there were a browser choice usage direction, without X-Path (attributes), it hardly seems worth the development effort. (As a user, if I saw a basic implementation, I'd wonder and want it to do more - human nature - the intent of offering a simple variation could backfire)

    That said, it would be a cool feature to have as an additional interesting feature in the arsenal of what Espruino can do, but as @opichals indicates could easily become a challenge (lack of memory) on complex Xml nodes.

    My 0.02 worth . . . .

  • XML sounds interesting, but there is no usecase in my mind.

  • Yes, you wouldn't want to use XML 'just because', but there are still a bunch of IoT services that use XML.

    As well as @opichals UPnP, a good example is RSS. I know it's probably getting less popular now, but having a proper way to parse that data would be great. Not just for news, but things like the weather are often XML.

    When I've done stuff with it in the past I've just used string searching hacks to get the data I want (eg. https://youtu.be/-Ag55U2BTK8?t=856

    ) but it'd be far better to be able to drag out the data.

    @opichals yes, definitely we'd have to have something that avoided recursing too much - I think it should be reasonably easy.

    In terms of API it'd be nice to have something 'standard' - but failing that the Compact JSON format used by https://www.npmjs.com/package/xml-js looks possible. Having said that they point out that multiple nodes of the same type get handled differently (node:{a_node} vs node:[{a_node},{a_node}]) and I wonder whether a cut down DOM really uses that much more memory.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

XML Parsing/Serializing

Posted by Avatar for Gordon @Gordon

Actions