XmlDocument.d.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /**
  2. * Copyright (C) 2016-2019 Michael Kourlas
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. import { IStringOptions } from "../options";
  17. import XmlComment, { IXmlCommentOptions } from "./XmlComment";
  18. import XmlDecl, { IXmlDeclOptions } from "./XmlDecl";
  19. import XmlDtd, { IXmlDtdOptions } from "./XmlDtd";
  20. import XmlElement, { IXmlElementOptions } from "./XmlElement";
  21. import XmlProcInst, { IXmlProcInstOptions } from "./XmlProcInst";
  22. /**
  23. * The options used to create a new document.
  24. */
  25. export interface IXmlDocumentOptions {
  26. /**
  27. * Whether to throw an exception if basic XML validation fails while
  28. * building the document.
  29. */
  30. validation?: boolean;
  31. }
  32. /**
  33. * Represents a document.
  34. *
  35. * A sample document is structured as follows:
  36. *
  37. * ```xml
  38. * <?xml version="1.0" encoding="UTF-8"?>
  39. * <DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  40. * "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  41. * <html>
  42. * <head>
  43. * <title>My page title</title>
  44. * </head>
  45. * <body>
  46. * <h1>Welcome!</h1>
  47. * <p>I hope you enjoy visiting my website.</p>
  48. * <img src="picture.png"/>
  49. * </body>
  50. * </html>
  51. * ```
  52. *
  53. * Each component of the document, such as the declaration, document type
  54. * definition, and root element, are children of this node.
  55. *
  56. * Documents must have exactly one element, which is the document's root
  57. * element.
  58. *
  59. * Documents can have exactly one declaration and one document type definition
  60. * in that order, so long as they precede the element.
  61. *
  62. * Documents can have an unlimited number of comments or processing
  63. * instructions, so long as they follow the declaration, if one exists.
  64. */
  65. export default class XmlDocument {
  66. private readonly _children;
  67. private readonly _validation;
  68. constructor(options: IXmlDocumentOptions);
  69. /**
  70. * Adds a comment to this document and returns the new comment.
  71. */
  72. comment(options: IXmlCommentOptions): XmlComment<this>;
  73. /**
  74. * Adds a declaration to this document and returns the new declaration.
  75. */
  76. decl(options?: IXmlDeclOptions): XmlDecl<this>;
  77. /**
  78. * Adds a document type definition to this document and returns the new
  79. * document type definition.
  80. */
  81. dtd(options: IXmlDtdOptions): XmlDtd<this>;
  82. /**
  83. * Adds the root element to this document and returns the element.
  84. */
  85. element(options: IXmlElementOptions): XmlElement<this>;
  86. /**
  87. * Adds a processing instruction to this document and returns the new
  88. * processing instruction.
  89. */
  90. procInst(options: IXmlProcInstOptions): XmlProcInst<this>;
  91. /**
  92. * Returns an XML string representation of this document using the
  93. * specified options.
  94. */
  95. toString(options?: IStringOptions): string;
  96. }