2

I'm trying to generate XML containing structures similar to the following:

<p>
  Some text ...
  <bold>Bold text</bold>
  ... some more text ...
  <italic>Italic text</italic>
  ... and yet more text.
</p>

What input to new xml2js.Builder().buildObject() will obtain this structure?

Note that the children of the p element are a mix of element nodes and text nodes, and occur in a specific order.

Background: This is JATS, not HTML. I'm modifying some existing code that produces XML for Crossref, and I have to add portions of JATS to the tree, a bit like this. If xml2js simply can't produce these structures I will seek another tool, but that would require a substantial refactoring, which I'd prefer to avoid.

Ben Whitmore
  • 857
  • 1
  • 6
  • 15
  • Seems like you try to create a html site instead of xml. Why are you not using a template engine like handlebars? – Marc Sep 27 '21 at 13:41
  • @Marc This is not HTML, but rather, JATS. And I'm not working with set templates, so a handlebars-like approach doesn't seem right. – Ben Whitmore Sep 27 '21 at 21:57
  • Your example seems to be well-formed XML("well-formed JATS") ... so I don't see why it wouldn't work. Q: Have you tried it yet? What did you find? – paulsm4 Sep 27 '21 at 22:24
  • @paulsm How can I try this? What is the structure of the javascript object I need to pass in to `new xml2js.Builder().buildObject()`? – Ben Whitmore Sep 28 '21 at 03:58
  • *You're* asking *ME*? I thought the whole point of your question - the entire reason you were considering xml2js - is that you were receiving some JSON (from "somewhere"), you wanted to convert it to JATS ("somehow") and you thought xml2js might do the job (sounds plausible). Q: So where *ARE* you getting your input from? Is it in JSON format (like I thought your question implied)? And what led you to xml2js in the first place? Are you considering other, different alternatives as well? – paulsm4 Sep 28 '21 at 04:37
  • @paulsm I have tried to clarify the question. I'm modifying some code that uses xml2js to generate XML ([Crossref](https://data.crossref.org/reports/help/schema_doc/4.4.2/index.html) format), and I need to add portions of JATS to the tree. I have complete control of the input object, which is programmatically built, not ingested from JSON. Essentially, my question is, what input to `new xml2js.Builder().buildObject()` will produce the desired output above? I can switch to other tools if xml2js simply can't do it, but that will require a substantial refactoring of existing code. – Ben Whitmore Sep 28 '21 at 05:29

0 Answers0