Java Reference
In-Depth Information
default:
break;
}
break;
case XMLStreamConstants.END_ELEMENT:
String elementname
= reader.getLocalName();
if (elementname.equals("patient")) {
System.out.printf("Patient:
%s\nName: %s\nDiagnosis: %s\n\n",id, name,
diagnosis);
id = name = diagnosis = null;
inName = inDiagnosis = false;
}
break;
case XMLStreamConstants.CHARACTERS:
if (inName) {
name = reader.getText();
inName = false;
} else if (inDiagnosis) {
diagnosis = reader.getText();
inDiagnosis = false;
}
break;
default:
break;
}
}
reader.close();
}
}
Solution 2
Use the XMLEventReader to read and process events using an event-oriented inter-
face. This API is called an iterator-oriented API as well. The following code is much
like the code in Solution 1, except that it uses the event-oriented API instead of the
cursor-oriented API. This code snippet is available from the same
Search WWH ::




Custom Search