当前位置: 首页>>代码示例>>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;未经允许,请勿转载。