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


Java SAXParser.getXMLReader方法代码示例

本文整理汇总了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;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:26,代码来源:JspDocumentParser.java

示例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();
        }

    }
 
开发者ID:sfilmak,项目名称:MakiLite,代码行数:21,代码来源:RssReader.java

示例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;
    }
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:24,代码来源:RepoDetails.java

示例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();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:23,代码来源:XML_SAX_StAX_FI.java

示例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;
}
 
开发者ID:GDSRS,项目名称:TrabalhoFinalEDA2,代码行数:27,代码来源:mxGraphViewImageReader.java

示例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;
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:27,代码来源:ProductImportParser.java

示例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;
}
 
开发者ID:Linguaculturalists,项目名称:Phoenicia,代码行数:27,代码来源:LocaleManager.java

示例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 "";
}
 
开发者ID:ABTSoftware,项目名称:SciChart.Android.Examples,代码行数:21,代码来源:ExampleSourceCodeParser.java

示例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;
}
 
开发者ID:ondramisar,项目名称:AdronEngine,代码行数:45,代码来源:TMXLoader.java

示例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)));
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:28,代码来源:ServiceProvisioningServiceBeanImportExportSchemaIT.java

示例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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:Bug4848653.java

示例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();
}
 
开发者ID:Linguaculturalists,项目名称:Phoenicia,代码行数:19,代码来源:LocaleLoader.java

示例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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:AstroProcessor.java

示例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));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:NSTableTest.java

示例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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:Bug6594813.java


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