You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // Generated by CoffeeScript 2.4.1
  2. (function() {
  3. var NodeType, WriterState, XMLDOMImplementation, XMLDocument, XMLDocumentCB, XMLStreamWriter, XMLStringWriter, assign, isFunction;
  4. ({assign, isFunction} = require('./Utility'));
  5. XMLDOMImplementation = require('./XMLDOMImplementation');
  6. XMLDocument = require('./XMLDocument');
  7. XMLDocumentCB = require('./XMLDocumentCB');
  8. XMLStringWriter = require('./XMLStringWriter');
  9. XMLStreamWriter = require('./XMLStreamWriter');
  10. NodeType = require('./NodeType');
  11. WriterState = require('./WriterState');
  12. // Creates a new document and returns the root node for
  13. // chain-building the document tree
  14. // `name` name of the root element
  15. // `xmldec.version` A version number string, e.g. 1.0
  16. // `xmldec.encoding` Encoding declaration, e.g. UTF-8
  17. // `xmldec.standalone` standalone document declaration: true or false
  18. // `doctype.pubID` public identifier of the external subset
  19. // `doctype.sysID` system identifier of the external subset
  20. // `options.headless` whether XML declaration and doctype will be included:
  21. // true or false
  22. // `options.keepNullNodes` whether nodes with null values will be kept
  23. // or ignored: true or false
  24. // `options.keepNullAttributes` whether attributes with null values will be
  25. // kept or ignored: true or false
  26. // `options.ignoreDecorators` whether decorator strings will be ignored when
  27. // converting JS objects: true or false
  28. // `options.separateArrayItems` whether array items are created as separate
  29. // nodes when passed as an object value: true or false
  30. // `options.noDoubleEncoding` whether existing html entities are encoded:
  31. // true or false
  32. // `options.stringify` a set of functions to use for converting values to
  33. // strings
  34. // `options.writer` the default XML writer to use for converting nodes to
  35. // string. If the default writer is not set, the built-in XMLStringWriter
  36. // will be used instead.
  37. module.exports.create = function(name, xmldec, doctype, options) {
  38. var doc, root;
  39. if (name == null) {
  40. throw new Error("Root element needs a name.");
  41. }
  42. options = assign({}, xmldec, doctype, options);
  43. // create the document node
  44. doc = new XMLDocument(options);
  45. // add the root node
  46. root = doc.element(name);
  47. // prolog
  48. if (!options.headless) {
  49. doc.declaration(options);
  50. if ((options.pubID != null) || (options.sysID != null)) {
  51. doc.dtd(options);
  52. }
  53. }
  54. return root;
  55. };
  56. // Creates a new document and returns the document node for
  57. // chain-building the document tree
  58. // `options.keepNullNodes` whether nodes with null values will be kept
  59. // or ignored: true or false
  60. // `options.keepNullAttributes` whether attributes with null values will be
  61. // kept or ignored: true or false
  62. // `options.ignoreDecorators` whether decorator strings will be ignored when
  63. // converting JS objects: true or false
  64. // `options.separateArrayItems` whether array items are created as separate
  65. // nodes when passed as an object value: true or false
  66. // `options.noDoubleEncoding` whether existing html entities are encoded:
  67. // true or false
  68. // `options.stringify` a set of functions to use for converting values to
  69. // strings
  70. // `options.writer` the default XML writer to use for converting nodes to
  71. // string. If the default writer is not set, the built-in XMLStringWriter
  72. // will be used instead.
  73. // `onData` the function to be called when a new chunk of XML is output. The
  74. // string containing the XML chunk is passed to `onData` as its single
  75. // argument.
  76. // `onEnd` the function to be called when the XML document is completed with
  77. // `end`. `onEnd` does not receive any arguments.
  78. module.exports.begin = function(options, onData, onEnd) {
  79. if (isFunction(options)) {
  80. [onData, onEnd] = [options, onData];
  81. options = {};
  82. }
  83. if (onData) {
  84. return new XMLDocumentCB(options, onData, onEnd);
  85. } else {
  86. return new XMLDocument(options);
  87. }
  88. };
  89. module.exports.stringWriter = function(options) {
  90. return new XMLStringWriter(options);
  91. };
  92. module.exports.streamWriter = function(stream, options) {
  93. return new XMLStreamWriter(stream, options);
  94. };
  95. module.exports.implementation = new XMLDOMImplementation();
  96. module.exports.nodeType = NodeType;
  97. module.exports.writerState = WriterState;
  98. }).call(this);