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


Java XMLStreamReader.getTextCharacters方法代码示例

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


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

示例1: getAndVerifyText

import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
/**
 * Method that not only gets currently available text from the reader, but
 * also checks that its consistenly accessible using different StAX methods.
 */
protected static String getAndVerifyText(XMLStreamReader sr) throws XMLStreamException {
    String text = sr.getText();

    /*
     * 05-Apr-2006, TSa: Although getText() is available for DTD and
     * ENTITY_REFERENCE, getTextXxx() are not. Thus, can not do more checks
     * for those types.
     */
    int type = sr.getEventType();
    if (type != ENTITY_REFERENCE && type != DTD) {
        Assert.assertNotNull("getText() should never return null.", text);
        int expLen = sr.getTextLength();
        /*
         * Hmmh. Can only return empty text for CDATA (since empty blocks
         * are legal).
         */
        /*
         * !!! 01-Sep-2004, TSa: note: theoretically, in coalescing mode, it
         * could be possible to have empty CDATA section(s) get converted to
         * CHARACTERS, which would be empty... may need to enhance this to
         * check that mode is not coalescing? Or something
         */
        if (sr.getEventType() == CHARACTERS) {
            if (expLen == 0) {
                Assert.fail("Stream reader should never return empty Strings.");
            }
        }
        Assert.assertEquals(expLen, text.length(), "Expected text length of " + expLen + ", got " + text.length());
        char[] textChars = sr.getTextCharacters();
        int start = sr.getTextStart();
        String text2 = new String(textChars, start, expLen);
        Assert.assertEquals("Expected getText() and getTextCharacters() to return same value for event of type (" + tokenTypeDesc(sr.getEventType()) + ")",
                text, text2);
    } else { // DTD or ENTITY_REFERENCE
        // not sure if null is legal for these either, but...
        if (text == null) { // let's prevent an NPE at caller
            text = "";
        }
    }
    return text;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:46,代码来源:BaseStAXUT.java


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