本文整理匯總了Java中javax.xml.parsers.SAXParser.getXMLReader方法的典型用法代碼示例。如果您正苦於以下問題:Java SAXParser.getXMLReader方法的具體用法?Java SAXParser.getXMLReader怎麽用?Java SAXParser.getXMLReader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.xml.parsers.SAXParser
的用法示例。
在下文中一共展示了SAXParser.getXMLReader方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getSAXParser
import javax.xml.parsers.SAXParser; //導入方法依賴的package包/類
private static SAXParser getSAXParser(
boolean validating,
JspDocumentParser jspDocParser)
throws Exception {
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(true);
// Preserve xmlns attributes
factory.setFeature(
"http://xml.org/sax/features/namespace-prefixes",
true);
factory.setValidating(validating);
//factory.setFeature(
// "http://xml.org/sax/features/validation",
// validating);
// Configure the parser
SAXParser saxParser = factory.newSAXParser();
XMLReader xmlReader = saxParser.getXMLReader();
xmlReader.setProperty(LEXICAL_HANDLER_PROPERTY, jspDocParser);
xmlReader.setErrorHandler(jspDocParser);
return saxParser;
}
示例2: read
import javax.xml.parsers.SAXParser; //導入方法依賴的package包/類
public static RssFeed read(InputStream stream) throws SAXException, IOException {
try {
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser parser = factory.newSAXParser();
XMLReader reader = parser.getXMLReader();
RssHandler handler = new RssHandler();
InputSource input = new InputSource(stream);
reader.setContentHandler(handler);
reader.parse(input);
return handler.getResult();
} catch (ParserConfigurationException e) {
throw new SAXException();
}
}
示例3: getFromFile
import javax.xml.parsers.SAXParser; //導入方法依賴的package包/類
@NonNull
public static RepoDetails getFromFile(InputStream inputStream, int pushRequests) {
try {
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(true);
SAXParser parser = factory.newSAXParser();
XMLReader reader = parser.getXMLReader();
RepoDetails repoDetails = new RepoDetails();
MockRepo mockRepo = new MockRepo(100, pushRequests);
RepoXMLHandler handler = new RepoXMLHandler(mockRepo, repoDetails);
reader.setContentHandler(handler);
InputSource is = new InputSource(new BufferedInputStream(inputStream));
reader.parse(is);
return repoDetails;
} catch (ParserConfigurationException | SAXException | IOException e) {
e.printStackTrace();
fail();
// Satisfies the compiler, but fail() will always throw a runtime exception so we never
// reach this return statement.
return null;
}
}
示例4: parse
import javax.xml.parsers.SAXParser; //導入方法依賴的package包/類
public void parse(InputStream xml, OutputStream finf, String workingDirectory) throws Exception {
StAXDocumentSerializer documentSerializer = new StAXDocumentSerializer();
documentSerializer.setOutputStream(finf);
SAX2StAXWriter saxTostax = new SAX2StAXWriter(documentSerializer);
SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
saxParserFactory.setNamespaceAware(true);
SAXParser saxParser = saxParserFactory.newSAXParser();
XMLReader reader = saxParser.getXMLReader();
reader.setProperty("http://xml.org/sax/properties/lexical-handler", saxTostax);
reader.setContentHandler(saxTostax);
if (workingDirectory != null) {
reader.setEntityResolver(createRelativePathResolver(workingDirectory));
}
reader.parse(new InputSource(xml));
xml.close();
finf.close();
}
示例5: convert
import javax.xml.parsers.SAXParser; //導入方法依賴的package包/類
/**
* Creates the image for the given display XML input source. (Note: The XML
* is an encoded mxGraphView, not mxGraphModel.)
*
* @param inputSource
* Input source that contains the display XML.
* @return Returns an image representing the display XML input source.
*/
public static BufferedImage convert(InputSource inputSource,
mxGraphViewImageReader viewReader)
throws ParserConfigurationException, SAXException, IOException
{
BufferedImage result = null;
SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
XMLReader reader = parser.getXMLReader();
reader.setContentHandler(viewReader);
reader.parse(inputSource);
if (viewReader.getCanvas() instanceof mxImageCanvas)
{
result = ((mxImageCanvas) viewReader.getCanvas()).destroy();
}
return result;
}
示例6: parse
import javax.xml.parsers.SAXParser; //導入方法依賴的package包/類
/**
* Parse the given XML string an create/update the corresponding entities
*
* @param xml
* the XML string
* @return the parse return code
* @throws Exception
*/
public int parse(byte[] xml) throws Exception {
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setNamespaceAware(true);
SchemaFactory sf = SchemaFactory
.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
try (InputStream inputStream = ResourceLoader.getResourceAsStream(
getClass(), getSchemaName())) {
Schema schema = sf.newSchema(new StreamSource(inputStream));
spf.setSchema(schema);
}
SAXParser saxParser = spf.newSAXParser();
XMLReader reader = saxParser.getXMLReader();
reader.setFeature(Constants.XERCES_FEATURE_PREFIX
+ Constants.DISALLOW_DOCTYPE_DECL_FEATURE, true);
reader.setContentHandler(this);
reader.parse(new InputSource(new ByteArrayInputStream(xml)));
return 0;
}
示例7: scan
import javax.xml.parsers.SAXParser; //導入方法依賴的package包/類
/**
* Identify available locales
* @param locales_directory
* @return
*/
public Map<String, String> scan(String locales_directory) throws IOException {
final Map<String, String> locale_map = new HashMap<String, String>();
String[] files = PhoeniciaContext.assetManager.list(locales_directory);
for (String locale_dir: files) {
if (locale_dir.equals("common")) continue;
String locale_path = locales_directory+"/"+locale_dir+"/manifest.xml";
LocaleHeaderScanner scanner = new LocaleHeaderScanner(locale_path, locale_map);
try {
InputStream locale_manifest_in = PhoeniciaContext.assetManager.open(locale_path);
final SAXParserFactory spf = SAXParserFactory.newInstance();
final SAXParser sp = spf.newSAXParser();
final XMLReader xr = sp.getXMLReader();
xr.setContentHandler(scanner);
xr.parse(new InputSource(new BufferedInputStream(locale_manifest_in)));
} catch (Exception e) {
Debug.e(e);
}
}
return locale_map;
}
示例8: getSearchWords
import javax.xml.parsers.SAXParser; //導入方法依賴的package包/類
private static String getSearchWords(String xml) {
try {
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
ItemXMLHandler myXMLHandler = new ItemXMLHandler();
xr.setContentHandler(myXMLHandler);
InputSource inStream = new InputSource();
inStream.setCharacterStream(new StringReader(xml));
xr.parse(inStream);
return myXMLHandler.getCollectedNodes();
} catch (ParserConfigurationException | SAXException | IOException e) {
e.printStackTrace();
}
return "";
}
示例9: readTMX
import javax.xml.parsers.SAXParser; //導入方法依賴的package包/類
/**
* Reads XML file from assets and returns a TileMapData structure describing its contents
*
* @param filename path to the file in assets
* @param c context of the application to resolve assets folder
* @return data structure containing map data
*/
public static TileMapData readTMX(String filename, Context c){
TileMapData t = null;
// Initialize SAX
try{
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser parser = spf.newSAXParser();
XMLReader reader = parser.getXMLReader();
// Create an instance of the TMX XML handler
// that will create a TileMapData object
TMXHandler handler = new TMXHandler();
reader.setContentHandler(handler);
AssetManager assetManager = c.getAssets();
reader.parse((new InputSource(assetManager.open(filename))));
// Extract the created object
t = handler.getData();
} catch(ParserConfigurationException pce) {
Log.e("SAX XML", "sax parse error", pce);
} catch(SAXException se) {
Log.e("SAX XML", "sax error", se);
} catch(IOException ioe) {
Log.e("SAX XML", "sax parse io error", ioe);
}finally{
}
return t;
}
示例10: verifyXML
import javax.xml.parsers.SAXParser; //導入方法依賴的package包/類
private void verifyXML(byte[] xml) throws IOException, SAXException,
ParserConfigurationException {
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setNamespaceAware(true);
SchemaFactory sf = SchemaFactory
.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
ClassLoader classLoader = Thread.currentThread()
.getContextClassLoader();
if (classLoader == null) {
classLoader = getClass().getClassLoader();
}
final Schema schema;
try (InputStream inputStream = ResourceLoader.getResourceAsStream(
getClass(), "TechnicalServices.xsd")) {
schema = sf.newSchema(new StreamSource(inputStream));
}
spf.setSchema(schema);
SAXParser saxParser = spf.newSAXParser();
XMLReader reader = saxParser.getXMLReader();
ErrorHandler errorHandler = new MyErrorHandler();
reader.setErrorHandler(errorHandler);
reader.parse(new InputSource(new ByteArrayInputStream(xml)));
}
示例11: test
import javax.xml.parsers.SAXParser; //導入方法依賴的package包/類
@Test
public void test() throws IOException, SAXException, ParserConfigurationException {
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setValidating(false);
SAXParser parser = factory.newSAXParser();
parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage", XMLConstants.W3C_XML_SCHEMA_NS_URI);
String filename = XML_DIR + "Bug4848653.xml";
InputSource is = new InputSource(filenameToURL(filename));
XMLReader xmlReader = parser.getXMLReader();
xmlReader.setErrorHandler(new MyErrorHandler());
xmlReader.parse(is);
}
示例12: load
import javax.xml.parsers.SAXParser; //導入方法依賴的package包/類
/**
* Load and read the manifest.xml for a Locale.
* @param locale_manifest_in
* @return
*/
public Locale load(InputStream locale_manifest_in) {
LocaleParser localeParser = new LocaleParser();
try {
final SAXParserFactory spf = SAXParserFactory.newInstance();
final SAXParser sp = spf.newSAXParser();
final XMLReader xr = sp.getXMLReader();
xr.setContentHandler(localeParser);
xr.parse(new InputSource(new BufferedInputStream(locale_manifest_in)));
} catch (Exception e) {
Debug.e(e);
}
return localeParser.getLocale();
}
示例13: getXMLReader
import javax.xml.parsers.SAXParser; //導入方法依賴的package包/類
private XMLReader getXMLReader() throws Exception {
SAXParser parser = spf.newSAXParser();
parser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA_NS_URI);
parser.setProperty(JAXP_SCHEMA_SOURCE, "catalog.xsd");
XMLReader catparser = parser.getXMLReader();
catparser.setErrorHandler(new CatalogErrorHandler());
return catparser;
}
示例14: xrNSTable01
import javax.xml.parsers.SAXParser; //導入方法依賴的package包/類
/**
* Here namespace processing and namespace-prefixes are enabled.
* The testcase tests XMLReader for this.
*
* @throws Exception If any errors occur.
*/
@Test
public void xrNSTable01() throws Exception {
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setNamespaceAware(true);
SAXParser saxParser = spf.newSAXParser();
XMLReader xmlReader = saxParser.getXMLReader();
xmlReader.setFeature(NAMESPACE_PREFIXES, true);
assertTrue(xmlReader.getFeature(NAMESPACES));
assertTrue(xmlReader.getFeature(NAMESPACE_PREFIXES));
}
示例15: runTransform
import javax.xml.parsers.SAXParser; //導入方法依賴的package包/類
private String runTransform(SAXParser sp) throws Exception {
// Run identity transform using SAX parser
SAXSource src = new SAXSource(sp.getXMLReader(), new InputSource(new StringReader(TESTXML)));
Transformer transformer = TransformerFactory.newInstance().newTransformer();
StringWriter sw = new StringWriter();
transformer.transform(src, new StreamResult(sw));
String result = sw.getBuffer().toString();
// System.out.println(result);
return result;
}