Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XML support #2488

Closed
iugo opened this issue Aug 2, 2022 · 7 comments
Closed

XML support #2488

iugo opened this issue Aug 2, 2022 · 7 comments

Comments

@iugo
Copy link

iugo commented Aug 2, 2022

XML is common. It would be nice if the standard library could support XML to JS and some JS to XML.

Is your feature request related to a problem? Please describe.

Just like: #231, #431

Describe the solution you'd like

https://www.npmjs.com/package/xml2js

Describe alternatives you've considered

@crowlKats
Copy link
Member

There is #2471, however it seems a bit questionable whether it will be part of std

@tjosepo
Copy link
Contributor

tjosepo commented Sep 17, 2022

While this might not be the answer you're looking for, most DOM parsers are able to parse XML as well:

import { DOMParser } from "https://esm.sh/[email protected]";

const xml = `
  <note>
    <to>Tove</to>
    <from>Jani</from>
    <heading>Reminder</heading>
    <body>Don't forget me this weekend!</body>
  </note>
`;

const document = new DOMParser().parseFromString(xml, "text/xml");
const to = document.querySelector("to").innerText;
const from = document.querySelector("from").innerText;
console.log("To: " + to + ", from: " + from); // => "To: Tove, from: Jani"

@lino-levan
Copy link
Contributor

I feel like there should be a decision made by either the core team or the community on whether or not XML parsing should be in std. My sense is that it is overly complicated and there are already /x/ libraries for it, but I'm curious to hear from not just myself.

@iuioiua
Copy link
Collaborator

iuioiua commented Nov 5, 2022

I'm -1 on this. I don't see a benefit of a implementation in std if existing third party modules work great. I've used a couple of them before.

@cjihrig
Copy link
Contributor

cjihrig commented Nov 5, 2022

@iuioiua do you have a few that you'd like to recommend here? I know I'm personally not super excited at the thought of maintaining an XML library unless absolutely necessary 😄

@iuioiua
Copy link
Collaborator

iuioiua commented Nov 5, 2022

I've used and recommend:

  1. xml2js - converts xml to a straightforward and easy to work with JS object.
  2. xml - probably more extensive and mimics the familiar JSON API (parse and stringify).

@cjihrig
Copy link
Contributor

cjihrig commented Nov 7, 2022

I'm going to close this out based on the feedback in #2471, as well as the availability of third party modules.

@cjihrig cjihrig closed this as completed Nov 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants