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


Java XMLReaderFactory.createXMLReader方法代码示例

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


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

示例1: testcase08

import org.xml.sax.helpers.XMLReaderFactory; //导入方法依赖的package包/类
/**
 * Test newTransformerHandler with a Template Handler.
 *
 * @throws Exception If any errors occur.
 */
public void testcase08() throws Exception {
    String outputFile = USER_DIR + "saxtf008.out";
    String goldFile = GOLDEN_DIR + "saxtf008GF.out";

    try (FileOutputStream fos = new FileOutputStream(outputFile)) {
        XMLReader reader = XMLReaderFactory.createXMLReader();
        SAXTransformerFactory saxTFactory
                = (SAXTransformerFactory)TransformerFactory.newInstance();

        TemplatesHandler thandler = saxTFactory.newTemplatesHandler();
        reader.setContentHandler(thandler);
        reader.parse(XSLT_FILE);
        TransformerHandler tfhandler
                = saxTFactory.newTransformerHandler(thandler.getTemplates());

        Result result = new StreamResult(fos);
        tfhandler.setResult(result);

        reader.setContentHandler(tfhandler);
        reader.parse(XML_FILE);
    }
    assertTrue(compareWithGold(goldFile, outputFile));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:SAXTFactoryTest.java

示例2: load

import org.xml.sax.helpers.XMLReaderFactory; //导入方法依赖的package包/类
public static SyntaxScheme load(Font baseFont, InputStream in)
		throws IOException {
	SyntaxSchemeLoader parser = null;
	try {
		XMLReader reader = XMLReaderFactory.createXMLReader();
		parser = new SyntaxSchemeLoader(baseFont);
		parser.baseFont = baseFont;
		reader.setContentHandler(parser);
		InputSource is = new InputSource(in);
		is.setEncoding("UTF-8");
		reader.parse(is);
	} catch (SAXException se) {
		throw new IOException(se.toString());
	}
	return parser.scheme;
}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:17,代码来源:SyntaxScheme.java

示例3: fillMaps

import org.xml.sax.helpers.XMLReaderFactory; //导入方法依赖的package包/类
private static void fillMaps() throws IOException {
  Logger log = Logger.getInstance(UnsupportedFeaturesUtil.class.getName());
  FileReader reader = new FileReader(PythonHelpersLocator.getHelperPath("/tools/versions.xml"));
  try {
    XMLReader xr = XMLReaderFactory.createXMLReader();
    VersionsParser parser = new VersionsParser();
    xr.setContentHandler(parser);
    xr.parse(new InputSource(reader));
  }
  catch (SAXException e) {
    log.error("Improperly formed \"versions.xml\". " + e.getMessage());
  }
  finally {
    reader.close();
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:UnsupportedFeaturesUtil.java

示例4: testcase03

import org.xml.sax.helpers.XMLReaderFactory; //导入方法依赖的package包/类
/**
 * Unit test for newTransformerhandler(Source). DcoumentBuilderFactory is
 * namespace awareness, DocumentBuilder parse xslt file as DOMSource.
 *
 * @throws Exception If any errors occur.
 */
@Test
public void testcase03() throws Exception {
    String outputFile = USER_DIR + "saxtf003.out";
    String goldFile = GOLDEN_DIR + "saxtf003GF.out";

    try (FileOutputStream fos = new FileOutputStream(outputFile)) {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        DocumentBuilder docBuilder = dbf.newDocumentBuilder();
        Document document = docBuilder.parse(new File(XSLT_FILE));
        Node node = (Node)document;
        DOMSource domSource= new DOMSource(node);

        XMLReader reader = XMLReaderFactory.createXMLReader();
        SAXTransformerFactory saxTFactory
                = (SAXTransformerFactory)TransformerFactory.newInstance();
        TransformerHandler handler =
                    saxTFactory.newTransformerHandler(domSource);
        Result result = new StreamResult(fos);
        handler.setResult(result);
        reader.setContentHandler(handler);
        reader.parse(XML_FILE);
    }
    assertTrue(compareWithGold(goldFile, outputFile));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:32,代码来源:SAXTFactoryTest.java

示例5: main

import org.xml.sax.helpers.XMLReaderFactory; //导入方法依赖的package包/类
/**
    public static void main(String[] args) {
        TestRunner.run(JDK6770436Test.class);
    }
*/
    @Test
    public void entityCallbackOrderJava() throws SAXException, IOException {
        final String input = "<element> &amp; some more text</element>";

        final MockContentHandler handler = new MockContentHandler();
        final XMLReader xmlReader = XMLReaderFactory.createXMLReader();

        xmlReader.setContentHandler(handler);
        xmlReader.setProperty("http://xml.org/sax/properties/lexical-handler", handler);

        xmlReader.parse(new InputSource(new StringReader(input)));

        final List<String> events = handler.getEvents();
        printEvents(events);
        assertCallbackOrder(events); //regression from JDK5
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:EntityCharacterEventOrder.java

示例6: decode

import org.xml.sax.helpers.XMLReaderFactory; //导入方法依赖的package包/类
/** This will unmarshal the input XML into a List of FormKey objects.
 * @param historyNavXml The XML representation of the historyNavList.
 * @return The List of FormKey objects.
 */
public static List decode(String historyNavXml) {
    List historyNavList = null;
    try {
        // The following step may seem out of place.
        // And the correct thing to do is to probably do a convertToHtml() on the String returned by the encode() method.
        // However, on a Post, the browser implicitly converts all the entities to corresponding characters.
        // Hence the need for the following step !!
        historyNavXml = StringHelper.replace(historyNavXml, "&", "&amp;");

        if (log.isDebugEnabled())
            log.debug("Unmarshalling the historyNavXml " + historyNavXml);
        XMLReader reader = XMLReaderFactory.createXMLReader();
        HistoryNavHandler handler = new HistoryNavHandler();
        reader.setContentHandler(handler);
        reader.parse(new InputSource(new BufferedReader(new StringReader(historyNavXml))));
        historyNavList = handler.getHistoryNavList();
    } catch (Exception e) {
        if (log.isInfoEnabled())
            log.info("Error while parsing the historyNavXml " + historyNavXml, e);
    }
    if (log.isDebugEnabled())
        log.debug("Unmarshalled List: " + historyNavList);
    return historyNavList;
}
 
开发者ID:jaffa-projects,项目名称:jaffa-framework,代码行数:29,代码来源:HistoryNav.java

示例7: parse

import org.xml.sax.helpers.XMLReaderFactory; //导入方法依赖的package包/类
public static void parse(DefaultHandler handler, String file) throws SAXException, IOException {
	XMLReader xreader = XMLReaderFactory.createXMLReader();
	xreader.setContentHandler(handler);
	xreader.setErrorHandler(handler);
	FileReader reader = new FileReader(file);
    xreader.parse(new InputSource(reader));			
}
 
开发者ID:amritbhat786,项目名称:DocIT,代码行数:8,代码来源:SAXUtilities.java

示例8: main

import org.xml.sax.helpers.XMLReaderFactory; //导入方法依赖的package包/类
public static void main(String[] argv) throws Exception {
	XMLReader xr = XMLReaderFactory.createXMLReader();

	BugCollection bugCollection = new SortedBugCollection();
	Project project = new Project();

	SAXBugCollectionHandler handler = new SAXBugCollectionHandler(bugCollection, project);
	xr.setContentHandler(handler);
	xr.setErrorHandler(handler);

	// Parse each file provided on the
	// command line.
	for (int i = 0; i < argv.length; i++) {
		FileReader r = new FileReader(argv[i]);
		xr.parse(new InputSource(r));
	}
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:18,代码来源:SAXBugCollectionHandler.java

示例9: search

import org.xml.sax.helpers.XMLReaderFactory; //导入方法依赖的package包/类
public WishlistProduct search(String productID) throws Exception {
	// TODO test
	if (productID.equals("XXXXXXXXXX")) {
		return new WishlistProduct("XXXXXXXXXX", "Test product",
				(1458500000000l - System.currentTimeMillis()) / 1000, 500,
				new Date());
	}
	params.put("ItemId", productID);
	String url = helper.sign(params);
	System.out.println(url);
	WishlistProduct wishlistProduct = new WishlistProduct();

	XMLReader xmlReader = XMLReaderFactory.createXMLReader();
	xmlReader.setContentHandler(new XMLContentHandler(wishlistProduct));
	xmlReader.parse(new InputSource(new URL(url).openStream()));
	if (wishlistProduct.getCurrentPrice() == 0) {
		return null;
	}
	return wishlistProduct;
}
 
开发者ID:fasthall,项目名称:amazon-price-tracker,代码行数:21,代码来源:JavaCodeSnippet.java

示例10: load

import org.xml.sax.helpers.XMLReaderFactory; //导入方法依赖的package包/类
/**
 * Note that if file starts with 'classpath:' the resource is looked
 * up on the classpath instead.
 */
public static Configuration load(String file)
  throws IOException, SAXException {
  ConfigurationImpl cfg = new ConfigurationImpl();

  XMLReader parser = XMLReaderFactory.createXMLReader();
  parser.setContentHandler(new ConfigHandler(cfg, file));
  if (file.startsWith("classpath:")) {
    String resource = file.substring("classpath:".length());
    ClassLoader cloader = Thread.currentThread().getContextClassLoader();
    InputStream istream = cloader.getResourceAsStream(resource);
    parser.parse(new InputSource(istream));
  } else
    parser.parse(file);

  return cfg;
}
 
开发者ID:enricopal,项目名称:STEM,代码行数:21,代码来源:ConfigLoader.java

示例11: ParserXML

import org.xml.sax.helpers.XMLReaderFactory; //导入方法依赖的package包/类
/**
 * Classe permettant de parser les fichiers XML Bati3D issus du Matis
 */
public ParserXML(String filePath) throws Exception {

  super();

  // Creation d'un lecteur
  XMLReader xr = XMLReaderFactory.createXMLReader();

  // Modification de la taille du tableau dans lequel est engrange les
  // donnees issues du fichier XML
  String id = "http://apache.org/xml/properties/input-buffer-size";
  Object value = new Integer(16 * 16 * 65536);
  xr.setProperty(id, value);

  // Pour utiliser le setContentHandler et le setContentHandler
  xr.setContentHandler(this);
  xr.setErrorHandler(this);

  // Debut du Parsing
  xr.parse(filePath);

}
 
开发者ID:IGNF,项目名称:geoxygene,代码行数:25,代码来源:ParserXML.java

示例12: validate

import org.xml.sax.helpers.XMLReaderFactory; //导入方法依赖的package包/类
/**
 * Valida el documento XML.
 * 
 * @param documentFile Documento XML que se quiere validar
 * @param eh ErrorHandler. Manejador de errores
 * @param ch ContentHandler. Manejador de contenido
 * 
 * @throws Exception si se produce un error durante la validaci�n.
 */
private void validate(File documentFile, ErrorHandler eh, ContentHandler ch) throws Exception {

	XMLReader xreader = XMLReaderFactory.createXMLReader(cParserXerces);

	xreader.setFeature(cValidation, true);
	xreader.setFeature(cValidationSchema, true);
	xreader.setFeature(cNamespaces, true);
	xreader.setFeature(cNamespacePrefix, true);
	xreader.setFeature(cFullCheckSchema, true);
	xreader.setFeature(cContinuaFaltalError, true);
	xreader.setFeature(cDinamicValidation, false);
	xreader.setProperty(cSchemaLenguage, W3C_XML_SCHEMA_NS_URI);

	xreader.setEntityResolver(XbrlApiConfiguration.getInstance().getResolver());

	if(ch != null)
		xreader.setContentHandler(ch);

	if(eh != null)
		xreader.setErrorHandler(eh);

	xreader.parse(new InputSource(new java.io.InputStreamReader(new FileInputStream(documentFile), "UTF-8")));

}
 
开发者ID:xbrles,项目名称:lenloc-penloc,代码行数:34,代码来源:XSDValidator.java

示例13: XmlTagTreeReader

import org.xml.sax.helpers.XMLReaderFactory; //导入方法依赖的package包/类
public XmlTagTreeReader(int which, String uri, boolean verbose) throws SAXException, IOException {
	XMLReader saxReader = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
	saxReader.setEntityResolver(new MyEntityResolver());
	//System.err.println("@@@@@@@@@@@@@@ File " + uri);
	switch (which) {
	case POL:
        saxReader.setContentHandler(new TagContentHandler(verbose));
        saxReader.parse(uri);
        polarities = ((TagContentHandler) saxReader.getContentHandler()).getPolarities();
        lexNodes   = ((TagContentHandler) saxReader.getContentHandler()).getLexNodes();
        families   = ((TagContentHandler) saxReader.getContentHandler()).getFamilies();
        inGrammarSize=((TagContentHandler) saxReader.getContentHandler()).getInGrammarSize();
		break;
	case GRAMMAR:
        saxReader.setContentHandler(new TagTreeContentHandler(verbose));
        saxReader.parse(uri);
        trees = ((TagTreeContentHandler) saxReader.getContentHandler()).getSchema();			
		break;
	case LEMMA:
		saxReader.setContentHandler(new LemmaContentHandler(verbose));
        saxReader.parse(uri);
        lemmas = ((LemmaContentHandler) saxReader.getContentHandler()).getLemma();
        coanchors = ((LemmaContentHandler) saxReader.getContentHandler()).getCoanchors();
		break;
	case MORPH:
        saxReader.setContentHandler(new MorphContentHandler(verbose));
        saxReader.parse(uri);
        morphs = ((MorphContentHandler) saxReader.getContentHandler()).getMorphs();
		break;
	}
}
 
开发者ID:spetitjean,项目名称:TuLiPA-frames,代码行数:32,代码来源:XmlTagTreeReader.java

示例14: testcase06

import org.xml.sax.helpers.XMLReaderFactory; //导入方法依赖的package包/类
/**
 * Unit test newTransformerHandler with a DOMSource.
 *
 * @throws Exception If any errors occur.
 */
@Test
public void testcase06() throws Exception {
    String outputFile = USER_DIR + "saxtf006.out";
    String goldFile = GOLDEN_DIR + "saxtf006GF.out";

    try (FileOutputStream fos = new FileOutputStream(outputFile)) {
        XMLReader reader = XMLReaderFactory.createXMLReader();
        SAXTransformerFactory saxTFactory
                = (SAXTransformerFactory)TransformerFactory.newInstance();

        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        DocumentBuilder docBuilder = dbf.newDocumentBuilder();
        Node node = (Node)docBuilder.parse(new File(XSLT_INCL_FILE));

        DOMSource domSource = new DOMSource(node, "file:///" + XML_DIR);
        TransformerHandler handler =
                    saxTFactory.newTransformerHandler(domSource);

        Result result = new StreamResult(fos);
        handler.setResult(result);
        reader.setContentHandler(handler);
        reader.parse(XML_FILE);
    }
    assertTrue(compareWithGold(goldFile, outputFile));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:32,代码来源:SAXTFactoryTest.java

示例15: XmlResponsesSaxParser

import org.xml.sax.helpers.XMLReaderFactory; //导入方法依赖的package包/类
/**
 * Constructs the XML SAX parser.
 *
 * @throws CosClientException
 */
public XmlResponsesSaxParser() throws CosClientException {
    // Ensure we can load the XML Reader.
    try {
        xr = XMLReaderFactory.createXMLReader();
    } catch (SAXException e) {
        throw new CosClientException("Couldn't initialize a SAX driver to create an XMLReader",
                e);
    }
}
 
开发者ID:tencentyun,项目名称:cos-java-sdk-v5,代码行数:15,代码来源:XmlResponsesSaxParser.java


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