4 ms·
> It uses XML, which requires a library for browser JavaScript, What? XMLHTTPRequest (XHR) People forget XML parsing is baked into JS as is XPath But I do ag
by hunterb123 4y ago
> It uses XML, which requires a library for browser JavaScript,
What? XMLHTTPRequest (XHR)
People forget XML parsing is baked into JS as is XPath
But I do agree with your premise otherwise.
- anderspitman 4y agoHa. Honestly, you're totally right. I've used XHR for years but never actually for XML. When looking at WebDAV in the past I couldn't find a way to serialize/deserialize XML the same way you can with JSON (is there a way?), but I didn't realize XHR handles that natively. TIL, thanks.
- easrng 4y agoYou can use a DOMParser to parse XML (or HTML) from a string. const doc = new DOMParser().parseFromString('<xml><tag attr="value" /></xml>', "text/xml"); doc.querySelector("tag").getAttribute("attr") // returns "value"
- anderspitman 4y agoAwesome, thanks! I could have sworn I looked into this and didn't find a way in vanilla JS, but definitely looks like I was wrong.