当前位置: 首页>>代码示例>>Java>>正文


Java DocumentBuilderFactory.setCoalescing方法代码示例

本文整理汇总了Java中javax.xml.parsers.DocumentBuilderFactory.setCoalescing方法的典型用法代码示例。如果您正苦于以下问题:Java DocumentBuilderFactory.setCoalescing方法的具体用法?Java DocumentBuilderFactory.setCoalescing怎么用?Java DocumentBuilderFactory.setCoalescing使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.xml.parsers.DocumentBuilderFactory的用法示例。


在下文中一共展示了DocumentBuilderFactory.setCoalescing方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: compare

import javax.xml.parsers.DocumentBuilderFactory; //导入方法依赖的package包/类
@Override
protected boolean compare(File baselineFile, File comparisonFile) {
    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

        factory.setNamespaceAware(true);
        factory.setCoalescing(true);
        factory.setIgnoringElementContentWhitespace(true);
        factory.setIgnoringComments(true);

        DocumentBuilder builder = factory.newDocumentBuilder();
        Document baselineXml = builder.parse(baselineFile);
        Document comparisonXml = builder.parse(comparisonFile);

        baselineXml.normalizeDocument();
        comparisonXml.normalizeDocument();

        XMLUnit.setIgnoreAttributeOrder(true);
        XMLUnit.setIgnoreComments(true);
        XMLUnit.setIgnoreWhitespace(true);

        return XMLUnit.compareXML(baselineXml, comparisonXml).similar();
    } catch (SAXException | IOException | ParserConfigurationException e) {
        throw new TransformationUtilityException("An exception happened when comparing the two XML files", e);
    }
}
 
开发者ID:paypal,项目名称:butterfly,代码行数:27,代码来源:CompareXMLFiles.java

示例2: assertEqualsXml

import javax.xml.parsers.DocumentBuilderFactory; //导入方法依赖的package包/类
/**
 * Assert that the specified XML file has not semantically changed,
 * although it might be identical to the original one due to format
 * changes, comments not being present, etc
 *
 * @param relativeFilePath relative path to file to be evaluated
 * @throws ParserConfigurationException
 * @throws IOException
 * @throws SAXException
 */
protected void assertEqualsXml(String relativeFilePath) throws ParserConfigurationException, IOException, SAXException {
    File originalFile = new File(appFolder, relativeFilePath);
    File transformedFile = new File(transformedAppFolder, relativeFilePath);

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

    factory.setNamespaceAware(true);
    factory.setCoalescing(true);
    factory.setIgnoringElementContentWhitespace(true);
    factory.setIgnoringComments(true);

    DocumentBuilder builder = factory.newDocumentBuilder();
    Document originalXml = builder.parse(originalFile);
    Document transformedXml = builder.parse(transformedFile);

    originalXml.normalizeDocument();
    transformedXml.normalizeDocument();

    XMLUnit.setIgnoreAttributeOrder(true);
    XMLUnit.setIgnoreComments(true);
    XMLUnit.setIgnoreWhitespace(true);

    Assert.assertTrue(XMLUnit.compareXML(originalXml, transformedXml).similar());
}
 
开发者ID:paypal,项目名称:butterfly,代码行数:35,代码来源:TransformationUtilityTestHelper.java

示例3: compareFile

import javax.xml.parsers.DocumentBuilderFactory; //导入方法依赖的package包/类
public void compareFile(String fileLeft, String fileRight) throws SAXException, IOException, ParserConfigurationException, TransformerException {
	DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
	dbf.setNamespaceAware(true);
	dbf.setCoalescing(true);
	dbf.setIgnoringElementContentWhitespace(true);
	dbf.setIgnoringComments(true);

	DocumentBuilder db = dbf.newDocumentBuilder();

	Document doc1 = db.parse(new File(expectedPath + "/" + fileRight + ".xml"));
	doc1.normalizeDocument();

	Document doc2 = db.parse(new File(OUT_DIR + "/" + fileLeft + ".xml"));
	doc2.normalizeDocument();

	assertEquals("Output <" + fileLeft + "> is not the same as expected output <" +
			fileRight + ">", 
			docToString(doc1), 
			docToString(doc2));
}
 
开发者ID:RJMillerLab,项目名称:ibench,代码行数:21,代码来源:AbstractCheckExpectedOutputTester.java

示例4: initializePool

import javax.xml.parsers.DocumentBuilderFactory; //导入方法依赖的package包/类
/**
 * Initializes the pool with a new set of configuration options.
 * 
 * @throws XMLParserException thrown if there is a problem initialzing the pool
 */
protected synchronized void initializePool() throws XMLParserException {
    if (!dirtyBuilderConfiguration) {
        // in case the pool was initialized by some other thread
        return;
    }

    DocumentBuilderFactory newFactory = DocumentBuilderFactory.newInstance();
    setAttributes(newFactory, builderAttributes);
    setFeatures(newFactory, builderFeatures);
    newFactory.setCoalescing(coalescing);
    newFactory.setExpandEntityReferences(expandEntityReferences);
    newFactory.setIgnoringComments(ignoreComments);
    newFactory.setIgnoringElementContentWhitespace(ignoreElementContentWhitespace);
    newFactory.setNamespaceAware(namespaceAware);
    newFactory.setSchema(schema);
    newFactory.setValidating(dtdValidating);
    newFactory.setXIncludeAware(xincludeAware);

    poolVersion++;
    dirtyBuilderConfiguration = false;
    builderFactory = newFactory;
    builderPool.clear();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:29,代码来源:BasicParserPool.java

示例5: parseXmlFile

import javax.xml.parsers.DocumentBuilderFactory; //导入方法依赖的package包/类
public Document parseXmlFile(String fileName) throws Exception {
    System.out.println("Parsing XML file... " + fileName);
    DocumentBuilder docBuilder = null;
    Document doc = null;
    DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
    docBuilderFactory.setCoalescing(true);
    docBuilderFactory.setXIncludeAware(true);
    System.out.println("Include: " + docBuilderFactory.isXIncludeAware());
    docBuilderFactory.setNamespaceAware(true);
    docBuilderFactory.setExpandEntityReferences(true);

    docBuilder = docBuilderFactory.newDocumentBuilder();

    File sourceFile = new File(fileName);
    doc = docBuilder.parse(sourceFile);

    System.out.println("XML file parsed");
    return doc;

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:Bug6794483Test.java

示例6: testAttributeCaching

import javax.xml.parsers.DocumentBuilderFactory; //导入方法依赖的package包/类
@Test
public void testAttributeCaching() {
    File xmlFile = new File(getClass().getResource("Bug6879614.xml").getFile());
    DocumentBuilderFactory _documentBuilderFactory = DocumentBuilderFactory.newInstance();
    _documentBuilderFactory.setValidating(false);
    _documentBuilderFactory.setIgnoringComments(true);
    _documentBuilderFactory.setIgnoringElementContentWhitespace(true);
    _documentBuilderFactory.setCoalescing(true);
    _documentBuilderFactory.setExpandEntityReferences(true);
    _documentBuilderFactory.setNamespaceAware(true);
    DocumentBuilder _documentBuilder = null;
    try {
        _documentBuilder = _documentBuilderFactory.newDocumentBuilder();
    } catch (ParserConfigurationException pce) {
        pce.printStackTrace();
    }

    Document xmlDoc = null;
    try {
        xmlDoc = _documentBuilder.parse(xmlFile);
        if (xmlDoc == null) {
            System.out.println("Hello!!!, there is a problem here");
        } else {
            System.out.println("Good, the parsing went through fine.");
        }
    } catch (SAXException se) {
        se.printStackTrace();
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:32,代码来源:Bug6879614Test.java

示例7: compareDocumentWithGold

import javax.xml.parsers.DocumentBuilderFactory; //导入方法依赖的package包/类
/**
 * Compare contents of golden file with test output file by their document
 * representation.
 * Here we ignore the white space and comments. return true if they're
 * lexical identical.
 * @param goldfile Golden output file name.
 * @param resultFile Test output file name.
 * @return true if two file's document representation are identical.
 *         false if two file's document representation are not identical.
 * @throws javax.xml.parsers.ParserConfigurationException if the
 *         implementation is not available or cannot be instantiated.
 * @throws SAXException If any parse errors occur.
 * @throws IOException if an I/O error occurs reading from the file or a
 *         malformed or unmappable byte sequence is read .
 */
public static boolean compareDocumentWithGold(String goldfile, String resultFile)
        throws ParserConfigurationException, SAXException, IOException {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);
    factory.setCoalescing(true);
    factory.setIgnoringElementContentWhitespace(true);
    factory.setIgnoringComments(true);
    DocumentBuilder db = factory.newDocumentBuilder();

    Document goldD = db.parse(Paths.get(goldfile).toFile());
    goldD.normalizeDocument();
    Document resultD = db.parse(Paths.get(resultFile).toFile());
    resultD.normalizeDocument();
    return goldD.isEqualNode(resultD);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:31,代码来源:JAXPTestUtilities.java

示例8: getW3CXmlDoc

import javax.xml.parsers.DocumentBuilderFactory; //导入方法依赖的package包/类
/**
 *  Gets a org.w3c.dom.Document for this record. This method is optimized to create only one DOM when
 *  accessed multiple times for the same XMLDocReader.
 *
 * @return    A org.w3c.dom.Document, or null if unable to read.
 */
public org.w3c.dom.Document getW3CXmlDoc() {
	if (w3cXmlDoc != null)
		return w3cXmlDoc;

	DocumentBuilderFactory docfactory
		 = DocumentBuilderFactory.newInstance();
	docfactory.setCoalescing(true);
	docfactory.setExpandEntityReferences(true);
	docfactory.setIgnoringComments(true);

	docfactory.setNamespaceAware(true);

	// We must set validation false since jdk1.4 parser
	// doesn't know about schemas.
	docfactory.setValidating(false);

	// Ignore whitespace doesn't work unless setValidating(true),
	// according to javadocs.
	docfactory.setIgnoringElementContentWhitespace(false);
	try {
		DocumentBuilder docbuilder = docfactory.newDocumentBuilder();
		w3cXmlDoc = docbuilder.parse(getXml());
	} catch (Throwable e) {
		return null;
	}
	return w3cXmlDoc;
}
 
开发者ID:NCAR,项目名称:joai-project,代码行数:34,代码来源:XMLDocReader.java

示例9: parseXmlStream

import javax.xml.parsers.DocumentBuilderFactory; //导入方法依赖的package包/类
/**
 * Parses the xml stream.
 *
 * @param pInputSource the input source
 * @return the document
 * @throws Exception the in case a problem occurred.
 */
public static Document parseXmlStream(InputSource pInputSource) throws Exception {
    DocumentBuilderFactory tFactory = DocumentBuilderFactory.newInstance();
    tFactory.setIgnoringComments(true);
    tFactory.setCoalescing(true); // Convert CDATA to Text nodes
    tFactory.setNamespaceAware(false); // No namespaces: this is default
    tFactory.setValidating(false); // Don't validate DTD: also default
    DocumentBuilder tParser = tFactory.newDocumentBuilder();
    return tParser.parse(pInputSource);
}
 
开发者ID:cinnober,项目名称:ciguan,代码行数:17,代码来源:AsXmlTool.java

示例10: getDocument

import javax.xml.parsers.DocumentBuilderFactory; //导入方法依赖的package包/类
public static Document getDocument(InputStream pStream) throws Exception {
	DocumentBuilderFactory tFactory = DocumentBuilderFactory.newInstance();
	tFactory.setIgnoringComments(true);
	tFactory.setCoalescing(true); // Convert CDATA to Text nodes
	tFactory.setNamespaceAware(false); // No namespaces: this is default
	tFactory.setValidating(false); // Don't validate DTD: also default

	DocumentBuilder tParser = tFactory.newDocumentBuilder();

	return tParser.parse(pStream);
}
 
开发者ID:cinnober,项目名称:ciguan,代码行数:12,代码来源:ConfigTestUtil.java

示例11: initialValue

import javax.xml.parsers.DocumentBuilderFactory; //导入方法依赖的package包/类
protected DocumentBuilderFactory initialValue() {
	try {
		DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
		documentBuilderFactory.setNamespaceAware(true);
		documentBuilderFactory.setCoalescing(true);
		documentBuilderFactory.setFeature("http://apache.org/xml/features/validation/schema/normalized-value", false);
		
		return documentBuilderFactory;
	} catch (ParserConfigurationException e) {
		e.printStackTrace();
		return null;
	}
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:14,代码来源:SchemaUtils.java

示例12: initializeFactory

import javax.xml.parsers.DocumentBuilderFactory; //导入方法依赖的package包/类
/**
 * Initializes the pool with a new set of configuration options.
 * 
 * @throws XMLParserException thrown if there is a problem initialzing the pool
 */
protected synchronized void initializeFactory() throws XMLParserException {
    DocumentBuilderFactory newFactory = DocumentBuilderFactory.newInstance();
    setAttributes(newFactory, builderAttributes);
    setFeatures(newFactory, builderFeatures);
    newFactory.setCoalescing(coalescing);
    newFactory.setExpandEntityReferences(expandEntityReferences);
    newFactory.setIgnoringComments(ignoreComments);
    newFactory.setIgnoringElementContentWhitespace(ignoreElementContentWhitespace);
    newFactory.setNamespaceAware(namespaceAware);
    newFactory.setSchema(schema);
    newFactory.setValidating(dtdValidating);
    newFactory.setXIncludeAware(xincludeAware);
    builderFactory = newFactory;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:20,代码来源:StaticBasicParserPool.java

示例13: load

import javax.xml.parsers.DocumentBuilderFactory; //导入方法依赖的package包/类
public static Document load(String paramString) throws Exception {
	DocumentBuilderFactory localDocumentBuilderFactory = DocumentBuilderFactory.newInstance();
	localDocumentBuilderFactory.setIgnoringComments(false);
	localDocumentBuilderFactory.setIgnoringElementContentWhitespace(false);
	localDocumentBuilderFactory.setValidating(false);
	localDocumentBuilderFactory.setCoalescing(true);
	DocumentBuilder localDocumentBuilder = localDocumentBuilderFactory.newDocumentBuilder();
	return localDocumentBuilder.parse(paramString);
}
 
开发者ID:inspingcc,项目名称:LibraSock,代码行数:10,代码来源:XmlUtils.java

示例14: loadString

import javax.xml.parsers.DocumentBuilderFactory; //导入方法依赖的package包/类
public static Document loadString(String paramString) throws Exception {
	DocumentBuilderFactory localDocumentBuilderFactory = DocumentBuilderFactory.newInstance();
	localDocumentBuilderFactory.setIgnoringComments(false);
	localDocumentBuilderFactory.setIgnoringElementContentWhitespace(false);
	localDocumentBuilderFactory.setValidating(false);
	localDocumentBuilderFactory.setCoalescing(false);
	DocumentBuilder localDocumentBuilder = localDocumentBuilderFactory.newDocumentBuilder();
	char[] arrayOfChar = new char[paramString.length()];
	paramString.getChars(0, paramString.length(), arrayOfChar, 0);
	InputSource localInputSource = new InputSource(new CharArrayReader(arrayOfChar));
	return localDocumentBuilder.parse(localInputSource);
}
 
开发者ID:inspingcc,项目名称:LibraSock,代码行数:13,代码来源:XmlUtils.java

示例15: blankDocument

import javax.xml.parsers.DocumentBuilderFactory; //导入方法依赖的package包/类
public static Document blankDocument(String paramString) throws Exception {
	DocumentBuilderFactory localDocumentBuilderFactory = DocumentBuilderFactory.newInstance();
	localDocumentBuilderFactory.setIgnoringComments(false);
	localDocumentBuilderFactory.setIgnoringElementContentWhitespace(false);
	localDocumentBuilderFactory.setValidating(false);
	localDocumentBuilderFactory.setCoalescing(false);
	DocumentBuilder localDocumentBuilder = localDocumentBuilderFactory.newDocumentBuilder();
	Document localDocument = localDocumentBuilder.newDocument();
	Element localElement = localDocument.createElement(paramString);
	localDocument.appendChild(localElement);
	return localDocument;
}
 
开发者ID:inspingcc,项目名称:LibraSock,代码行数:13,代码来源:XmlUtils.java


注:本文中的javax.xml.parsers.DocumentBuilderFactory.setCoalescing方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。