This method creates the response XML element.

@param document
The {@link Document} instance for the response.
@return The created XML {@link Element}.
334837
private static Element createResultElement(final Document document) {
        return document.createElementNS(JaxRxConstants.URL, JaxRxConstants.JAXRX + ":results");
    }
318109
protected static Document createDocument(String document) throws PolicyIndexException {

        // parse policy document and create dom
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);
        DocumentBuilder builder;
        try {
            builder = factory.newDocumentBuilder();
            Document doc = builder.parse(new InputSource(new StringReader(document)));
            return doc;
        } catch (ParserConfigurationException e) {
            throw new PolicyIndexException(e);
        } catch (SAXException e) {
            throw new PolicyIndexException(e);
        } catch (IOException e) {
            throw new PolicyIndexException(e);
        }
    }
658478
public static Element[] toElementArray(Document doc, Object o) throws PageException {
	// Node[]
	if (o instanceof Node[]) {
	    Node[] nodes = (Node[]) o;
	    if (_isAllOfSameType(nodes, Node.ELEMENT_NODE)) return (Element[]) nodes;

	    Element[] elements = new Element[nodes.length];
	    for (int i = 0; i < nodes.length; i++) {
		elements[i] = toElement(doc, nodes[i]);
	    }
	    return elements;
	}
	// Collection
	else if (o instanceof Collection) {
	    Collection coll = (Collection) o;
	    Iterator<Object> it = coll.valueIterator();
	    List<Element> elements = new ArrayList<Element>();
	    while (it.hasNext()) {
		elements.add(toElement(doc, it.next()));
	    }
	    return elements.toArray(new Element[elements.size()]);
	}
	// Node Map and List
	Node[] nodes = _toNodeArray(doc, o);
	if (nodes != null) return toElementArray(doc, nodes);
	// Single Text Node
	try {
	    return new Element[] { toElement(doc, o) };
	}
	catch (ExpressionException e) {
	    throw new XMLException("can't cast Object of type " + Caster.toClassName(o) + " to a XML Element Array");
	}
    }
1155348
public static void transformDocumentToXml(DomDocument document, StreamResult result) {
    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    try {
      Transformer transformer = transformerFactory.newTransformer();
      transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
      transformer.setOutputProperty(OutputKeys.INDENT, "yes");
      transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");

      synchronized(document) {
        transformer.transform(document.getDomSource(), result);
      }
    } catch (TransformerConfigurationException e) {
      throw new ModelIoException("Unable to create a transformer for the model", e);
    } catch (TransformerException e) {
      throw new ModelIoException("Unable to transform model to xml", e);
    }
  }
503596
public int addDocument(String document) {
    if (root().getNumberOfChildren() >= 0) {
      throw new IllegalStateException("Tree sorting has begun");
    }
    final int index;
    synchronized (this) {
      index = documents.size();
      documents.add(document);
    }
    cursors.addAll(
      IntStream.range(0, document.length() + 1).mapToObj(i -> new CursorData(index, i)).collect(Collectors.toList()));
    nodes.update(0, node -> node.setCursorCount(cursors.length()));
    return index;
  }
1205972
Document createDocument(NodeDataIndexing node) throws RepositoryException
   {
      Document aDoc = null;
      if (volatileIndex != null)
      {
         aDoc = volatileIndex.getAggregateIndexes(node.getIdentifier());
      }
      if (aDoc == null)
      {
         aDoc = handler.createDocument(node, nsMappings, version, true, volatileIndex);
      }
      return aDoc;
   }
538990
public Document generateXml(I_CmsXmlConfiguration configuration) {

        // create a new document
        Document result = DocumentHelper.createDocument();

        // set the document type
        DOMDocumentType docType = new DOMDocumentType();
        docType.setElementName(N_ROOT);
        docType.setSystemID(configuration.getDtdUrlPrefix() + configuration.getDtdFilename());
        result.setDocType(docType);

        Element root = result.addElement(N_ROOT);
        // start the XML generation
        configuration.generateXml(root);

        // return the resulting document
        return result;
    }
739406
public static Document toDocument(String xml) throws SAXException {
		try {
			return toDocument(new StringReader(xml));
		} catch (IOException e) {
			//reading from string
			throw new RuntimeException(e);
		}
	}
635569
public Document doc() throws IOException {
		// if the stream has already been read, use the text format
		InputSource is;
		if (document == null) {
			if (text == null) {
				is = new InputSource(inputStream);
				is.setEncoding(getCharSet().name());
			} else {
				is = new InputSource(new StringReader(text));
			}
			try {
				document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(is);
			} catch (SAXException e) {
				e.printStackTrace();
			} catch (ParserConfigurationException e) {
				e.printStackTrace();
			}
			inputStream.close();
		}
		return document;
	}
733533
public static Result ok(Document document) {
        return status(Result.OK).render(document).as(MimeTypes.XML);
    }
539139
private static List<String> getElementsId(Document document) {
        List<String> result = new ArrayList<String>();

        List<Element> elementList = getElements(document);

        result = getElementsId(elementList);

        return result;
    }
2251
public static String toXml(com.greenpepper.document.Document document) throws IOException
	{
		StringWriter sw = new StringWriter();

		XmlReport xmlReport = XmlReport.newInstance("");
		xmlReport.generate( document );
		xmlReport.printTo( sw );

		return sw.toString();
	}
815238
public static Layout parseDocument(Document document) {
        return new Layout(instance.parseChildren(document, null, Tag.LAYOUT));
    }
553631
@XmlElementDecl(namespace = PROV_NS, name = "document")
    public JAXBElement<Document> createDocument(Document value) {
        return new JAXBElement<Document>(_Document_QNAME, Document.class, null, value);
    }
942452
public Document createDOM(PDDocument doc) throws IOException
    {
        /* We call the original PDFTextStripper.writeText but nothing should
           be printed actually because our processing methods produce no output.
           They create the DOM structures instead */
        super.writeText(doc, new OutputStreamWriter(System.out));
        return this.doc;
    }
593877
@Override
    public <A> A fromXML(Document document, Class<A> clazz) {
        return fromXML(stringify(document), clazz);
    }
1258092
public static Metadata fromXml(Document domainXml) {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat(XML_DATE_FORMAT);
            Element metadata = getMetadataElement(domainXml);
            if (metadata == null) {
                return null;
            }
            Namespace ns = Namespace.getNamespace(METADATA_NS_V1);
            Element ocMetadata = metadata.getChild(OVERCAST_METADATA, ns);
            if (ocMetadata == null) {
                return null;
            }
            String parentDomain = getElementText(ocMetadata, PARENT_DOMAIN, ns);
            String creationTime = getElementText(ocMetadata, CREATION_TIME, ns);
            Date date = sdf.parse(creationTime);

            if(ocMetadata.getChild(PROVISIONED_WITH, ns) != null) {
                String provisionedWith = getElementText(ocMetadata, PROVISIONED_WITH, ns);
                String checkSum = getElementText(ocMetadata, PROVISIONED_CHECKSUM, ns);

                return new Metadata(parentDomain, provisionedWith, checkSum, date);
            }
            return new Metadata(parentDomain, date);
        } catch (ParseException e) {
            throw new IllegalArgumentException("Invalid date in metadata on domain", e);
        }
    }