Bug6555001.java 文件源码

java
阅读 20 收藏 0 点赞 0 评论 0

项目:openjdk9 作者:
@Test
public void testReplacing() throws Exception {
    XMLInputFactory factory = XMLInputFactory.newInstance();
    factory.setProperty("javax.xml.stream.isReplacingEntityReferences", true);

    StringReader sr = new StringReader(XML);
    XMLEventReader reader = factory.createXMLEventReader(sr);

    boolean sawUndef = false;
    boolean sawDef = false;

    while (reader.hasNext()) {
        XMLEvent event = reader.nextEvent();
        // System.out.println("Event: " + event);
        if (event.isEntityReference()) {
            EntityReference ref = (EntityReference) event;
            if ("def".equals(ref.getName())) {
                sawDef = true;
            } else if ("undef".equals(ref.getName())) {
                sawUndef = true;
            } else {
                throw new IllegalArgumentException("Unexpected entity name");
            }
        }
    }

    Assert.assertEquals(false, sawDef);
    Assert.assertEquals(true, sawUndef);
    reader.close();
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号