Java - Reading Comment from XML-File

拥有回忆 提交于 2019-12-05 20:32:08

You need to implement a lexical handler. More information over here - http://docs.oracle.com/javase/tutorial/jaxp/dom/readingXML.html

Look at the Lexical Controls chapter.

I suggest StAX, fastest and simple

    XMLStreamReader xr = XMLInputFactory.newInstance().createXMLStreamReader(
            new FileInputStream("1.xml"));
    while (xr.hasNext()) {
        if (xr.next() == XMLStreamConstants.COMMENT) {
            String comment = xr.getText();
        }
    }

Are you using XPath? If yes, you can select comments with comment() function.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!