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


Java DocumentBuilderFactory.setIgnoringComments方法代码示例

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


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

示例1: testDOM

import javax.xml.parsers.DocumentBuilderFactory; //导入方法依赖的package包/类
@Test
public void testDOM() throws ParserConfigurationException, SAXException, IOException {
    InputStream xmlFile = getClass().getResourceAsStream("Bug6564400.xml");

    // Set the options on the DocumentFactory to remove comments, remove
    // whitespace
    // and validate against the schema.
    DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
    docFactory.setIgnoringComments(true);
    docFactory.setIgnoringElementContentWhitespace(true);
    docFactory.setSchema(schema);

    DocumentBuilder parser = docFactory.newDocumentBuilder();
    Document xmlDoc = parser.parse(xmlFile);

    boolean ok = dump(xmlDoc, true);
    Assert.assertEquals(true, ok);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:Bug6564400.java

示例2: 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

示例3: 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

示例4: readXml

import javax.xml.parsers.DocumentBuilderFactory; //导入方法依赖的package包/类
/** Read XML as DOM.
 */
public static Document readXml(InputStream is)
    throws SAXException, IOException, ParserConfigurationException
{
    DocumentBuilderFactory dbf =
        DocumentBuilderFactory.newInstance();

    dbf.setValidating(false);
    dbf.setIgnoringComments(false);
    dbf.setIgnoringElementContentWhitespace(true);
    //dbf.setCoalescing(true);
    //dbf.setExpandEntityReferences(true);

    DocumentBuilder db = null;
    db = dbf.newDocumentBuilder();
    db.setEntityResolver( new NullResolver() );

    // db.setErrorHandler( new MyErrorHandler());

    Document doc = db.parse(is);
    return doc;
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:24,代码来源:DomUtil.java

示例5: GlueSettingsParser

import javax.xml.parsers.DocumentBuilderFactory; //导入方法依赖的package包/类
public GlueSettingsParser() throws ResourceParseException {
	try {
		setTypeMappings();
		setStyleMappings();
		DocumentBuilderFactory factory = DocumentBuilderFactory
				.newInstance();
		factory.setIgnoringElementContentWhitespace(true);
		factory.setIgnoringComments(true);
		root = factory.newDocumentBuilder()
				.parse(AjLatexMath.getAssetManager().open(RESOURCE_NAME))
				.getDocumentElement();
		parseGlueTypes();
	} catch (Exception e) { // JDOMException or IOException
		throw new XMLResourceParseException(RESOURCE_NAME, e);
	}
}
 
开发者ID:daquexian,项目名称:FlexibleRichTextView,代码行数:17,代码来源:GlueSettingsParser.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: 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

示例8: 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

示例9: inititalizeParser

import javax.xml.parsers.DocumentBuilderFactory; //导入方法依赖的package包/类
/**
 * Initializer method of the parser. Initializes the document instance.
 * @param inputStream - configuration file input stream to be parsed
 * @param systemId Provide a base for resolving relative URIs.
 * @throws IOException - if the streamed object is not found
 */
private void inititalizeParser( InputStream inputStream, String systemId ) throws IOException,
                                                                           SAXException,
                                                                           ParserConfigurationException {

    DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    documentBuilderFactory.setIgnoringElementContentWhitespace(true);
    documentBuilderFactory.setNamespaceAware(true);
    documentBuilderFactory.setValidating(false);
    documentBuilderFactory.setIgnoringComments(true);

    try {
        // skip DTD validation
        documentBuilderFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar",
                                          false);
        documentBuilderFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd",
                                          false);

        DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
        mDocument = documentBuilder.parse(inputStream, systemId);

        /* NOTE:
         * XSD Validation process is performed after the XML parsing (not during), 
         * because when we do it during the parsing, the XML Document element adds attributes which has a default values in the XSD.
         * In our case for example, it adds lock="true" for all 'table' elements and when the database is oracle
         * we log WARN messages. It's wrong. That's why we do the validation after parsing the XML.
         */

        ConfigurationParser.class.getClassLoader().getResource("agent_descriptor.xsd");

        // XSD Validation
        SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        Schema schema = schemaFactory.newSchema(this.getClass()
                                                    .getClassLoader()
                                                    .getResource("agent_descriptor.xsd"));
        Validator validator = schema.newValidator();
        validator.validate(new DOMSource(mDocument));

    } catch (ParserConfigurationException pce) {
        log.error(pce.getMessage());
        throw pce;
    } catch (IOException ioe) {
        log.error(ioe.getMessage());
        throw ioe;
    } catch (SAXException saxe) {
        log.error(saxe.getMessage());
        throw saxe;
    }
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:55,代码来源:ConfigurationParser.java

示例10: loadXML

import javax.xml.parsers.DocumentBuilderFactory; //导入方法依赖的package包/类
public void loadXML() throws SAXException, IOException, ParserConfigurationException
{
	final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
	factory.setValidating(false);
	factory.setIgnoringComments(true);
	final File file = new File(Config.DATAPACK_ROOT + "/data/" + MPCS_FILE);
	if (file.exists())
	{
		int defaultPriceConfigId;
		final Document doc = factory.newDocumentBuilder().parse(file);
		
		Node n = doc.getDocumentElement();
		final Node dpcNode = n.getAttributes().getNamedItem("defaultPriceConfig");
		if (dpcNode == null)
		{
			throw new IllegalStateException("merchantPriceConfig must define an 'defaultPriceConfig'");
		}
		defaultPriceConfigId = Integer.parseInt(dpcNode.getNodeValue());
		
		MerchantPriceConfig mpc;
		for (n = n.getFirstChild(); n != null; n = n.getNextSibling())
		{
			mpc = parseMerchantPriceConfig(n);
			if (mpc != null)
			{
				_mpcs.put(mpc.getId(), mpc);
			}
		}
		
		final MerchantPriceConfig defaultMpc = this.getMerchantPriceConfig(defaultPriceConfigId);
		if (defaultMpc == null)
		{
			throw new IllegalStateException("'defaultPriceConfig' points to an non-loaded priceConfig");
		}
		_defaultMpc = defaultMpc;
	}
}
 
开发者ID:rubenswagner,项目名称:L2J-Global,代码行数:38,代码来源:MerchantPriceConfigTable.java

示例11: TeXFormulaSettingsParser

import javax.xml.parsers.DocumentBuilderFactory; //导入方法依赖的package包/类
public TeXFormulaSettingsParser(InputStream file, String name)
		throws ResourceParseException, IOException {
	try {
		DocumentBuilderFactory factory = DocumentBuilderFactory
				.newInstance();
		factory.setIgnoringElementContentWhitespace(true);
		factory.setIgnoringComments(true);
		root = factory.newDocumentBuilder().parse(file)
				.getDocumentElement();
	} catch (Exception e) { // JDOMException or IOException
		throw new XMLResourceParseException(name, e);
	}
	file.close();
}
 
开发者ID:daquexian,项目名称:FlexibleRichTextView,代码行数:15,代码来源:TeXFormulaSettingsParser.java

示例12: 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

示例13: loadXmlResource

import javax.xml.parsers.DocumentBuilderFactory; //导入方法依赖的package包/类
/**
 * Load XML resource.
 *
 * @param pResource the resource
 * @return the document
 * @throws Exception in case a problem occurred
 */
public static Document loadXmlResource(String pResource) throws Exception {

    String tResource = (pResource.startsWith("/") ? pResource.substring(1) : pResource);
    InputStream tStream = null;

    /**
     * Try own class loader first, then the system class loader
     */
    tStream = AsXmlTool.class.getClassLoader().getResourceAsStream(tResource);
    if (tStream == null) {
        tStream = ClassLoader.getSystemResourceAsStream(tResource);
    }
    if (tStream == null) {
        tStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(tResource);
    }        
    if (tStream == null) {
        throw new RuntimeException("Failed to locate module '" + pResource + "'");
    }
    
    DocumentBuilderFactory tFactory = DocumentBuilderFactory.newInstance();
    tFactory.setIgnoringComments(true);
    tFactory.setNamespaceAware(false); // No namespaces: this is default
    tFactory.setValidating(false); // Don't validate DTD: also default
    
    DocumentBuilder tParser = tFactory.newDocumentBuilder();
    
    return tParser.parse(tStream);
}
 
开发者ID:cinnober,项目名称:ciguan,代码行数:36,代码来源:AsXmlTool.java

示例14: validate

import javax.xml.parsers.DocumentBuilderFactory; //导入方法依赖的package包/类
public static boolean validate(File mainMenuFile) {
	try {
		DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
		dbf.setIgnoringComments(true);
		DocumentBuilder db = dbf.newDocumentBuilder();
		Document dom = db.parse(mainMenuFile);
	} catch (SAXException e) {
		return false;
	} catch (ParserConfigurationException pe) {
		return false;
	} catch (IOException io) {
		return false;
	}
	return true;
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:16,代码来源:XML_Menu.java

示例15: parse

import javax.xml.parsers.DocumentBuilderFactory; //导入方法依赖的package包/类
private QueuePlacementPolicy parse(String str) throws Exception {
  // Read and parse the allocations file.
  DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory
      .newInstance();
  docBuilderFactory.setIgnoringComments(true);
  DocumentBuilder builder = docBuilderFactory.newDocumentBuilder();
  Document doc = builder.parse(IOUtils.toInputStream(str));
  Element root = doc.getDocumentElement();
  return QueuePlacementPolicy.fromXml(root, configuredQueues, conf);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:11,代码来源:TestQueuePlacementPolicy.java


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