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


Java DocumentBuilderFactory.setIgnoringElementContentWhitespace方法代码示例

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


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

示例1: get

import javax.xml.parsers.DocumentBuilderFactory; //导入方法依赖的package包/类
public Document get(String url) throws Exception{
    URL obj = new URL(url);
    HttpURLConnection con = (HttpURLConnection) obj.openConnection();
    String user = api.getUser();String password = api.getPassword();
    String authStr = user + ":" + password;
    String authEncoded = Base64.encodeBase64String(authStr.getBytes());
    con.setRequestMethod("GET");
    con.setRequestProperty("Authorization", "Basic " + authEncoded);
    con.setDoOutput(true);
    DocumentBuilderFactory factoryBuilder = DocumentBuilderFactory.newInstance();
    factoryBuilder.setIgnoringComments(true);
    factoryBuilder.setIgnoringElementContentWhitespace(true);
    DocumentBuilder d = factoryBuilder.newDocumentBuilder();
    Document document = d.parse(con.getInputStream());
    return document;
}
 
开发者ID:CodedByYou,项目名称:MAL-,代码行数:17,代码来源:MalGet.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: testCheckElementContentWhitespace

import javax.xml.parsers.DocumentBuilderFactory; //导入方法依赖的package包/类
/**
 * Test for the isIgnoringElementContentWhitespace and the
 * setIgnoringElementContentWhitespace. The xml file has all kinds of
 * whitespace,tab and newline characters, it uses the MyNSContentHandler
 * which does not invoke the characters callback when this
 * setIgnoringElementContentWhitespace is set to true.
 * @throws Exception If any errors occur.
 */
@Test
public void testCheckElementContentWhitespace() throws Exception {
    String goldFile = GOLDEN_DIR + "dbfactory02GF.out";
    String outputFile = USER_DIR + "dbfactory02.out";
    MyErrorHandler eh = MyErrorHandler.newInstance();
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setValidating(true);
    assertFalse(dbf.isIgnoringElementContentWhitespace());
    dbf.setIgnoringElementContentWhitespace(true);
    DocumentBuilder db = dbf.newDocumentBuilder();
    db.setErrorHandler(eh);
    Document doc = db.parse(new File(XML_DIR, "DocumentBuilderFactory06.xml"));
    assertFalse(eh.isErrorOccured());
    DOMSource domSource = new DOMSource(doc);
    TransformerFactory tfactory = TransformerFactory.newInstance();
    Transformer transformer = tfactory.newTransformer();
    SAXResult saxResult = new SAXResult();
    try(MyCHandler handler = MyCHandler.newInstance(new File(outputFile))) {
        saxResult.setHandler(handler);
        transformer.transform(domSource, saxResult);
    }
    assertTrue(compareWithGold(goldFile, outputFile));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:32,代码来源:DocumentBuilderFactoryTest.java

示例6: setDocument

import javax.xml.parsers.DocumentBuilderFactory; //导入方法依赖的package包/类
/**
 * Loads the document used for signing/verification/redaction from the given input stream.
 * <p>
 * The document is checked against the given schema and the given error handler is used.
 *
 * @param inputStream the input stream
 * @param schema      the schema of the loaded XML document
 * @param handler     the errorhandler
 * @throws RedactableXMLSignatureException if this RedactableXMLSignature object is not properly initialized
 */
public final void setDocument(InputStream inputStream, Schema schema, ErrorHandler handler)
        throws RedactableXMLSignatureException {

    DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    documentBuilderFactory.setSchema(schema);
    documentBuilderFactory.setNamespaceAware(true);
    documentBuilderFactory.setIgnoringElementContentWhitespace(true);

    try {
        DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
        documentBuilder.setErrorHandler(handler);
        setDocument(documentBuilder.parse(inputStream));
    } catch (ParserConfigurationException | SAXException | IOException e) {
        throw new RedactableXMLSignatureException(e);
    }
}
 
开发者ID:woefe,项目名称:xmlrss,代码行数:27,代码来源:RedactableXMLSignature.java

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

示例8: root

import javax.xml.parsers.DocumentBuilderFactory; //导入方法依赖的package包/类
/**
 * Reads a XML file and loads its content into a list of nodes
 *
 * @param fn Name of the XML file (relative to the executable's current path)
 * @return Root of the XML tree corresponding to the loaded document, as a singleton list of nodes
 */
public static LinkedList<Node> root(String fn) {
    LinkedList<Node> nodes = new LinkedList<>();
    try {
        // Remove quotes (first and last character)
        File xmlFile = new File(fn.substring(1, fn.length() - 1));
        DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
        // Ignore non-relevant whitespace (only works if the XML has an associated DTD)
        docFactory.setIgnoringElementContentWhitespace(true);
        DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
        Document doc = docBuilder.parse(xmlFile);
        // Normalize document
        doc.getDocumentElement().normalize();
        nodes.add(doc);
    } catch (Exception e) {
        return new LinkedList<>();
    }
    return nodes;
}
 
开发者ID:jsidrach,项目名称:xquery-engine,代码行数:25,代码来源:XPathEvaluator.java

示例9: 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:how2j,项目名称:lazycat,代码行数:22,代码来源:DomUtil.java

示例10: loadResourceAsXML

import javax.xml.parsers.DocumentBuilderFactory; //导入方法依赖的package包/类
/**
 * Loads a XML
 *
 * @param name Name of the resource (without path)
 * @return List of nodes corresponding to the children of the root of the loaded document
 * @throws Exception Exception if input resource is not found or it has invalid format
 */
LinkedList<Node> loadResourceAsXML(String name) throws Exception {
    FileInputStream xmlFile = getResource(name);
    DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
    // Ignore non-relevant whitespace
    docFactory.setIgnoringElementContentWhitespace(true);
    DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
    Document doc = docBuilder.parse(xmlFile);
    // Normalize document
    doc.getDocumentElement().normalize();
    // Add the children (XML resource should have a root which is ignored)
    LinkedList<Node> nodes = new LinkedList<>();
    NodeList nl = doc.getDocumentElement().getChildNodes();
    for (int i = 0; i < nl.getLength(); ++i) {
        nodes.add(nl.item(i));
    }
    return nodes;
}
 
开发者ID:jsidrach,项目名称:xquery-engine,代码行数:25,代码来源:XQueryTests.java

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

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

示例13: TeXSymbolParser

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

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

示例15: convertToDocument

import javax.xml.parsers.DocumentBuilderFactory; //导入方法依赖的package包/类
/**
 * Converts a given string into its document representation.
 * 
 * @param string
 *            The String to be converted.
 * @param nameSpaceAware
 *            Indicates whether namespaces have to be considered or not.
 * @return The document representation of the string, <code>null</code> in
 *         case the input string was <code>null</code>.
 * @throws ParserConfigurationException
 *             Thrown in case the conversion cannot be initiated.
 * @throws IOException
 *             Thrown in case the reading of the string fails.
 * @throws SAXException
 *             Thrown in case the string cannot be parsed.
 */
public static Document convertToDocument(String string,
        boolean nameSpaceAware) throws ParserConfigurationException,
        SAXException, IOException {
    if (string == null) {
        return null;
    }
    DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
    dfactory.setNamespaceAware(nameSpaceAware);
    dfactory.setValidating(false);
    dfactory.setIgnoringElementContentWhitespace(true);
    dfactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
    DocumentBuilder builder = dfactory.newDocumentBuilder();
    Document doc = builder.parse(new InputSource(new StringReader(string)));
    return doc;
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:32,代码来源:XMLConverter.java


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