本文整理汇总了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));
}
示例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;
}
示例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();
}
}
示例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));
}
示例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> & 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
}
示例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, "&", "&");
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;
}
示例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));
}
示例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));
}
}
示例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;
}
示例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;
}
示例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);
}
示例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")));
}
示例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;
}
}
示例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));
}
示例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);
}
}