Skip to main content

SAX - missing element in XML document

1 reply [Last post]
Joined: 2010-09-30
Points: 0

I have a question. Here is simple SAX Java example:
The XML file contains Employees (with Emp_Id, Emp_Name and Emp_E-mail). I have situation when for example Emp_Name element is missing. Is it possible find out in Java console please?

I tried this:

if (name){
System.out.println("Name: " + str);
name = false;
System.out.println("Name is missing");

But this solution writes "Name is missing" every time. Thank you very much, best regards Tomas

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2010-01-18
Points: 0

What you need to do is pick up on an endElement event ( Similar to startElement, but triggered when the closing segment is read ). If you find the end of an Employee element, you can then check that all the details your expecting for the person have been set.