1
  • I want to parse and print XML tags using jdom2 (not w3c/xml.sax)

  • the root element is getting printed and the debug till before for loop is also there, but after that, there's blank, no syntax error, am I missing something in the for loop?

  • this is what my main looks like in the message reader class

public class XMLReaderDOM {
    public static void main(String[] args) {
        System.out.println("Starting out now");
        try {
            SAXBuilder builder = new SAXBuilder();
            File xmlFile = new File("file.xml");
            Document doc = (Document) builder.build(xmlFile);
            Element root = doc.getRootElement();
            System.out.println("Document built");
            List < Element > listGrpHdr = root.getChildren("GrpHdr");
            List < GrpHdr > grphdrList = new ArrayList <>();
            
            System.out.println("root element:" + doc.getRootElement().getName());        
            System.out.println("Right before for");
            
            for (Element grphdrElement: listGrpHdr){
                GrpHdr grphdr = new GrpHdr();
                System.out.println("before getting our elements");
                grphdr.setGrp_id(grphdrElement.getChildText("grp_id"));
                grphdr.setCreationDateTime(grphdrElement.getChildText("creationDateTime"));
                grphdr.setMessageType(grphdrElement.getChildText("messageType"));
                grphdr.setGrp_hdr_xml(grphdrElement.getChildText("grp_hdr_xml"));
                grphdrList.add(grphdr);
                
              }
            
            grphdrList.forEach(grphdr->{
                System.out.println(grphdr.toString());
            });
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
0m3r
  • 12,286
  • 15
  • 35
  • 71
K. Nik
  • 11
  • 1

0 Answers0