Skip to content

xml_new_document creates only a new document without a root node. In most cases you should instead use xml_new_root, which creates a new document and assigns the root node in one step.


xml_new_document(version = "1.0", encoding = "UTF-8")

  .copy = inherits(.value, "xml_node"),
  .version = "1.0",
  .encoding = "UTF-8"



The version number of the document.


The character encoding to use in the document. The default encoding is ‘UTF-8’. Available encodings are specified at


node to insert.


If named attributes or namespaces to set on the node, if unnamed text to assign to the node.


whether to copy the .value before replacing. If this is FALSE then the node will be moved from it's current location.


The version number of the document, passed to xml_new_document(version).


The encoding of the document, passed to xml_new_document(encoding).


A xml_document object.