D
designbyjohn
Hi all.
I am new to JSP and DOM, I am trying to get a subset of values
(categories) from an xml file which looks something like this:
<page>
<something>
....
</something>
<categories>
<category>cat1</category>
<category>cat2</category>
</categories>
</page>
So far I have come up with this. It returns "null null null", which is
interesting because there are only two categories in my xml file.. Any
help would be greatly appreciated.
Regards,
John.
Document doc = db.parse(file);
NodeList list = doc.getElementsByTagName("categories");
for (int i=0; i<list.getLength(); i++) {
Element element = (Element)list.item(i);
NodeList childNodes = element.getChildNodes();
if (childNodes != null) {
for (int x=0; x<childNodes.getLength(); x++) {
String string = childNodes.item(x).getNodeValue();
out.println(string);
}
}
}
I am new to JSP and DOM, I am trying to get a subset of values
(categories) from an xml file which looks something like this:
<page>
<something>
....
</something>
<categories>
<category>cat1</category>
<category>cat2</category>
</categories>
</page>
So far I have come up with this. It returns "null null null", which is
interesting because there are only two categories in my xml file.. Any
help would be greatly appreciated.
Regards,
John.
Document doc = db.parse(file);
NodeList list = doc.getElementsByTagName("categories");
for (int i=0; i<list.getLength(); i++) {
Element element = (Element)list.item(i);
NodeList childNodes = element.getChildNodes();
if (childNodes != null) {
for (int x=0; x<childNodes.getLength(); x++) {
String string = childNodes.item(x).getNodeValue();
out.println(string);
}
}
}