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