當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。