Search code examples
javaeclipsexml-parsingnormalization

Issue in XML Parsing through Java


I have the following simple XML structure that has to be parsed:

<Nodes>
  <Node id="1">
      <att1>
      <att2>
      ...
  </Node>
  <Node id="2">
      ...
</Nodes>

Now the problem is simple that while parsing this file through Java code I am receiving the "line returns" as seperate nodes which is causing complexity in the processing ... I am even using the normalize method for DOMParsers but it doesn't seem to work.. below is the parser code:

public LogParser(File XMLFile) throws ParserConfigurationException,
        SAXException, IOException {
    //Logger.printInfoMessage("XML file to be parsed is "+XMLFile.toString());
     DocumentBuilder documentBuilder = getDocumentBuilder();
    doc = documentBuilder.parse(XMLFile);
    doc.normalizeDocument();

}

Solution

  • I think that the problem is that normalizeDocument() normalizes based on the normalization options that you have previously specified .... and you haven't specified any.

    I haven't read it in detail, but this page seems to explain how to deal with this.

    It is worth noting that (according to the link above) not all XML parsers support this feature.