本文整理匯總了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.");
}
示例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());
}
}
示例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);
}
示例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);
}
}
示例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
}
}
示例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
}
}
示例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;
}
示例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());
}
示例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);
}
}
示例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());
}
}
示例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);
}
示例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());
}
}
示例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();
}
}
示例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;
}
示例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();
}
}