diff --git a/cs675/dom_sax/JDOM.java b/cs675/dom_sax/JDOM.java index 3e757a9..ffed0d9 100644 --- a/cs675/dom_sax/JDOM.java +++ b/cs675/dom_sax/JDOM.java @@ -40,7 +40,7 @@ public class JDOM DocumentBuilder db = dbf.newDocumentBuilder(); doc = db.parse(file); if (doc != null) - printHTMLSchedule(doc); + printHTMLSchedule(doc, System.out); } catch (Exception e) { @@ -48,9 +48,8 @@ public class JDOM } } - private void printHTMLSchedule(Node n) + private void printHTMLSchedule(Node n, PrintStream out) { - PrintStream out = System.out; int type = n.getNodeType(); switch (type) { @@ -65,7 +64,7 @@ public class JDOM out.println(""); out.println(""); - printHTMLSchedule( ((Document) n).getDocumentElement() ); + printHTMLSchedule( ((Document) n).getDocumentElement(), out ); out.println("
Daily Planner
 AMPM
\n\n"); break; @@ -76,7 +75,7 @@ public class JDOM if (name.equals("dailyplanner")) { for (int i = 0; i < children.getLength(); i++) - printHTMLSchedule(children.item(i)); + printHTMLSchedule(children.item(i), out); } else if (m_weekDayNames.containsKey(name)) { @@ -85,9 +84,12 @@ public class JDOM out.println(""); for (int i = 0; i < children.getLength(); i++) { - out.print(""); - printAMPM(children.item(i)); - out.print(""); + if (children.item(i).getNodeType() == Node.ELEMENT_NODE) + { + out.print(""); + printAMPM(children.item(i), out); + out.print(""); + } } out.println(""); } @@ -95,14 +97,15 @@ public class JDOM } } - private void printAMPM(Node n) + private void printAMPM(Node n, PrintStream out) { - NodeList children = n.getChildren(); + NodeList children = n.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node c = children.item(i); - if (c.getType() == Node.TEXT_NODE) + if (c.getNodeType() == Node.TEXT_NODE) { + out.print(c.getNodeValue()); } } }