Without going into the deep dark world of parsing xml with Java, you could use regex:
import java.util.regex.Pattern;
import java.util.regex.Matcher;
public class FindZip {
public static void main(String[] args) {
Pattern pattern =
Pattern.compile("<zip>(\\d+)</zip>");
String zip_code;
Matcher matcher = pattern.matcher(
"<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<Chart>" +
" <request>" +
" <zip>12345</zip>" +
" <city>Miami</city>" +
" </request>" +
"</Chart>"
);
boolean found = false;
while (matcher.find()) {
zip_code = matcher.group(1);
System.out.printf(
"I found the zip code \"%s\" starting at index %d and ending at index %d.%n",
zip_code,
matcher.start(1),
matcher.end(1)
);
found = true;
}
if (!found) {
System.out.println("No match found.");
}
}
}
There are obvious drawbacks and limitations to this approach, but at least you get your zip code