Leonidas-from-XIV / node-xml2js

XML to JavaScript object converter.
MIT License
4.88k stars 602 forks source link

Parsing text, and tag/attr/content form #505

Open rpav opened 5 years ago

rpav commented 5 years ago

It would be useful if one could customize how entire tags were converted to JS structure. It does not seem possible to usefully parse text given any of the available options. E.g.,

parse('<text>so <i>this</i> is <b>text</b></text>', (err,x) => {console.log(x)});

// => { text: { _: 'so  is ', i: [ 'this' ], b: [ 'text' ] } }

No options seem to produce useful results. Instead, if one could provide a transform function on entire nodes, it would be possible to produce a "general" form:

{ tag: "text",
  attrs: [],
  content: [
      "so ",
      { tag: "i", attrs: [], content: ["this"] },
      " is ", ...