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


Java DocumentBuilderFactory.setSchema方法代码示例

本文整理汇总了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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:Bug6564400.java

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

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

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

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

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

示例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)));
}
 
开发者ID:Doccrazy,项目名称:keycloak-protocol-cas,代码行数:15,代码来源:ServiceResponseTest.java

示例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;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:20,代码来源:StaticBasicParserPool.java


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