Search code examples
javaxmlxml-comments

Java - Reading Comment from XML-File


I have to extract comments from a XML-File. I couldn't find a way to get them using JDOM or something else. At the moment I use Regex and FileReader but I don't feel like this is the way to go.

Can you use something like JDOM to get comments from a XML-File? Or ist it limited to Elements/Nodes and Attributes?


Solution

  • 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.