本文整理匯總了Java中javax.xml.parsers.DocumentBuilderFactory.setSchema方法的典型用法代碼示例。如果您正苦於以下問題:Java DocumentBuilderFactory.setSchema方法的具體用法?Java DocumentBuilderFactory.setSchema怎麽用?Java DocumentBuilderFactory.setSchema使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.xml.parsers.DocumentBuilderFactory
的用法示例。
在下文中一共展示了DocumentBuilderFactory.setSchema方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testDOM
import javax.xml.parsers.DocumentBuilderFactory; //導入方法依賴的package包/類
@Test
public void testDOM() throws ParserConfigurationException, SAXException, IOException {
InputStream xmlFile = getClass().getResourceAsStream("Bug6564400.xml");
// Set the options on the DocumentFactory to remove comments, remove
// whitespace
// and validate against the schema.
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
docFactory.setIgnoringComments(true);
docFactory.setIgnoringElementContentWhitespace(true);
docFactory.setSchema(schema);
DocumentBuilder parser = docFactory.newDocumentBuilder();
Document xmlDoc = parser.parse(xmlFile);
boolean ok = dump(xmlDoc, true);
Assert.assertEquals(true, ok);
}
示例2: initializePool
import javax.xml.parsers.DocumentBuilderFactory; //導入方法依賴的package包/類
/**
* Initializes the pool with a new set of configuration options.
*
* @throws XMLParserException thrown if there is a problem initialzing the pool
*/
protected synchronized void initializePool() throws XMLParserException {
if (!dirtyBuilderConfiguration) {
// in case the pool was initialized by some other thread
return;
}
DocumentBuilderFactory newFactory = DocumentBuilderFactory.newInstance();
setAttributes(newFactory, builderAttributes);
setFeatures(newFactory, builderFeatures);
newFactory.setCoalescing(coalescing);
newFactory.setExpandEntityReferences(expandEntityReferences);
newFactory.setIgnoringComments(ignoreComments);
newFactory.setIgnoringElementContentWhitespace(ignoreElementContentWhitespace);
newFactory.setNamespaceAware(namespaceAware);
newFactory.setSchema(schema);
newFactory.setValidating(dtdValidating);
newFactory.setXIncludeAware(xincludeAware);
poolVersion++;
dirtyBuilderConfiguration = false;
builderFactory = newFactory;
builderPool.clear();
}
示例3: setDocument
import javax.xml.parsers.DocumentBuilderFactory; //導入方法依賴的package包/類
/**
* Loads the document used for signing/verification/redaction from the given input stream.
* <p>
* The document is checked against the given schema and the given error handler is used.
*
* @param inputStream the input stream
* @param schema the schema of the loaded XML document
* @param handler the errorhandler
* @throws RedactableXMLSignatureException if this RedactableXMLSignature object is not properly initialized
*/
public final void setDocument(InputStream inputStream, Schema schema, ErrorHandler handler)
throws RedactableXMLSignatureException {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setSchema(schema);
documentBuilderFactory.setNamespaceAware(true);
documentBuilderFactory.setIgnoringElementContentWhitespace(true);
try {
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
documentBuilder.setErrorHandler(handler);
setDocument(documentBuilder.parse(inputStream));
} catch (ParserConfigurationException | SAXException | IOException e) {
throw new RedactableXMLSignatureException(e);
}
}
示例4: testUsingDocumentBuilderFactory
import javax.xml.parsers.DocumentBuilderFactory; //導入方法依賴的package包/類
/**
* XERCESJ-1141 root-type-definition property not read by XMLSchemaValidator during reset()
*/
@Test
public void testUsingDocumentBuilderFactory() throws Exception {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setAttribute(ROOT_TYPE, typeX);
dbf.setAttribute(DOCUMENT_CLASS_NAME,"com.sun.org.apache.xerces.internal.dom.PSVIDocumentImpl");
dbf.setNamespaceAware(true);
dbf.setValidating(false);
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
dbf.setSchema(sf.newSchema(fSchemaURL));
DocumentBuilder db = dbf.newDocumentBuilder();
Document document = db.parse(fDocumentURL.toExternalForm());
ElementPSVI rootNode = (ElementPSVI) document.getDocumentElement();
assertValidity(ItemPSVI.VALIDITY_VALID, rootNode.getValidity());
assertValidationAttempted(ItemPSVI.VALIDATION_FULL, rootNode
.getValidationAttempted());
assertElementNull(rootNode.getElementDeclaration());
assertTypeName("X", rootNode.getTypeDefinition().getName());
}
示例5: testConformantDOM
import javax.xml.parsers.DocumentBuilderFactory; //導入方法依賴的package包/類
@Test
public void testConformantDOM() throws ParserConfigurationException, SAXException, IOException {
InputStream xmlFile = getClass().getResourceAsStream("Bug6564400.xml");
// Set the options on the DocumentFactory to remove comments, remove
// whitespace
// and validate against the schema.
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
docFactory.setIgnoringComments(true);
docFactory.setIgnoringElementContentWhitespace(true);
docFactory.setSchema(schema);
docFactory.setFeature("http://java.sun.com/xml/schema/features/report-ignored-element-content-whitespace", true);
DocumentBuilder parser = docFactory.newDocumentBuilder();
Document xmlDoc = parser.parse(xmlFile);
boolean ok = dump(xmlDoc, true);
Assert.assertEquals(false, ok);
}
示例6: setAttr
import javax.xml.parsers.DocumentBuilderFactory; //導入方法依賴的package包/類
void setAttr(boolean setSrc) {
DocumentBuilderFactory docBFactory = DocumentBuilderFactory.newInstance();
Schema sch = createSchema();
docBFactory.setSchema(sch);
docBFactory.setNamespaceAware(true);
docBFactory.setValidating(true);
final String aSchemaLanguage = "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
final String aSchemaSource = "http://java.sun.com/xml/jaxp/properties/schemaSource";
docBFactory.setAttribute(aSchemaLanguage, "http://www.w3.org/2001/XMLSchema");
// System.out.println("---- Set schemaLanguage: " +
// docBFactory.getAttribute(aSchemaLanguage));
if (setSrc) {
docBFactory.setAttribute(aSchemaSource, new InputSource(new StringReader(schemaSource)));
// System.out.println("---- Set schemaSource: " +
// docBFactory.getAttribute(aSchemaSource));
}
try {
docBFactory.newDocumentBuilder();
Assert.fail("ParserConfigurationException expected");
} catch (ParserConfigurationException pce) {
return; // success
}
}
示例7: parseAndValidate
import javax.xml.parsers.DocumentBuilderFactory; //導入方法依賴的package包/類
/**
* Parse XML document and validate against CAS schema
*/
private Document parseAndValidate(String xml) throws Exception {
Schema schema = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI)
.newSchema(getClass().getResource("cas-response-schema.xsd"));
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setSchema(schema);
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
builder.setErrorHandler(new FatalAdapter(new DefaultHandler()));
return builder.parse(new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)));
}
示例8: initializeFactory
import javax.xml.parsers.DocumentBuilderFactory; //導入方法依賴的package包/類
/**
* Initializes the pool with a new set of configuration options.
*
* @throws XMLParserException thrown if there is a problem initialzing the pool
*/
protected synchronized void initializeFactory() throws XMLParserException {
DocumentBuilderFactory newFactory = DocumentBuilderFactory.newInstance();
setAttributes(newFactory, builderAttributes);
setFeatures(newFactory, builderFeatures);
newFactory.setCoalescing(coalescing);
newFactory.setExpandEntityReferences(expandEntityReferences);
newFactory.setIgnoringComments(ignoreComments);
newFactory.setIgnoringElementContentWhitespace(ignoreElementContentWhitespace);
newFactory.setNamespaceAware(namespaceAware);
newFactory.setSchema(schema);
newFactory.setValidating(dtdValidating);
newFactory.setXIncludeAware(xincludeAware);
builderFactory = newFactory;
}