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


Java SAXParserFactory.setValidating方法代码示例

本文整理汇总了Java中javax.xml.parsers.SAXParserFactory.setValidating方法的典型用法代码示例。如果您正苦于以下问题:Java SAXParserFactory.setValidating方法的具体用法?Java SAXParserFactory.setValidating怎么用?Java SAXParserFactory.setValidating使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.xml.parsers.SAXParserFactory的用法示例。


在下文中一共展示了SAXParserFactory.setValidating方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testLargeMaxOccurs

import javax.xml.parsers.SAXParserFactory; //导入方法依赖的package包/类
@Test
public final void testLargeMaxOccurs() {

    String XML_FILE_NAME = "Bug4674384_MAX_OCCURS_Test.xml";

    try {
        // create and initialize the parser
        SAXParserFactory spf = SAXParserFactory.newInstance();
        spf.setNamespaceAware(true);
        spf.setValidating(true);

        SAXParser parser = spf.newSAXParser();
        parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");

        File xmlFile = new File(getClass().getResource(XML_FILE_NAME).getPath());

        parser.parse(xmlFile, new DefaultHandler());
    } catch (Exception e) {
        System.err.println("Failure: File " + XML_FILE_NAME + " was parsed with a large value of maxOccurs.");
        e.printStackTrace();
        Assert.fail("Failure: File " + XML_FILE_NAME + " was parsed with a large value of maxOccurs.  " + e.getMessage());
    }

    System.out.println("Success: File " + XML_FILE_NAME + " was parsed with a large value of maxOccurs.");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:Bug4674384_MAX_OCCURS_Test.java

示例2: testMaxOccurLimitPos

import javax.xml.parsers.SAXParserFactory; //导入方法依赖的package包/类
/**
 * Testing set MaxOccursLimit to 10000 in the secure processing enabled for
 * SAXParserFactory.
 *
 * @throws Exception If any errors occur.
 */
@Test
public void testMaxOccurLimitPos() throws Exception {
    String schema_file = XML_DIR + "toys.xsd";
    String xml_file = XML_DIR + "toys.xml";
    SAXParserFactory factory = SAXParserFactory.newInstance();
    factory.setValidating(true);
    factory.setFeature(FEATURE_SECURE_PROCESSING, true);
    setSystemProperty(SP_MAX_OCCUR_LIMIT, String.valueOf(10000));
    SAXParser parser = factory.newSAXParser();
    parser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA_NS_URI);
    parser.setProperty(JAXP_SCHEMA_SOURCE, new File(schema_file));
    try (InputStream is = new FileInputStream(xml_file)) {
        MyErrorHandler eh = new MyErrorHandler();
        parser.parse(is, eh);
        assertFalse(eh.isAnyError());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:AuctionItemRepository.java

示例3: test

import javax.xml.parsers.SAXParserFactory; //导入方法依赖的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

示例4: createReader

import javax.xml.parsers.SAXParserFactory; //导入方法依赖的package包/类
private XMLReader createReader() throws SAXException {
    try {
        SAXParserFactory pfactory = SAXParserFactory.newInstance();
        pfactory.setValidating(false);
        pfactory.setNamespaceAware(true);

        // Enable schema validation
        SchemaFactory sfactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
        InputStream stream = Parser.class.getResourceAsStream("graphdocument.xsd");
        pfactory.setSchema(sfactory.newSchema(new Source[]{new StreamSource(stream)}));

        return pfactory.newSAXParser().getXMLReader();
    } catch (ParserConfigurationException ex) {
        throw new SAXException(ex);
    }
}
 
开发者ID:arodchen,项目名称:MaxSim,代码行数:17,代码来源:Parser.java

示例5: parseTheme

import javax.xml.parsers.SAXParserFactory; //导入方法依赖的package包/类
private void parseTheme(){
    try{
        SAXParserFactory factory = SAXParserFactory.newInstance();
        factory.setValidating(false);
        factory.setNamespaceAware(false);

        Parser p = new XMLReaderAdapter(factory.newSAXParser().getXMLReader());
        p.setDocumentHandler(this);
        String externalForm = themeURL.toExternalForm();
        InputSource is = new InputSource(externalForm);
        p.parse(is);
        activeThemes=null;  //dispose of now useless hashtable
        locator = null;
    }
    catch(java.io.IOException ie){
        System.err.println ("IO exception reading theme file"); //NOI18N
    } catch(org.xml.sax.SAXException se){
        System.err.println ("Error parsing theme file " + (locator != null ? "line " + locator.getLineNumber() : "")); //NOI18N
    } catch (ParserConfigurationException e) {
        System.err.println ("Couldn't create XML parser for theme file"); //NOI18N
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:NbTheme.java

示例6: createXMLReader

import javax.xml.parsers.SAXParserFactory; //导入方法依赖的package包/类
/** Creates a SAX parser.
 *
 * <p>See {@link #parse} for hints on setting an entity resolver.
 *
 * @param validate if true, a validating parser is returned
 * @param namespaceAware if true, a namespace aware parser is returned
 *
 * @throws FactoryConfigurationError Application developers should never need to directly catch errors of this type.
 * @throws SAXException if a parser fulfilling given parameters can not be created
 *
 * @return XMLReader configured according to passed parameters
 */
public static synchronized XMLReader createXMLReader(boolean validate, boolean namespaceAware)
throws SAXException {
    SAXParserFactory factory = saxes[validate ? 0 : 1][namespaceAware ? 0 : 1];
    if (factory == null) {
        try {
            factory = SAXParserFactory.newInstance();
        } catch (FactoryConfigurationError err) {
            Exceptions.attachMessage(
                err, 
                "Info about thread context classloader: " + // NOI18N
                Thread.currentThread().getContextClassLoader()
            );
            throw err;
        }
        factory.setValidating(validate);
        factory.setNamespaceAware(namespaceAware);
        saxes[validate ? 0 : 1][namespaceAware ? 0 : 1] = factory;
    }

    try {
        return factory.newSAXParser().getXMLReader();
    } catch (ParserConfigurationException ex) {
        throw new SAXException("Cannot create parser satisfying configuration parameters", ex); //NOI18N                        
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:38,代码来源:XMLUtil.java

示例7: createParser

import javax.xml.parsers.SAXParserFactory; //导入方法依赖的package包/类
protected static SAXParser createParser() throws Exception {
    SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setNamespaceAware(true);
    spf.setValidating(true);
    SAXParser parser = spf.newSAXParser();
    parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");

    return parser;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:Bug4991946.java

示例8: testGetOwnerItemList1

import javax.xml.parsers.SAXParserFactory; //导入方法依赖的package包/类
/**
 * Check for the same imported schemas but will use SAXParserFactory and try
 * parsing using the SAXParser. SCHEMA_SOURCE attribute is using for this
 * test.
 *
 * @throws Exception If any errors occur.
 * @see <a href="content/coins.xsd">coins.xsd</a>
 * @see <a href="content/coinsImportMe.xsd">coinsImportMe.xsd</a>
 */

@Test
public void testGetOwnerItemList1() throws Exception {
    String xsdFile = XML_DIR + "coins.xsd";
    String xmlFile = XML_DIR + "coins.xml";
    SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setNamespaceAware(true);
    spf.setValidating(true);

    SAXParser sp = spf.newSAXParser();
    sp.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA_NS_URI);
    sp.setProperty(JAXP_SCHEMA_SOURCE, xsdFile);

    MyErrorHandler eh = new MyErrorHandler();
    sp.parse(new File(xmlFile), eh);
    assertFalse(eh.isAnyError());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:AuctionController.java

示例9: createReader

import javax.xml.parsers.SAXParserFactory; //导入方法依赖的package包/类
private XMLReader createReader() throws SAXException {
    try {
        SAXParserFactory pfactory = SAXParserFactory.newInstance();
        pfactory.setValidating(true);
        pfactory.setNamespaceAware(true);

        // Enable schema validation
        SchemaFactory sfactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
        InputStream stream = Parser.class.getResourceAsStream("graphdocument.xsd");
        pfactory.setSchema(sfactory.newSchema(new Source[]{new StreamSource(stream)}));

        return pfactory.newSAXParser().getXMLReader();
    } catch (ParserConfigurationException ex) {
        throw new SAXException(ex);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:Parser.java

示例10: load

import javax.xml.parsers.SAXParserFactory; //导入方法依赖的package包/类
public static void load(ThemeNULL theme, InputStream in) throws IOException {
	SAXParserFactory spf = SAXParserFactory.newInstance();
	spf.setValidating(true);
	try {
		SAXParser parser = spf.newSAXParser();
		XMLReader reader = parser.getXMLReader();
		XmlHandler handler = new XmlHandler();
		handler.theme = theme;
		reader.setEntityResolver(handler);
		reader.setContentHandler(handler);
		reader.setDTDHandler(handler);
		reader.setErrorHandler(handler);
		InputSource is = new InputSource(in);
		is.setEncoding("UTF-8");
		reader.parse(is);
	} catch (/*SAX|ParserConfiguration*/Exception se) {
		se.printStackTrace();
		throw new IOException(se.toString());
	}
}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:21,代码来源:ThemeNULL.java

示例11: setupReaders

import javax.xml.parsers.SAXParserFactory; //导入方法依赖的package包/类
/**
 * Setup readers.
 */
public void setupReaders() {
  SAXParserFactory spf = catalogManager.useServicesMechanism() ?
                  SAXParserFactory.newInstance() : new SAXParserFactoryImpl();
  spf.setNamespaceAware(true);
  spf.setValidating(false);

  SAXCatalogReader saxReader = new SAXCatalogReader(spf);

  saxReader.setCatalogParser(null, "XMLCatalog",
                             "com.sun.org.apache.xml.internal.resolver.readers.XCatalogReader");

  saxReader.setCatalogParser(OASISXMLCatalogReader.namespaceName,
                             "catalog",
                             "com.sun.org.apache.xml.internal.resolver.readers.ExtendedXMLCatalogReader");

  addReader("application/xml", saxReader);

  TR9401CatalogReader textReader = new TR9401CatalogReader();
  addReader("text/plain", textReader);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:24,代码来源:Resolver.java

示例12: testSAX

import javax.xml.parsers.SAXParserFactory; //导入方法依赖的package包/类
@Test
public void testSAX() {
    try {
        Schema schema = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(new StreamSource(_xsd));
        SAXParserFactory spf = SAXParserFactory.newInstance();
        spf.setNamespaceAware(true);
        spf.setValidating(true);
        spf.setSchema(schema);
        SAXParser parser = spf.newSAXParser();
        MyErrorHandler errorHandler = new MyErrorHandler();
        parser.parse(_xml, errorHandler);
        if (!errorHandler.errorOccured) {
            Assert.fail("should report error");
        }
    } catch (Exception e) {
        System.out.println(e.getMessage());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:Bug6974551Test.java

示例13: testException

import javax.xml.parsers.SAXParserFactory; //导入方法依赖的package包/类
@Test
public void testException() {
    try {
        SAXParserFactory factory = SAXParserFactory.newInstance();
        factory.setNamespaceAware(true);
        factory.setValidating(true);
        SAXParser saxParser = factory.newSAXParser();

        saxParser.parse(new ByteArrayInputStream(textXML.getBytes()), new TestFilter());

    } catch (Throwable t) {
        t.printStackTrace();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:Bug6949607Test.java

示例14: getParser

import javax.xml.parsers.SAXParserFactory; //导入方法依赖的package包/类
/**
 * Returns a SAXParser instance
 * @return a SAXParser instance
 * @throws CatalogException if constructing a SAXParser failed
 */
private SAXParser getParser() {
    SAXParser p = null;
    try {
        SAXParserFactory spf = new SAXParserFactoryImpl();
        spf.setNamespaceAware(true);
        spf.setValidating(false);
        spf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
        p = spf.newSAXParser();
    } catch (ParserConfigurationException | SAXException e) {
        CatalogMessages.reportRunTimeError(CatalogMessages.ERR_PARSING_FAILED, e);
    }
    return p;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:CatalogImpl.java

示例15: testNbfsTransformation2

import javax.xml.parsers.SAXParserFactory; //导入方法依赖的package包/类
public void testNbfsTransformation2() throws IOException, SAXException, ParserConfigurationException {
    checkSetUp();
    // additional check
    if (fs.isReadOnly() || root.isReadOnly()) return;
    String sysName = fs.getSystemName();
    if (sysName == null || sysName.length() == 0)
        return;
    if (Repository.getDefault().findFileSystem(fs.getSystemName()) == null)
        Repository.getDefault().addFileSystem(fs);

    
    InputStream inputStream = null;
    try {
        FileObject test = getTestFolder1(root);
        FileObject f = test.createData("layer.xml");
        createSimpleXML(f);
        SAXParserFactory pFactory = SAXParserFactory.newInstance();
        pFactory.setValidating (false);
        Parser p = pFactory.newSAXParser().getParser();
        p.setDocumentHandler(new HandlerBase());
        URL u = f.toURL();
        p.parse(u.toExternalForm());
        //
        byte[] b = new byte[10];
        inputStream = u.openConnection().getInputStream();
        inputStream.read(b);
        fsAssert("Nbfs check: unexpected content ", (new String (b)).startsWith("<?xml"));
    } finally {
        Repository.getDefault().removeFileSystem(fs);
        if (inputStream != null) inputStream.close();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:33,代码来源:FileObjectTestHid.java


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