xmlcreate

  • Version 2.0.4
  • Published
  • 169 kB
  • No dependencies
  • Apache-2.0 license

Install

npm i xmlcreate
yarn add xmlcreate
pnpm add xmlcreate

Overview

Simple XML builder for Node.js

Index

Functions

Classes

Interfaces

Functions

function document

document: (options?: IXmlDocumentOptions) => XmlDocument;
  • Returns a new XML document with the specified options.

Classes

class XmlAttribute

class XmlAttribute<Parent> {}
  • Represents an attribute.

    An attribute is part of the start tag of an element and is structured as follows, where {name} is the name of the attribute and {value} is the value of the attribute:

    <element {name}="{value}">

    The {name} value is a property of this node, while the {value} property consists of the children of this node.

    Attributes can have an unlimited number of attribute text, character references, and entity references.

constructor

constructor(parent: {}, validation: boolean, options: IXmlAttributeOptions);

    property name

    name: string;
    • Gets the name of this attribute.

    method charRef

    charRef: (options: IXmlCharRefOptions) => XmlCharRef<this>;
    • Adds a character reference to this attribute and returns the new character reference.

    method entityRef

    entityRef: (options: IXmlEntityRefOptions) => XmlEntityRef<this>;
    • Adds an entity reference to this attribute and returns the new entity reference.

    method text

    text: (options: IXmlAttributeTextOptions) => XmlAttributeText<this>;
    • Adds attribute text to this attribute and returns the new text.

    method toString

    toString: (options?: IStringOptions) => string;
    • Returns an XML string representation of this attribute.

    method up

    up: () => Parent;
    • Returns the parent of this attribute.

    class XmlAttributeText

    class XmlAttributeText<Parent> {}
    • Represents text in an attribute value.

      Restricted characters, such as the ampersand (&) and the opening angle bracket (<), are all automatically escaped.

    constructor

    constructor(parent: {}, validation: boolean, options: IXmlAttributeTextOptions);

      property charData

      charData: string;
      • Gets this attribute text.

      method toString

      toString: () => string;
      • Returns an XML string representation of this attribute text.

      method up

      up: () => Parent;
      • Returns the parent of this attribute text.

      class XmlCdata

      class XmlCdata<Parent> {}
      • Represents a CDATA section.

        A CDATA section is structured as follows, where {data} is the character data of the section:

        <![CDATA[{data}]]>

      constructor

      constructor(parent: {}, validation: boolean, options: IXmlCdataOptions);

        property charData

        charData: string;
        • Gets the character data of this CDATA section.

        method toString

        toString: () => string;
        • Returns an XML string representation of this CDATA section.

        method up

        up: () => Parent;
        • Returns the parent of this CDATA section.

        class XmlCharData

        class XmlCharData<Parent> {}
        • Represents character data.

          Restricted characters, such as the ampersand (&), the opening angle bracket (<), and the closing angle bracket (>) when it appears in the string ]]>, are all automatically escaped.

        constructor

        constructor(parent: {}, validation: boolean, options: IXmlCharDataOptions);

          property charData

          charData: string;
          • Gets the text of this character data.

          method toString

          toString: () => string;
          • Returns an XML string representation of this character data.

          method up

          up: () => Parent;
          • Returns the parent of this character data.

          class XmlCharRef

          class XmlCharRef<Parent> {}
          • Represents a character reference.

            A character reference is structured as follows, where {dec} is the decimal representation code point corresponding to a particular Unicode character:

            &#{dec};

            The corresponding hexadecimal version is structured as follows, where {hex} is the hexadecimal representation code point corresponding to a particular Unicode character:

            &#x{hex};

            Unicode characters outside of the Basic Multilingual Plane are represented using a surrogate pair consisting of two character references.

            The {dec} and {hex} values are defined by the char and hex properties of this node; the former is the character to be represented while the latter indicates whether the decimal or hexadecimal representation should be used.

          constructor

          constructor(parent: {}, validation: boolean, options: IXmlCharRefOptions);

            property char

            char: string;
            • Gets the character of this character reference.

            property hex

            hex: boolean;
            • Gets whether the decimal or hexadecimal representation should be used for this character reference.

            method toString

            toString: () => string;
            • Returns an XML string representation of this character reference.

            method up

            up: () => Parent;
            • Returns the parent of this character reference.

            class XmlComment

            class XmlComment<Parent> {}
            • Represents a comment.

              A comment is structured as follows, where {content} is the text of the comment:

              <!--{content}-->

            constructor

            constructor(parent: {}, validation: boolean, options: IXmlCommentOptions);

              property charData

              charData: string;
              • Gets the text of this comment.

              method toString

              toString: () => string;
              • Returns an XML string representation of this comment.

              method up

              up: () => Parent;
              • Returns the parent of this comment.

              class XmlDecl

              class XmlDecl<Parent> {}
              • Represents a declaration.

                A declaration is structured as follows, where {version} is the XML version, {encoding} is the encoding of the document, and {standalone} is either "yes" or "no", depending on whether the document may contain external markup declarations:

                <?xml version="{version}" encoding="{encoding}" standalone="{standalone}"?>

              constructor

              constructor(parent: {}, validation: boolean, options: IXmlDeclOptions);

                property encoding

                encoding: string;
                • Gets the encoding associated with this declaration.

                property standalone

                standalone: string;
                • Gets the value of the standalone attribute associated with this declaration.

                property version

                version: string;
                • Gets the XML version associated with this declaration.

                method toString

                toString: (options?: IStringOptions) => string;
                • Returns an XML string representation of this declaration.

                method up

                up: () => Parent;
                • Returns the parent of this declaration.

                class XmlDocument

                class XmlDocument {}
                • Represents a document.

                  A sample document is structured as follows:

                  <?xml version="1.0" encoding="UTF-8"?>
                  <DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
                  <html>
                  <head>
                  <title>My page title</title>
                  </head>
                  <body>
                  <h1>Welcome!</h1>
                  <p>I hope you enjoy visiting my website.</p>
                  <img src="picture.png"/>
                  </body>
                  </html>

                  Each component of the document, such as the declaration, document type definition, and root element, are children of this node.

                  Documents must have exactly one element, which is the document's root element.

                  Documents can have exactly one declaration and one document type definition in that order, so long as they precede the element.

                  Documents can have an unlimited number of comments or processing instructions, so long as they follow the declaration, if one exists.

                constructor

                constructor(options: IXmlDocumentOptions);

                  method comment

                  comment: (options: IXmlCommentOptions) => XmlComment<this>;
                  • Adds a comment to this document and returns the new comment.

                  method decl

                  decl: (options?: IXmlDeclOptions) => XmlDecl<this>;
                  • Adds a declaration to this document and returns the new declaration.

                  method dtd

                  dtd: (options: IXmlDtdOptions) => XmlDtd<this>;
                  • Adds a document type definition to this document and returns the new document type definition.

                  method element

                  element: (options: IXmlElementOptions) => XmlElement<this>;
                  • Adds the root element to this document and returns the element.

                  method procInst

                  procInst: (options: IXmlProcInstOptions) => XmlProcInst<this>;
                  • Adds a processing instruction to this document and returns the new processing instruction.

                  method toString

                  toString: (options?: IStringOptions) => string;
                  • Returns an XML string representation of this document using the specified options.

                  class XmlDtd

                  class XmlDtd<Parent> {}
                  • Represents an XML document type definition (DTD).

                    A document type definition is structured as follows, where {name} is the name of the DTD, {sysId} is the system identifier of the DTD, {pubId} is the public identifier of the DTD, and {intSubset} is the internal subset of the DTD:

                    <!DOCTYPE {name} SYSTEM "{sysId}" PUBLIC "{pubId}" [
                    {intSubset}
                    ]>

                    DTDs can have an unlimited number of comments, attribute-list declarations, element declarations, entity declarations, notation declarations, parameter entity references, and processing instructions.

                  constructor

                  constructor(parent: {}, validation: boolean, options: IXmlDtdOptions);

                    property name

                    name: string;
                    • Gets the name of the DTD.

                    property pubId

                    pubId: string;
                    • Gets the public identifier of the DTD.

                    property sysId

                    sysId: string;
                    • Gets the system identifier of the DTD.

                    method attlist

                    attlist: (options: IXmlDtdAttlistOptions) => XmlDtdAttlist<this>;
                    • Adds an attribute-list declaration to this document type declaration and returns the new attribute-list declaration.

                    method comment

                    comment: (options: IXmlCommentOptions) => XmlComment<this>;
                    • Adds a comment to this document type declaration and returns the new comment.

                    method element

                    element: (options: IXmlDtdElementOptions) => XmlDtdElement<this>;
                    • Adds an element declaration to this document type declaration and returns the new element declaration.

                    method entity

                    entity: (options: IXmlDtdEntityOptions) => XmlDtdEntity<this>;
                    • Adds an entity declaration to this document type declaration and returns the new entity declaration.

                    method notation

                    notation: (options: IXmlDtdNotationOptions) => XmlDtdNotation<this>;
                    • Adds a notation declaration to this document type declaration and returns the new notation declaration.

                    method paramEntityRef

                    paramEntityRef: (
                    options: IXmlDtdParamEntityRefOptions
                    ) => XmlDtdParamEntityRef<this>;
                    • Adds a parameter entity reference to this document type declaration and returns the new parameter entity reference.

                    method procInst

                    procInst: (options: IXmlProcInstOptions) => XmlProcInst<this>;
                    • Adds a processing instruction to this document type declaration and returns the new processing instruction.

                    method toString

                    toString: (options?: IStringOptions) => string;
                    • Returns an XML string representation of this document type declaration.

                    method up

                    up: () => Parent;
                    • Returns the parent of this attribute.

                    class XmlDtdAttlist

                    class XmlDtdAttlist<Parent> {}
                    • Represents an attribute-list declaration in a document type definition.

                      An attribute-list declaration is structured as follows, where {text} is the text of the declaration:

                      <!ATTLIST {text}>

                    constructor

                    constructor(parent: {}, validation: boolean, options: IXmlDtdAttlistOptions);

                      property charData

                      charData: string;
                      • Gets the text of this entity declaration.

                      method toString

                      toString: () => string;
                      • Returns an XML string representation of this entity declaration.

                      method up

                      up: () => Parent;
                      • Returns the parent of this entity declaration.

                      class XmlDtdElement

                      class XmlDtdElement<Parent> {}
                      • Represents an element declaration in a document type definition.

                        An element declaration is structured as follows, where {text} is the text of the declaration:

                        <!ELEMENT {text}>

                      constructor

                      constructor(parent: {}, validation: boolean, options: IXmlDtdElementOptions);

                        property charData

                        charData: string;
                        • Gets the text of this element declaration.

                        method toString

                        toString: () => string;
                        • Returns an XML string representation of this element declaration.

                        method up

                        up: () => Parent;
                        • Returns the parent of this element declaration.

                        class XmlDtdEntity

                        class XmlDtdEntity<Parent> {}
                        • Represents an entity declaration in a document type definition.

                          An entity declaration is structured as follows, where {text} is the text of the declaration:

                          <!ENTITY {text}>

                        constructor

                        constructor(parent: {}, validation: boolean, options: IXmlDtdEntityOptions);

                          property charData

                          charData: string;
                          • Gets the text of this entity declaration.

                          method toString

                          toString: () => string;
                          • Returns an XML string representation of this entity declaration.

                          method up

                          up: () => Parent;
                          • Returns the parent of this entity declaration.

                          class XmlDtdNotation

                          class XmlDtdNotation<Parent> {}
                          • Represents a notation declaration in a document type definition.

                            A notation declaration is structured as follows, where {text} is the text of the declaration:

                            <!NOTATION {text}>

                          constructor

                          constructor(parent: {}, validation: boolean, options: IXmlDtdNotationOptions);

                            property charData

                            charData: string;
                            • Gets the text of this notation declaration.

                            method toString

                            toString: () => string;
                            • Returns an XML string representation of this notation declaration.

                            method up

                            up: () => Parent;
                            • Returns the parent of this notation declaration.

                            class XmlDtdParamEntityRef

                            class XmlDtdParamEntityRef<Parent> {}
                            • Represents a parameter entity reference in a document type definition.

                              A parameter entity reference is structured as follows, where {entity} is the name of the entity:

                              %{entity};

                            constructor

                            constructor(
                            parent: {},
                            validation: boolean,
                            options: IXmlDtdParamEntityRefOptions
                            );

                              property name

                              name: string;
                              • Gets the name of this parameter entity reference.

                              method toString

                              toString: () => string;
                              • Returns an XML string representation of this parameter entity reference.

                              method up

                              up: () => Parent;
                              • Returns the parent of this parameter entity reference.

                              class XmlElement

                              class XmlElement<Parent> {}
                              • Represents an XML element.

                                A sample element is structured as follows, where {name} is the name of the element:

                                <{name} attname="attvalue">
                                <subelem/>
                                <?pitarget picontent?>
                                text
                                </{name}></pre>

                                XML elements can have an unlimited number of attributes, CDATA sections, character references, comments, elements, entity references, processing instructions, and character data.

                                An element with no content will be represented using an empty element tag:

                                <{name}/>

                              constructor

                              constructor(parent: {}, validation: boolean, options: IXmlElementOptions);

                                property name

                                name: string;
                                • Gets the name of this element.

                                method attribute

                                attribute: (options: IXmlAttributeOptions) => XmlAttribute<this>;
                                • Adds an attribute to this element and returns the new attribute.

                                method cdata

                                cdata: (options: IXmlCdataOptions) => XmlCdata<this>;
                                • Adds a CDATA section to this element and returns the new CDATA section.

                                method charData

                                charData: (options: IXmlCharDataOptions) => XmlCharData<this>;
                                • Adds character data to this element and returns the new character data.

                                method charRef

                                charRef: (options: IXmlCharRefOptions) => XmlCharRef<this>;
                                • Adds a character reference to this element and returns the new character reference.

                                method comment

                                comment: (options: IXmlCommentOptions) => XmlComment<this>;
                                • Adds a comment to this element and returns the new comment.

                                method element

                                element: (options: IXmlElementOptions) => XmlElement<this>;
                                • Adds an element to this element and returns the new element.

                                method entityRef

                                entityRef: (options: IXmlEntityRefOptions) => XmlEntityRef<this>;
                                • Adds an entity reference to this element and returns the new entity reference.

                                method procInst

                                procInst: (options: IXmlProcInstOptions) => XmlProcInst<this>;
                                • Adds a processing instruction to this element and returns the new processing instruction.

                                method toString

                                toString: (options?: IStringOptions) => string;
                                • Returns an XML string representation of this element using the specified options.

                                method up

                                up: () => Parent;
                                • Returns the parent of this element.

                                class XmlEntityRef

                                class XmlEntityRef<Parent> {}
                                • Represents an entity reference.

                                  An entity reference is structured as follows, where {name} is the name of the entity to be referenced:

                                  &{entity};

                                constructor

                                constructor(parent: {}, validation: boolean, options: IXmlEntityRefOptions);

                                  property name

                                  name: string;
                                  • Gets the name of this entity reference.

                                  method toString

                                  toString: () => string;
                                  • Returns an XML string representation of this entity reference.

                                  method up

                                  up: () => Parent;
                                  • Returns the parent of this entity reference.

                                  class XmlProcInst

                                  class XmlProcInst<Parent> {}
                                  • Represents a processing instruction.

                                    A processing instruction is structured as follows, where {target} and {content} are the target and content of the processing instruction respectively:

                                    <?{target} {content}?>

                                  constructor

                                  constructor(parent: {}, validation: boolean, options: IXmlProcInstOptions);

                                    property content

                                    content: string;
                                    • Gets the content of this processing instruction.

                                    property target

                                    target: string;
                                    • Gets the target of this processing instruction.

                                    method toString

                                    toString: () => string;
                                    • Returns an XML string representation of this processing instruction.

                                    method up

                                    up: () => Parent;
                                    • Returns the parent of this processing instruction.

                                    Interfaces

                                    interface IStringOptions

                                    interface IStringOptions {}
                                    • Formatting options for the string representation of an XML node.

                                    property doubleQuotes

                                    doubleQuotes?: boolean;
                                    • Whether double quotes or single quotes should be used in XML attributes. By default, single quotes are used.

                                    property indent

                                    indent?: string;
                                    • The indent string used for pretty-printing. The default indent string is four spaces.

                                    property newline

                                    newline?: string;
                                    • The newline string used for pretty-printing. The default newline string is "\n".

                                    property pretty

                                    pretty?: boolean;
                                    • Whether pretty-printing is enabled. By default, pretty-printing is enabled.

                                    interface IXmlAttributeOptions

                                    interface IXmlAttributeOptions {}
                                    • The options used to create a new attribute.

                                    property name

                                    name: string;
                                    • The name of the attribute.

                                    property replaceInvalidCharsInName

                                    replaceInvalidCharsInName?: boolean;
                                    • Whether to replace any invalid characters in the name of the attribute with the Unicode replacement character. By default, this is disabled.

                                    interface IXmlAttributeTextOptions

                                    interface IXmlAttributeTextOptions {}
                                    • The options used to create attribute text.

                                    property charData

                                    charData: string;
                                    • The attribute text.

                                    property replaceInvalidCharsInCharData

                                    replaceInvalidCharsInCharData?: boolean;
                                    • Whether to replace any invalid characters in the attribute text with the Unicode replacement character. By default, this is disabled.

                                    interface IXmlCdataOptions

                                    interface IXmlCdataOptions {}
                                    • The options used to create a CDATA section.

                                    property charData

                                    charData: string;
                                    • The character data of the CDATA section.

                                    property replaceInvalidCharsInCharData

                                    replaceInvalidCharsInCharData?: boolean;
                                    • Whether to replace any invalid characters in the character data of the CDATA section with the Unicode replacement character. By default, this is disabled.

                                    interface IXmlCharDataOptions

                                    interface IXmlCharDataOptions {}
                                    • The options used to create new character data.

                                    property charData

                                    charData: string;
                                    • The character data.

                                    property replaceInvalidCharsInCharData

                                    replaceInvalidCharsInCharData?: boolean;
                                    • Whether to replace any invalid characters in the character data with the Unicode replacement character. By default, this is disabled.

                                    interface IXmlCharRefOptions

                                    interface IXmlCharRefOptions {}
                                    • The options used to create a new character reference.

                                    property char

                                    char: string;
                                    • The character to represent using the reference.

                                    property hex

                                    hex?: boolean;
                                    • Whether to use the hexadecimal or decimal representation for the reference. Defaults to false.

                                    interface IXmlCommentOptions

                                    interface IXmlCommentOptions {}
                                    • The options used to create a new comment.

                                    property charData

                                    charData: string;
                                    • The content of the comment.

                                    property replaceInvalidCharsInCharData

                                    replaceInvalidCharsInCharData?: boolean;
                                    • Whether to replace any invalid characters in the content of the comment with the Unicode replacement character. By default, this is disabled.

                                    interface IXmlDeclOptions

                                    interface IXmlDeclOptions {}
                                    • The options used to create a new declaration.

                                    property encoding

                                    encoding?: string;
                                    • The encoding attribute to be included in the declaration. If defined, this value must be a valid encoding. By default, no encoding attribute is included.

                                    property standalone

                                    standalone?: string;
                                    • The value of the standalone attribute to be included in the declaration. If defined, this value must be "yes" or "no". By default, no standalone attribute is included.

                                    property version

                                    version?: string;
                                    • The XML version to be included in the declaration. If defined, this value must be a valid XML version number. Defaults to "1.0".

                                    interface IXmlDocumentOptions

                                    interface IXmlDocumentOptions {}
                                    • The options used to create a new document.

                                    property validation

                                    validation?: boolean;
                                    • Whether to throw an exception if basic XML validation fails while building the document.

                                    interface IXmlDtdAttlistOptions

                                    interface IXmlDtdAttlistOptions {}
                                    • The options used to create a new attribute-list declaration.

                                    property charData

                                    charData: string;
                                    • The text of the declaration.

                                    interface IXmlDtdElementOptions

                                    interface IXmlDtdElementOptions {}
                                    • The options used to create a new element declaration.

                                    property charData

                                    charData: string;
                                    • The text of the declaration.

                                    interface IXmlDtdEntityOptions

                                    interface IXmlDtdEntityOptions {}
                                    • The options used to create a new entity declaration.

                                    property charData

                                    charData: string;
                                    • The text of the declaration.

                                    interface IXmlDtdNotationOptions

                                    interface IXmlDtdNotationOptions {}
                                    • The options used to create a new notation declaration.

                                    property charData

                                    charData: string;
                                    • The text of the declaration.

                                    interface IXmlDtdOptions

                                    interface IXmlDtdOptions {}
                                    • The options used to create a new document type definition.

                                    property name

                                    name: string;
                                    • The name of the DTD.

                                    property pubId

                                    pubId?: string;
                                    • The public identifier of the DTD, excluding quotation marks. If a public identifier is provided, a system identifier must be provided as well. By default, no public identifier is included.

                                    property sysId

                                    sysId?: string;
                                    • The system identifier of the DTD, excluding quotation marks. By default, no system identifier is included.

                                    interface IXmlDtdParamEntityRefOptions

                                    interface IXmlDtdParamEntityRefOptions {}
                                    • The options used to create a new parameter entity reference.

                                    property name

                                    name: string;
                                    • The name of the entity to be referenced.

                                    interface IXmlElementOptions

                                    interface IXmlElementOptions {}
                                    • The options used to create a new element.

                                    property name

                                    name: string;
                                    • The name of the element.

                                    property replaceInvalidCharsInName

                                    replaceInvalidCharsInName?: boolean;
                                    • Whether to replace any invalid characters in the name of the element with the Unicode replacement character. By default, this is disabled.

                                    property useSelfClosingTagIfEmpty

                                    useSelfClosingTagIfEmpty?: boolean;
                                    • Whether to use a self-closing tag if this element is empty.

                                      For example, use:

                                      <element/>

                                      instead of:

                                      <element></element>

                                      By default, this is enabled.

                                    interface IXmlEntityRefOptions

                                    interface IXmlEntityRefOptions {}
                                    • The options used to create a new entity reference.

                                    property name

                                    name: string;
                                    • The name of the entity to be referenced.

                                    interface IXmlProcInstOptions

                                    interface IXmlProcInstOptions {}
                                    • The options used to create a new processing instruction.

                                    property content

                                    content?: string;
                                    • The data of the processing instruction, or undefined if there is no content.

                                    property target

                                    target: string;
                                    • The target of the processing instruction.

                                    Package Files (19)

                                    Dependencies (0)

                                    No dependencies.

                                    Dev Dependencies (10)

                                    Peer Dependencies (0)

                                    No peer dependencies.

                                    Badge

                                    To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                    You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/xmlcreate.

                                    • Markdown
                                      [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/xmlcreate)
                                    • HTML
                                      <a href="https://www.jsdocs.io/package/xmlcreate"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>