3

Is there any easy way to create XML based on XML schema in Node.js? Currently I see modules like xmlbuilder that does help in creating XML from scratch ( does not follow schema). I want something high level, based on XML schema /XSD which will help in creating xml. Like POJOs are created based on XSD and now easy to populate POJOs and then create XML.

Thanks for any hints...

Shiva Kodityala
  • 105
  • 1
  • 10

1 Answers1

2

I am the author of Jsonix which is a powerful schema-driven XML<->JS converter, working in Node.js as well as in browsers.

See this answer for a complete example:

Schema-driven means that you can take an XML Schema and generate Jsonix mappings out of it. You can then serialize your JSON data conforming to the original XML Schema or unmarshal XML in that schema. Jsonix considers types and structures of the schema.

Community
  • 1
  • 1
lexicore
  • 42,748
  • 17
  • 132
  • 221
  • 2
    Wait, what? It requires Java? – Keith Tyler Aug 11 '16 at 16:44
  • @KeithTyler Jsonix - no, it's pure JavaScript. Jsonix Schema Compiler - yes. – lexicore Aug 11 '16 at 17:37
  • Well, if I want to use jsonix to generate compliant XML based on a known schema, I'm dependent on the Java-based schema compiler. Any reason why jsonix can't just parse the xsd natively? – Keith Tyler Aug 12 '16 at 17:43
  • In the compile-time - yes, in the runtime - no. The reason for the Java dependency is that Jsonix Schema Compiler uses JAXB/XJC undeneath which is Java. It would be a huge effort to rewrite it in JS. And, frankly, I see no reason to do this. – lexicore Aug 12 '16 at 17:54