06-27-2018 18:15
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

06-27-2018 18:15
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I'm working on a simple app which accesses a CALDAV server. Responses are in XML. It appears as though Fitbit standardized on JSON a little while back and deprecated XML support. Fine and understandable. Given that, what's the easiest way to parse a relatively simple XML response? Write my own recursive XML parser?

- Labels:
-
JavaScript
07-21-2018 20:52
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

07-21-2018 20:52
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I would like to know an answer to this as well.
Through the Simulator I am able to use DomParser in order to parse the data:
var parser = new DOMParser(); var xmlDoc = parser.parseFromString(data,"text/xml");
However, once pushed to the Versa I receive: Can't find variable: DOMParser.
This discontinuity from the Simulator to the device has me at a loss.

07-21-2018 21:33
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

07-21-2018 21:33
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
/raj
(sent from iPhone)

07-22-2018 04:19
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

07-22-2018 04:19
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Thank you Raj, I actually did the same after I wrote here.

11-30-2020 04:59
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

11-30-2020 04:59
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Hi Rajid,
I have the same problem right now. Would you mind sharing your parser with me?
Kind regards,
Schete

11-30-2020 13:04
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

11-30-2020 13:04
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
Here's my simple, basic, recursive, parser. It called my parseCalendar() routine in order to actually parse the calendar entry, but the rest is simply a basic parse of the XML. I hope it's useful as a starting point. (If you're trying to deal with actual calendar information on a Fitbit watch, they now have an API specifically to do that, which is must easier.
function xmlparse(xml,index) {
xml = xml.trim();
while (xml.length > 0) {
if (xml.indexOf("<!") == 0) {
let e = xml.indexOf(">");
// console.log(`Calendar data is: ${xml.substring(2,e)}`);
parseCalendar(xml.substring(2,e),index);
return xml.substring(e+1);
}
if (xml[0] != '<') {
let e=xml.indexOf("<");
// console.log(`Body='${xml.substring(0,e)}`);
return xml.substring(e);
}
// Save the initial component name
let comp = xml.search(/[ >]/);
// console.log(`comp=${comp}`);
let component = xml.substring(1,comp);
// console.log(`component is '${component}'`);
// Find the closing brace
let compEnd = xml.search(/>/);
// Now parse the rest
let remain = xmlparse(xml.substring(compEnd+1),index);
if (!remain || remain.length == 0) {
return "";
}
remain.trim();
if (remain.indexOf("</" + component) == 0) {
// This is my component end
let compEnd = remain.search(/>/) + 1;
// console.log(`compEnd is: '${remain.substring(compEnd)}'`);
return remain.substring(compEnd);
}
// Parse next thing at this level
xml = remain.trim();
// console.log("** Next thing at this level");
}
}
11-30-2020 22:19
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

11-30-2020 22:19
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Thank you for sharing!

05-10-2023 13:10
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

05-10-2023 13:10
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
What’s good

