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


Java DTD.getNotations方法代码示例

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


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

示例1: testDTDEvent

import javax.xml.stream.events.DTD; //导入方法依赖的package包/类
/**
 * DTDEvent instances constructed via event reader are missing the notation
 * and entity declaration information
 */
@Test
public void testDTDEvent() {
    String XML = "<?xml version='1.0' ?>" + "<!DOCTYPE root [\n" + "<!ENTITY intEnt 'internal'>\n" + "<!ENTITY extParsedEnt SYSTEM 'url:dummy'>\n"
            + "<!NOTATION notation PUBLIC 'notation-public-id'>\n" + "<!NOTATION notation2 SYSTEM 'url:dummy'>\n"
            + "<!ENTITY extUnparsedEnt SYSTEM 'url:dummy2' NDATA notation>\n" + "]>" + "<root />";

    try {
        XMLEventReader er = getReader(XML);
        XMLEvent evt = er.nextEvent(); // StartDocument
        evt = er.nextEvent(); // DTD
        if (evt.getEventType() != XMLStreamConstants.DTD) {
            Assert.fail("Expected DTD event");
        }
        DTD dtd = (DTD) evt;
        writeAsEncodedUnicode(dtd);
        List entities = dtd.getEntities();
        if (entities == null) {
            Assert.fail("No entity found. Expected 3.");
        } else {
            writeAsEncodedUnicode((XMLEvent) entities.get(0));
            writeAsEncodedUnicode((XMLEvent) entities.get(1));
            writeAsEncodedUnicode((XMLEvent) entities.get(2));
        }

        List notations = dtd.getNotations();
        if (notations == null) {
            Assert.fail("No notation found. Expected 2.");
        } else {
            writeAsEncodedUnicode((XMLEvent) notations.get(0));
            writeAsEncodedUnicode((XMLEvent) notations.get(1));
        }
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:40,代码来源:Issue41Test.java

示例2: testDTDEvent

import javax.xml.stream.events.DTD; //导入方法依赖的package包/类
/**
 * DTDEvent instances constructed via event reader are missing the notation
 * and entity declaration information
 */
@Test
public void testDTDEvent() {
    String XML = "<?xml version='1.0' ?>" + "<!DOCTYPE root [\n" + "<!ENTITY intEnt 'internal'>\n" + "<!ENTITY extParsedEnt SYSTEM 'url:dummy'>\n"
            + "<!NOTATION notation PUBLIC 'notation-public-id'>\n" + "<!NOTATION notation2 SYSTEM 'url:dummy'>\n"
            + "<!ENTITY extUnparsedEnt SYSTEM 'url:dummy2' NDATA notation>\n" + "]>" + "<root />";

    try {
        XMLEventReader er = getReader(XML);
        XMLEvent evt = er.nextEvent(); // StartDocument
        evt = er.nextEvent(); // DTD
        if (evt.getEventType() != XMLStreamConstants.DTD) {
            Assert.fail("Expected DTD event");
        }
        DTD dtd = (DTD) evt;
        List entities = dtd.getEntities();
        if (entities == null) {
            Assert.fail("No entity found. Expected 3.");
        } else {
            Assert.assertEquals(entities.size(), 3);
        }
        // Let's also verify they are all of right type...
        testListElems(entities, EntityDeclaration.class);

        List notations = dtd.getNotations();
        if (notations == null) {
            Assert.fail("No notation found. Expected 2.");
        } else {
            Assert.assertEquals(notations.size(), 2);
        }
        // Let's also verify they are all of right type...
        testListElems(notations, NotationDeclaration.class);
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:40,代码来源:Issue48Test.java

示例3: testDtdNotations

import javax.xml.stream.events.DTD; //导入方法依赖的package包/类
/**
 * As of Stax 3.0 (Woodstox 4.0+), there is additional info for
 * NotationDeclarations (base URI). Let's verify it gets properly
 * populated.
 */
public void testDtdNotations()
    throws Exception
{
    final String URI = "http://test";

    /* Ok. And here we should just check that we do not get 2 adjacent
     * separate Characters event. We can try to trigger this by long
     * segment and a set of char entities...
     */
    final String XML = "<?xml version='1.0'?>"
        +"<!DOCTYPE root [\n"
        +"<!ELEMENT root EMPTY>\n"
        +"<!NOTATION not PUBLIC 'some-public-id'>\n"
        +"]>"
        +"<root/>";
	
    // Need to disable coalescing though for test to work:
    XMLEventReader2 er = getReader(XML, false);
    // Need to set Base URI; can do it for factory or instance
    er.setProperty(WstxInputProperties.P_BASE_URL, new URL(URI));
    assertTrue(er.nextEvent().isStartDocument());
    XMLEvent evt = er.nextEvent(); // DTD
    assertTokenType(DTD, evt.getEventType());

    DTD dtd = (DTD) evt;
    List<?> nots = dtd.getNotations();
    assertEquals(1, nots.size());
    NotationDeclaration2 notDecl = (NotationDeclaration2) nots.get(0);

    assertEquals(URI, notDecl.getBaseURI());
}
 
开发者ID:FasterXML,项目名称:woodstox,代码行数:37,代码来源:TestEventReader.java


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