當前位置: 首頁>>代碼示例>>Java>>正文


Java Document.normalize方法代碼示例

本文整理匯總了Java中org.w3c.dom.Document.normalize方法的典型用法代碼示例。如果您正苦於以下問題:Java Document.normalize方法的具體用法?Java Document.normalize怎麽用?Java Document.normalize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.w3c.dom.Document的用法示例。


在下文中一共展示了Document.normalize方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: writeApplicationXml

import org.w3c.dom.Document; //導入方法依賴的package包/類
/**
    * Writes the modified application back out to the file system.
    * 
    * @param doc
    *            The application.xml DOM Document
    * @throws org.apache.tools.ant.DeployException
    *             in case of any problems
    */
   protected void writeApplicationXml(final Document doc) throws DeployException {
System.out.println("Writing out doc " + doc);
try {
    doc.normalize();

    // Prepare the DOM document for writing
    DOMSource source = new DOMSource(doc);

    // Prepare the output file
    StreamResult result = new StreamResult(applicationXmlPath);

    // Write the DOM document to the file
    // Get Transformer
    Transformer xformer = TransformerFactory.newInstance().newTransformer();
    // Write to a file
    xformer.transform(source, result);
} catch (TransformerException tex) {
    throw new DeployException("Error writing out modified application xml", tex);
}
   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:29,代碼來源:UpdateApplicationXmlTask.java

示例2: writeWebXml

import org.w3c.dom.Document; //導入方法依賴的package包/類
/**
    * Writes the modified web.xml back out to war file
    * 
    * @param doc
    *            The application.xml DOM Document
    * @throws org.apache.tools.ant.DeployException
    *             in case of any problems
    */
   protected void writeWebXml(final Document doc, final OutputStream outputStream) throws DeployException {
try {
    doc.normalize();

    // Prepare the DOM document for writing
    DOMSource source = new DOMSource(doc);

    // Prepare the output file
    StreamResult result = new StreamResult(outputStream);

    // Write the DOM document to the file
    // Get Transformer
    Transformer xformer = TransformerFactory.newInstance().newTransformer();
    // Write to a file
    xformer.transform(source, result);
} catch (TransformerException tex) {
    throw new DeployException("Error writing out modified web xml ", tex);
}
   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:28,代碼來源:UpdateWarTask.java

示例3: readXml

import org.w3c.dom.Document; //導入方法依賴的package包/類
/**
 * Reads (well-formed) list XML and checks it for basic validity:
 * root node must be <code>&lt;rootTagName&gt;</code>
 */
private Document readXml(Reader reader) throws IOException, SAXException {
    try {
        Document xml = DocumentBuilderFactory.newInstance().newDocumentBuilder()
                .parse(new InputSource(reader));
        xml.normalize();
        
        if (!xml.getDocumentElement().getNodeName().equals(rootTagName)) {
            throw new IOException(Messages.XmlStringList_root_name_invalid);
        }
        
        return xml;
    } catch (ParserConfigurationException ex) {
        throw new IOException(ex);
    }
}
 
開發者ID:pgcodekeeper,項目名稱:pgcodekeeper,代碼行數:20,代碼來源:XmlStringList.java

示例4: writeXml

import org.w3c.dom.Document; //導入方法依賴的package包/類
private static void writeXml(final Document doc, final File file) throws IOException {
    doc.normalize();

    final TransformerFactory transformerFactory = TransformerFactory.newInstance(XML_FACTORY, null);

    try {
        final Transformer transformer = transformerFactory.newTransformer();
        transformer.setOutputProperty(OutputKeys.METHOD, "xml");
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
        transformer.transform(new DOMSource(doc), new StreamResult(file));
    } catch (final TransformerException ex) {
        throw new IOException(ex.getMessage(), ex);
    }
}
 
開發者ID:minijax,項目名稱:minijax,代碼行數:17,代碼來源:LiquibaseHelper.java

示例5: load

import org.w3c.dom.Document; //導入方法依賴的package包/類
public static Document load(String filename) {
    Document document = null;
    try {
    	// 1.得到DOM解析器的工廠實例
        DocumentBuilderFactory factory = DocumentBuilderFactory
                .newInstance();
     // 2.從DOM工廠裏獲取DOM解析器
        DocumentBuilder builder = factory.newDocumentBuilder();
     // 3.解析XML文檔,得到document,即DOM樹
        document = builder.parse(new File(filename));
      //Document對象調用normalize(),可以去掉XML文檔中作為格式化內容的空白而映射在DOM樹中的不必要的Text Node對象。
      //否則你得到的DOM樹可能並不如你所想象的那樣。特別是在輸出的時候,這個normalize()更為有用。 
        document.normalize();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return document;
}
 
開發者ID:yulele166,項目名稱:pub-service,代碼行數:19,代碼來源:PaseXml.java

示例6: removeWhitespace

import org.w3c.dom.Document; //導入方法依賴的package包/類
private void removeWhitespace(Document document) throws XPathExpressionException {
	document.normalize();
	XPath xPath = XPathFactory.newInstance().newXPath();
	NodeList nodeList = (NodeList) xPath.evaluate("//text()[normalize-space()='']",
			document,
			XPathConstants.NODESET);

	for (int i = 0; i < nodeList.getLength(); ++i) {
		Node node = nodeList.item(i);
		node.getParentNode().removeChild(node);
	}
}
 
開發者ID:CMSgov,項目名稱:qpp-conversion-tool,代碼行數:13,代碼來源:QrdaGenerator.java

示例7: compare

import org.w3c.dom.Document; //導入方法依賴的package包/類
/**
 * Compares by DOM. Ordering requirements will be respected.
 */
boolean compare(Document document1, Document document2)
{
	// Make sure adjacent text nodes are combined
	document1.normalize();
	document2.normalize();

	return compareChildren(document1.getDocumentElement(), document2.getDocumentElement());
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:12,代碼來源:XMLCompare.java

示例8: readDocument

import org.w3c.dom.Document; //導入方法依賴的package包/類
private static @NotNull Element readDocument(@NotNull File file) throws ParserConfigurationException, IOException, SAXException {
	final DocumentBuilder builder  = factory.newDocumentBuilder();
	final Document        document = builder.parse(file);

	document.normalize();

	return document.getDocumentElement();
}
 
開發者ID:Sxtanna,項目名稱:dependency-loader,代碼行數:9,代碼來源:Xmls.java


注:本文中的org.w3c.dom.Document.normalize方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。