0

I'm building a mobile app with PhoneGap. I'm not a very experienced web developer, and I just successfully made my first ever (!) XMLHttpRequest to a remote server and retrieved an XML document, all from an iPod. But now I have to parse the XML with JavaScript, and I've never done this before. Obviously browser specific parsers are out of the question, as this isn't happening in a browser. Another suggestion I saw was to use JQuery, but I'm wondering if there are any other methods which may be more straightforward or preferable in some other way I hadn't thought of.

Suggestions?

temporary_user_name
  • 35,956
  • 47
  • 141
  • 220
  • Given that you are not running in a browser, possibly [this answer](https://stackoverflow.com/a/48393811) or [this answer](https://stackoverflow.com/a/9056881) to [XML parsing of a variable string in JavaScript](https://stackoverflow.com/q/649614) might be relevant – dbc Feb 27 '23 at 23:02

2 Answers2

1

Assuming the document is served with the correct Content-Type, then any browser implementing XMLHttpRequest will populate the responseXML populate of that object with an XML DOM.

You don't need to manually parse it.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
0

I think this specific answer that I've recently seen here on SO might be helpful for you (you can read the whole post and I'm pretty sure you'll find an answer).

If you decide to eventually use JQuery anyway, I think there's a good explanation on how to use it for traversing XMLs here. However, be aware that it relies on the DOM innerHTML method and doesn't do the parsing itself, so cases such as having HTML content in your XML nodes might be problematic.

Hope this helps, Good luck!

UPDATE: I'm so sorry, I just read your question again and realized that you're not running in a browser, don't know how I missed it. In that case, I'm not completely sure my answer is very helpful any more, it's just that I'm not familiar with PhoneGap :/

Community
  • 1
  • 1
Adi
  • 707
  • 6
  • 12