Hacker News new | past | comments | ask | show | jobs | submit login

You 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"



Awesome, 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: