Example usage for org.dom4j DocumentType setElementName

List of usage examples for org.dom4j DocumentType setElementName

Introduction

In this page you can find the example usage for org.dom4j DocumentType setElementName.

Prototype

void setElementName(String elementName);

Source Link

Document

This method is the equivalent to the #setName method.

Usage

From source file:com.cladonia.xml.XMLUtilities.java

License:Open Source License

/**
 * Sets the XML DOCTYPE//  w  ww.ja  va  2 s. co  m
 *
 * @param document The Exchanger document
 * @param name The DOCTYPE name (should be root element's name)
 * @param type The type (SYSTEM,PUBLIC or INTERNAL)
 * @param publicID The publicID 
 * @param systemID The systemID
 * 
 */
public static void setXMLDoctype(ExchangerDocument document, String name, String type, String publicID,
        String systemID) {
    XDocument xdoc = document.getDocument();
    DocumentType dt = xdoc.getDocType();

    if (dt != null) {
        // update existing Doctype
        dt.setElementName(name);
        if (type.equals(INTERNAL)) {
            dt.setPublicID(null);
            dt.setSystemID(null);
        } else if (type.equals(SYSTEM)) {
            dt.setPublicID(null);
            dt.setSystemID(systemID);
        } else {
            dt.setPublicID(publicID);
            dt.setSystemID(systemID);

        }
    } else {
        // add new doctype
        if (type.equals(INTERNAL)) {
            xdoc.addDocType(name, null, null);
        } else if (type.equals(SYSTEM)) {
            xdoc.addDocType(name, null, systemID);
        } else {
            xdoc.addDocType(name, publicID, systemID);
        }

    }
}

From source file:com.tedi.engine.XMLOutput.java

License:Open Source License

/**
 * Set the system id.// w  w w  .  j a v a2s .  c  o  m
 * 
 * @param rootStr
 *            Root string
 */
private void setSystemID(String rootStr) {

    if (logger.isDebugEnabled()) {
        logger.debug("Setting system ID to the element- " + rootStr);
    }

    // set systemID
    if (dtd == null || dtd.length() == 0)
        return;
    String systemId = "";
    // if system ID is a full URL, use it, else just use DTD name
    try {
        absoluteDTD_URL = new URL(dtd);
        systemId = absoluteDTD_URL.toString();
    } catch (MalformedURLException me) {
        systemId = Utils.getFileComponent(dtd);
        try {
            absoluteDTD_URL = new File("dtd", systemId).toURL();
        } catch (Exception e) {
            String errStr = e.getMessage();
            logger.error(errStr);
            throw new RuntimeException(e);
        }
    }
    if (dtd.toLowerCase().endsWith("dtd")) {
        doc.addDocType(null, null, null);
        DocumentType type = doc.getDocType();
        type.setSystemID(systemId);
        type.setElementName(rootStr);
    }
}

From source file:org.olat.ims.qti.editor.beecom.objects.QTIDocument.java

License:Apache License

/**
 * Get the structure as an XML Document.
 * /*from w  w w . ja v  a2s .co  m*/
 * @return XML Document.
 */
public Document getDocument() {
    final Document tmp = DocumentHelper.createDocument();
    final DocumentType type = new DOMDocumentType();
    type.setElementName(DOCUMENT_ROOT);
    type.setSystemID(DOCUMENT_DTD);

    tmp.setDocType(type);
    final Element questestinterop = tmp.addElement(DOCUMENT_ROOT);
    this.assessment.addToElement(questestinterop);
    return tmp;
}