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


Java SAXParserFactory.setNamespaceAware方法代码示例

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


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

示例1: testWithTrueTrue

import javax.xml.parsers.SAXParserFactory; //导入方法依赖的package包/类
/**
 * namespace processing is enabled. namespace-prefix is also is enabled.
 * So it is a True-True combination.
 * The test is to test XMLReader with these conditions.
 *
 * @throws Exception If any errors occur.
 */
public void testWithTrueTrue() throws Exception {
    String outputFile = USER_DIR + "XRNSTableTT.out";
    String goldFile = GOLDEN_DIR + "NSTableTTGF.out";

    SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setNamespaceAware(true);
    XMLReader xmlReader = spf.newSAXParser().getXMLReader();
    xmlReader.setFeature(NAMESPACE_PREFIXES, true);

    try (FileInputStream fis = new FileInputStream(xmlFile);
        MyNSContentHandler handler = new MyNSContentHandler(outputFile);) {
        xmlReader.setContentHandler(handler);
        xmlReader.parse(new InputSource(fis));
    }
    assertTrue(compareWithGold(goldFile, outputFile));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:XMLReaderNSTableTest.java

示例2: 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

示例3: initParser

import javax.xml.parsers.SAXParserFactory; //导入方法依赖的package包/类
/** Initialize the parser. */
private void initParser() {
  catalogResolver = new CatalogResolver(catalogManager);
  SAXParserFactory spf = catalogManager.useServicesMechanism() ?
                  SAXParserFactory.newInstance() : new SAXParserFactoryImpl();
  spf.setNamespaceAware(namespaceAware);
  spf.setValidating(validating);

  try {
    saxParser = spf.newSAXParser();
    parser = saxParser.getParser();
    documentHandler = null;
    dtdHandler = null;
  } catch (Exception ex) {
    ex.printStackTrace();
  }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:18,代码来源:ResolvingParser.java

示例4: testPath

import javax.xml.parsers.SAXParserFactory; //导入方法依赖的package包/类
@Test
public void testPath() throws Exception {
    if (isWindows) {
        try {
            SAXParserFactory factory = SAXParserFactory.newInstance();
            factory.setNamespaceAware(true);
            SAXParser jaxpParser = factory.newSAXParser();
            XMLReader reader = jaxpParser.getXMLReader();
            reader.parse("C:/space error/x.xml");
            System.exit(0);
        } catch (Exception e) {
            System.out.println(e.getMessage());
            if (e.getMessage().equalsIgnoreCase("unknown protocol: c")) {
                Assert.fail("jdk5 allowed the above form");
            } else if (e.getMessage().indexOf("(The system cannot find the path specified)") > 0) {
                // expected
            }
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:Bug6506304Test.java

示例5: newSAXParserFactory

import javax.xml.parsers.SAXParserFactory; //导入方法依赖的package包/类
public static SAXParserFactory newSAXParserFactory(boolean disableSecurity) {
    SAXParserFactory factory = SAXParserFactory.newInstance();
    String featureToSet = XMLConstants.FEATURE_SECURE_PROCESSING;
    try {
        boolean securityOn = !xmlSecurityDisabled(disableSecurity);
        factory.setFeature(featureToSet, securityOn);
        factory.setNamespaceAware(true);
        if (securityOn) {
            featureToSet = DISALLOW_DOCTYPE_DECL;
            factory.setFeature(featureToSet, true);
            featureToSet = EXTERNAL_GE;
            factory.setFeature(featureToSet, false);
            featureToSet = EXTERNAL_PE;
            factory.setFeature(featureToSet, false);
            featureToSet = LOAD_EXTERNAL_DTD;
            factory.setFeature(featureToSet, false);
        }
    } catch (ParserConfigurationException | SAXNotRecognizedException | SAXNotSupportedException e) {
        LOGGER.log(Level.WARNING, "Factory [{0}] doesn't support "+featureToSet+" feature!", new Object[]{factory.getClass().getName()});
    }
    return factory;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:XmlUtil.java

示例6: testWithTrueTrue

import javax.xml.parsers.SAXParserFactory; //导入方法依赖的package包/类
/**
 * namespace processing is enabled. namespace-prefix is also is enabled.
 * So it is a True-True combination.
 * The test is to test SAXParser with these conditions.
 *
 * @throws Exception If any errors occur.
 */
@Test
public void testWithTrueTrue() throws Exception {
    String outputFile = USER_DIR + "SPNSTableTT.out";
    String goldFile = GOLDEN_DIR + "NSTableTTGF.out";
    String xmlFile = XML_DIR + "namespace1.xml";
    SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setNamespaceAware(true);
    spf.setFeature("http://xml.org/sax/features/namespace-prefixes",
                                true);
    try (MyNSContentHandler handler = new MyNSContentHandler(outputFile)) {
        spf.newSAXParser().parse(new File(xmlFile), handler);
    }
    assertTrue(compareWithGold(goldFile, outputFile));

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:SAXParserNSTableTest.java

示例7: spNSTable01

import javax.xml.parsers.SAXParserFactory; //导入方法依赖的package包/类
/**
 * Here namespace processing and namespace-prefixes are enabled.
 * The testcase tests SAXParserFactory for this.
 *
 * @throws Exception If any errors occur.
 */
@Test
public void spNSTable01() throws Exception {
    SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setNamespaceAware(true);
    spf.setFeature(NAMESPACE_PREFIXES,true);
    assertTrue(spf.getFeature(NAMESPACES));
    assertTrue(spf.getFeature(NAMESPACE_PREFIXES));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:NSTableTest.java

示例8: test

import javax.xml.parsers.SAXParserFactory; //导入方法依赖的package包/类
@Test
public void test() throws Exception {
    SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setNamespaceAware(true);
    XMLReader reader = spf.newSAXParser().getXMLReader();
    reader.setErrorHandler(null); // SAX 2.0.1 allows
    reader.setContentHandler(null); // SAX 2.0.1 allows
    reader.setEntityResolver(null); // SAX 2.0.1 allows
    reader.setDTDHandler(null); // SAX 2.0.1 allows
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:SAX201Test.java

示例9: getFeature01

import javax.xml.parsers.SAXParserFactory; //导入方法依赖的package包/类
/**
 * By default true is expected get namespaces feature.
 *
 * @throws Exception If any errors occur.
 */
@Test
public void getFeature01() throws Exception {
    SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setNamespaceAware(true);
    XMLReader xmlReader = spf.newSAXParser().getXMLReader();

    XMLFilterImpl xmlFilter = new XMLFilterImpl();
    xmlFilter.setParent(xmlReader);
    assertTrue(xmlFilter.getFeature(NAMESPACES));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:XMLFilterTest.java

示例10: parse02

import javax.xml.parsers.SAXParserFactory; //导入方法依赖的package包/类
/**
 * Unit test for parse a error-formatted file. SAXException is expected.
 *
 * @throws Exception If any errors occur.
 */
@Test(expectedExceptions = SAXException.class)
public void parse02() throws Exception {
    try (FileInputStream fis = new FileInputStream(XML_DIR + "invalid.xml")) {
        SAXParserFactory spf = SAXParserFactory.newInstance();
        spf.setNamespaceAware(true);
        spf.newSAXParser().getXMLReader().parse(new InputSource(fis));
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:XMLReaderTest.java

示例11: testNamespace02

import javax.xml.parsers.SAXParserFactory; //导入方法依赖的package包/类
/**
 * Test case to test setnamespaceAware() method.
 *
 * @throws Exception If any errors occur.
 */
@Test
public void testNamespace02() throws Exception {
    SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setNamespaceAware(true);
    SAXParser saxparser = spf.newSAXParser();
    assertTrue(saxparser.isNamespaceAware());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:SAXParserTest02.java

示例12: setFeature02

import javax.xml.parsers.SAXParserFactory; //导入方法依赖的package包/类
/**
 * Set namespaces-prefix feature to a value to XMLFilter. it's expected same
 * when obtain it again.
 *
 * @throws Exception If any errors occur.
 */
@Test
public void setFeature02() throws Exception {
    SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setNamespaceAware(true);

    XMLFilterImpl xmlFilter = new XMLFilterImpl();
    xmlFilter.setParent(spf.newSAXParser().getXMLReader());
    xmlFilter.setFeature(NAMESPACE_PREFIXES, false);
    assertFalse(xmlFilter.getFeature(NAMESPACE_PREFIXES));
    xmlFilter.setFeature(NAMESPACE_PREFIXES, true);
    assertTrue(xmlFilter.getFeature(NAMESPACE_PREFIXES));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:XMLFilterTest.java

示例13: createParser

import javax.xml.parsers.SAXParserFactory; //导入方法依赖的package包/类
/**
 * Creates a SAX parser using JAXP
 * 
 * @return the created SAX parser
 */
static XMLReader createParser() {
  try {
    SAXParserFactory factory = SAXParserFactory.newInstance();
    factory.setNamespaceAware(true);
    return factory.newSAXParser().getXMLReader();
  } catch (Exception e) {
    throw new RuntimeException("Couldn't create XMLReader: " + e.getMessage());
  }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:15,代码来源:PatternParser.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: setupXmlParser

import javax.xml.parsers.SAXParserFactory; //导入方法依赖的package包/类
/**
     * @param entityResolver2
     * @return
     * @throws SAXNotRecognizedException
     * @throws SAXNotSupportedException
     */
    protected void setupXmlParser() throws SAXNotRecognizedException,
            SAXNotSupportedException,
            ParserConfigurationException,
            SAXException {

        SAXParserFactory factory = SAXParserFactory.newInstance();
        factory.setNamespaceAware(true);
        factory.setValidating(false);
        xmlParser = factory.newSAXParser();
//        xmlParser.getXMLReader().setFeature(
//                "http://apache.org/xml/features/continue-after-fatal-error",
//                true);
        sourceReader.addCharacterHandler(sourceCode);
        reader = new IdFilter(xmlParser.getXMLReader());
        if (lexicalHandler != null) {
            xmlParser.setProperty("http://xml.org/sax/properties/lexical-handler",
                    (LexicalHandler) lexicalHandler);
        }

        reader.setFeature("http://xml.org/sax/features/string-interning", true);
        reader.setFeature(
                "http://xml.org/sax/features/external-general-entities",
                parser == ParserMode.XML_EXTERNAL_ENTITIES_NO_VALIDATION);
        reader.setFeature(
                "http://xml.org/sax/features/external-parameter-entities",
                parser == ParserMode.XML_EXTERNAL_ENTITIES_NO_VALIDATION);
        if (parser == ParserMode.XML_EXTERNAL_ENTITIES_NO_VALIDATION) {
            reader.setEntityResolver(entityResolver);
        } else {
            reader.setEntityResolver(new NullEntityResolver());
        }
        if (validator == null) {
            bufferingRootNamespaceSniffer = new BufferingRootNamespaceSniffer(
                    this);
            reader.setContentHandler(bufferingRootNamespaceSniffer);
        } else {
            reader.setContentHandler(new RootNamespaceSniffer(this,
                    validator.getContentHandler()));
            reader.setDTDHandler(validator.getDTDHandler());
        }
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:48,代码来源:NbValidationTransaction.java


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