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


Java DOMParser类代码示例

本文整理汇总了Java中org.apache.xerces.parsers.DOMParser的典型用法代码示例。如果您正苦于以下问题:Java DOMParser类的具体用法?Java DOMParser怎么用?Java DOMParser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: load

import org.apache.xerces.parsers.DOMParser; //导入依赖的package包/类
public Node load(String xmlfile) {
	Document doc = null;
	
 try{	
	DOMParser parser = new DOMParser();
	parser.reset();
	parser.parse(xmlfile);
	doc = parser.getDocument();
 }	
 catch (IOException ioe) 
        {ioe.printStackTrace();}
 catch (SAXException saxe)
 		{saxe.printStackTrace();}

 return doc;
}
 
开发者ID:RJMillerLab,项目名称:ibench,代码行数:17,代码来源:XMLReader.java

示例2: loadXMLFile

import org.apache.xerces.parsers.DOMParser; //导入依赖的package包/类
/**
 * Loads an XML file from an InputStream.
 * <br>
 * Note: the source stream is closed internally 
 * 
 * @param configurationFileStream the source stream
 * @return the loaded XML document
 * @throws IOException
 * @throws SAXException
 */
public static Document loadXMLFile( InputStream configurationFileStream ) throws IOException,
                                                                          SAXException {

    try {
        DOMParser parser = new DOMParser();

        // Required settings from the DomParser
        parser.setFeature("http://apache.org/xml/features/dom/defer-node-expansion", false);
        parser.setFeature("http://apache.org/xml/features/continue-after-fatal-error", true);
        parser.setFeature("http://apache.org/xml/features/allow-java-encodings", true);
        parser.parse(new InputSource(configurationFileStream));

        return parser.getDocument();
    } finally {
        IoUtils.closeStream(configurationFileStream);
    }
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:28,代码来源:XmlUtils.java

示例3: loadDocument

import org.apache.xerces.parsers.DOMParser; //导入依赖的package包/类
/**
   * load a XML Document as DOM representation
   * @param file XML File to load
   * @return DOM Object
   * @throws SAXException
   * @throws IOException
   */
  public Document loadDocument(Resource file) throws SAXException, IOException {
      DOMParser parser = new DOMParser();
   
InputStream in = null;
try {
	in = file.getInputStream();
	InputSource source = new InputSource(in);
	parser.parse(source);
}
finally {
	IOUtil.closeEL(in);
}
  	
  	return parser.getDocument();
  }
 
开发者ID:lucee,项目名称:Lucee4,代码行数:23,代码来源:StorageUtil.java

示例4: init

import org.apache.xerces.parsers.DOMParser; //导入依赖的package包/类
@Override
public void init(lucee.runtime.config.Config config,Resource searchDir, 
		LogAndSource log/* always null*/) throws SAXException, IOException, SearchException {
	this.config=config;
	this.searchDir=searchDir;
	this.searchFile=searchDir.getRealResource("search.xml");
	if(!searchFile.exists()) createSearchFile(searchFile);
	
	DOMParser parser = new DOMParser();
	InputStream is=null;
    try {
		is = IOUtil.toBufferedInputStream(searchFile.getInputStream());
        InputSource source = new InputSource(is);
    	parser.parse(source);
    }
    finally {
    	IOUtil.closeEL(is);
    }
   	doc = parser.getDocument();
   	    	
       
   	readCollections(config);
}
 
开发者ID:lucee,项目名称:Lucee4,代码行数:24,代码来源:SearchEngineSupport.java

示例5: parseXMLPage

import org.apache.xerces.parsers.DOMParser; //导入依赖的package包/类
private List<String> parseXMLPage(Page page) {
    DOMParser parser = new DOMParser();
    try {
        parser.parse(new InputSource(new ByteArrayInputStream(page.getContent())));
    } catch (SAXException | IOException e) {
        throw new RuntimeException("Failed to parse search results.", e);
    }
    Document doc = parser.getDocument();
    NodeList list = doc.getElementsByTagName("d:Url");
    List<String> urls = new ArrayList<String>();
    for (int j = 0; j < list.getLength(); j++) {
        Node node = list.item(j);
        NodeList children = node.getChildNodes();
        Node child = children.item(0);
        urls.add(child.getTextContent());
    }
    return urls;
}
 
开发者ID:ViDA-NYU,项目名称:ache,代码行数:19,代码来源:BingSearchAzureAPI.java

示例6: checkForParseError

import org.apache.xerces.parsers.DOMParser; //导入依赖的package包/类
/**
 * See if the DOMParser after parsing a Document has any errors and,
 * if so, throw a RuntimeException exception containing the errors.
 *
 */
private static void checkForParseError(
    final DOMParser parser,
    Throwable t)
{
    if (Util.IBM_JVM) {
        // IBM JDK returns lots of errors. Not sure whether they are
        // real errors, but ignore for now.
        return;
    }

    final ErrorHandler errorHandler = parser.getErrorHandler();
    if (errorHandler instanceof SaxErrorHandler) {
        final SaxErrorHandler saxEH = (SaxErrorHandler) errorHandler;
        final List<SaxErrorHandler.ErrorInfo> errors = saxEH.getErrors();

        if (errors != null && errors.size() > 0) {
            String errorStr = SaxErrorHandler.formatErrorInfos(saxEH);
            throw new RuntimeException(errorStr, t);
        }
    } else {
        System.out.println("errorHandler=" + errorHandler);
    }
}
 
开发者ID:OSBI,项目名称:mondrian,代码行数:29,代码来源:XmlUtil.java

示例7: parse

import org.apache.xerces.parsers.DOMParser; //导入依赖的package包/类
/**
 * Parse a stream into a Document (no validation).
 *
 */
public static Document parse(InputStream in)
    throws SAXException, IOException
{
    InputSource source = new InputSource(in);

    DOMParser parser = XmlUtil.getParser(null, null, false);
    try {
        parser.parse(source);
        checkForParseError(parser);
    } catch (SAXParseException ex) {
        checkForParseError(parser, ex);
    }

    Document document = parser.getDocument();
    return document;
}
 
开发者ID:OSBI,项目名称:mondrian,代码行数:21,代码来源:XmlUtil.java

示例8: validate

import org.apache.xerces.parsers.DOMParser; //导入依赖的package包/类
public static void validate(
    String docStr,
    String schemaLocationPropertyValue,
    EntityResolver resolver)
    throws IOException,
    SAXException
{
    if (resolver == null) {
        resolver = new Resolver();
    }
    DOMParser parser =
        getParser(schemaLocationPropertyValue, resolver, true);

    try {
        parser.parse(new InputSource(new StringReader(docStr)));
        checkForParseError(parser);
    } catch (SAXParseException ex) {
        checkForParseError(parser, ex);
    }
}
 
开发者ID:OSBI,项目名称:mondrian,代码行数:21,代码来源:XmlUtil.java

示例9: parseCase

import org.apache.xerces.parsers.DOMParser; //导入依赖的package包/类
/**
 * Parses the XML into an instance of the domain class defined in the class parameter.
 *
 * @return the created instance
 * @throws CaseParserException if there were problems while parsing case XML
 */
public T parseCase() throws CaseParserException {
    DOMParser parser = new DOMParser();

    InputSource inputSource = new InputSource();
    inputSource.setCharacterStream(new StringReader(xmlDoc));
    CaseXml ccCase;
    try {
        parser.parse(inputSource);
        ccCase = parseCase(parser.getDocument());
    } catch (IOException | SAXException ex) {
        throw new CaseParserException(ex,
                "Exception while trying to parse caseXml");
    }

    return domainMapper.mapToDomainObject(ccCase);
}
 
开发者ID:motech,项目名称:modules,代码行数:23,代码来源:CaseParser.java

示例10: loadDocument

import org.apache.xerces.parsers.DOMParser; //导入依赖的package包/类
public static Document loadDocument(URL fileUrl) {
	Document doc = null;
	DOMParser parser = new DOMParser();

	if (logger.isDebugEnabled()) {
		logger.debug("Loading document from " + fileUrl.toExternalForm());
	}

	try {
		InputSource inputSource = new InputSource(fileUrl.openStream());
		parser.parse(inputSource);
		doc = parser.getDocument();
	} catch (Exception e) {
		logger.warn("Unable to load document: " + e.getMessage());
	}

	return doc;
}
 
开发者ID:forcedotcom,项目名称:idecore,代码行数:19,代码来源:Utils.java

示例11: getPackageManifestDOMDocument

import org.apache.xerces.parsers.DOMParser; //导入依赖的package包/类
public Document getPackageManifestDOMDocument(IProject project) throws FactoryException {
    IFile packageManifestFile = getPackageManifestFile(project);
    Document document = null;
    try {
        InputSource content = new InputSource(packageManifestFile.getContents());
        DOMParser parser = new DOMParser();
        parser.parse(content);
        document = parser.getDocument();
    } catch (CoreException ce) {
        String logMessage = Utils.generateCoreExceptionLog(ce);
        logger.error("Core exception occurred when marshalling package manifest into DOM document: " + logMessage,
            ce);
        throw new FactoryException("Unable to create DOM document from path "
                + packageManifestFile.getProjectRelativePath().toPortableString(), ce);
    } catch (SAXException se) {
        logger.error("SAX exception occurred when marshalling package manifest into DOM document", se);
        throw new FactoryException("Unable to create DOM document from path "
                + packageManifestFile.getProjectRelativePath().toPortableString(), se);
    } catch (IOException ioe) {
        logger.error("IO exception occurred when marshalling package manifest into DOM document", ioe);
        throw new FactoryException("Unable to create DOM document from path "
                + packageManifestFile.getProjectRelativePath().toPortableString(), ioe);
    }
    return document;
}
 
开发者ID:forcedotcom,项目名称:idecore,代码行数:26,代码来源:PackageManifestFactory.java

示例12: parse

import org.apache.xerces.parsers.DOMParser; //导入依赖的package包/类
@Override
public Document parse() throws SAXException, IOException
{
    //temporay NekoHTML fix until nekohtml gets fixed
    if (!neko_fixed)
    {
        HTMLElements.Element li = HTMLElements.getElement(HTMLElements.LI);
        HTMLElements.Element[] oldparents = li.parent;
        li.parent = new HTMLElements.Element[oldparents.length + 1];
        for (int i = 0; i < oldparents.length; i++)
            li.parent[i] = oldparents[i];
        li.parent[oldparents.length] = HTMLElements.getElement(HTMLElements.MENU);
        neko_fixed = true;
    }
    
    DOMParser parser = new DOMParser(new HTMLConfiguration());
    parser.setProperty("http://cyberneko.org/html/properties/names/elems", "lower");
    if (charset != null)
        parser.setProperty("http://cyberneko.org/html/properties/default-encoding", charset);
    parser.parse(new org.xml.sax.InputSource(getDocumentSource().getInputStream()));
    return parser.getDocument();
}
 
开发者ID:radkovo,项目名称:CSSBox,代码行数:23,代码来源:DefaultDOMSource.java

示例13: testBasicGroupBy

import org.apache.xerces.parsers.DOMParser; //导入依赖的package包/类
/**
 * A simple test to verify that we can actually facet on a simple field and get back all values
 * across all documents, this is the same as faceting in regular solr.
 * 
 * @throws Exception
 */
@Test
public void testBasicGroupBy() throws Exception {
    ModifiableSolrParams p = new ModifiableSolrParams();
    p.set("q", "*:*");
    p.set("wt", "xml");
    p.set("rows", "0");
    p.set("indent", "true");
    p.set(GroupByComponent.Params.GROUPBY, "_root_");
    SolrQueryRequest req = new LocalSolrQueryRequest(h.getCore(), p);
    String response = h.query(req);
    System.out.println(response);

    DOMParser parser = new DOMParser();
    parser.parse(new InputSource(new StringReader(response)));
    Document document = parser.getDocument();
    XPath xpath = XPathFactory.newInstance().newXPath();
    NodeList nodes = (NodeList) xpath.compile("//lst[@name='group']//lst[@name='_root_']//lst//int[@name='count']").evaluate(document, XPathConstants.NODESET);
    assertEquals(2, nodes.getLength());
    assertEquals("6", nodes.item(0).getTextContent());
    assertEquals("5", nodes.item(1).getTextContent());
}
 
开发者ID:terrancesnyder,项目名称:solr-groupby-component,代码行数:28,代码来源:GroupByComponentTest.java

示例14: parse

import org.apache.xerces.parsers.DOMParser; //导入依赖的package包/类
public Document parse() throws SAXException, IOException
{
    DOMParser parser = new DOMParser(new HTMLConfiguration());
    parser.setProperty("http://cyberneko.org/html/properties/names/elems", "lower");
    parser.setProperty("http://cyberneko.org/html/properties/names/attrs", "lower");
    if (charset != null)
        parser.setProperty("http://cyberneko.org/html/properties/default-encoding", charset);
    
    //preparation for filters, not used now
    /*XMLDocumentFilter attributeFilter = new DOMAttributeFilter();
    XMLDocumentFilter[] filters = { attributeFilter };
    parser.setProperty("http://cyberneko.org/html/properties/filters", filters);*/        
    
    parser.parse(new org.xml.sax.InputSource(is));
    doc = parser.getDocument();
    return doc;
}
 
开发者ID:radkovo,项目名称:jStyleParser,代码行数:18,代码来源:DOMSource.java

示例15: checkForParseError

import org.apache.xerces.parsers.DOMParser; //导入依赖的package包/类
/**
 * See if the DOMParser after parsing a Document has any errors and,
 * if so, throw a RuntimeException exception containing the errors.
 *
 */
private static void checkForParseError(
    final DOMParser parser,
    Throwable t)
{
    final ErrorHandler errorHandler = parser.getErrorHandler();

    if (errorHandler instanceof SaxErrorHandler) {
        final SaxErrorHandler saxEH = (SaxErrorHandler) errorHandler;
        final List<SaxErrorHandler.ErrorInfo> errors = saxEH.getErrors();

        if (errors != null && errors.size() > 0) {
            String errorStr = SaxErrorHandler.formatErrorInfos(saxEH);
            throw new RuntimeException(errorStr, t);
        }
    } else {
        System.out.println("errorHandler=" + errorHandler);
    }
}
 
开发者ID:Twixer,项目名称:mondrian-3.1.5,代码行数:24,代码来源:XmlUtil.java


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