Hi,
I am writing a generic xml reader using XMLParser, below is a sample
xml file i am trying to parse:
<Employee-Detail>
<Employee>
<Emp_Id>E-001</Emp_Id>
</Employee>
</Employee-Detail>
And here is the code:
public void onSuccess(String xml_) {
Document doc_ = XMLParser.parse(xml_);
if (doc_.hasChildNodes()) {
NodeList parentNodes =
doc_.getChildNodes();
for (int i=0;
i<parentNodes.getLength(); i++) {
TreeItem parent =
tree.addItem(parentNodes.item(i).getNodeName());
parseXml(parentNodes.item(i),
parent);
}
}
}
private void parseXml(Node node_, TreeItem parent_) {
if (node_.hasChildNodes()) {
NodeList list_ = node_.getChildNodes();
System.out.println(list_.getLength());
for (int i=0; i<list_.getLength(); i++) {
System.out.println(list_.item(i).getNodeName());
TreeItem child_ =
parent_.addItem(list_.item(i).getNodeName());
parseXml(list_.item(i), child_);
}
} else {
parent_.addItem("Value: " + node_.getNodeValue());
}
}
What is happening is that when iterate to the last level, which is
Emp_id, node_.hasChildNodes() still returns true and returns #test as
its child node. I omitted all carriage or white spaces.
Please help!
Thanks!
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.