當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。