diff --git a/src/fr/devinsy/util/xml/XMLReader.java b/src/fr/devinsy/util/xml/XMLReader.java index e850f50..3258252 100644 --- a/src/fr/devinsy/util/xml/XMLReader.java +++ b/src/fr/devinsy/util/xml/XMLReader.java @@ -121,9 +121,9 @@ public class XMLReader // Load next event. if (this.nextEvent == null) { - if (in.hasNext()) + if (this.in.hasNext()) { - this.nextEvent = in.nextEvent(); + this.nextEvent = this.in.nextEvent(); } } @@ -275,6 +275,39 @@ public class XMLReader return result; } + /** + * + * @param label + * @return + * @throws XMLStreamException + * @throws XMLBadFormatException + * @throws Exception + */ + public XMLTag readNullableStartTag(final String label) throws XMLStreamException, XMLBadFormatException + { + XMLTag result; + + // + result = readTag(); + + // + if (result == null) + { + throw new XMLBadFormatException("XML file ends prematurely, start tag [" + label + "] is expected."); + } + else if ((result.getType() != TagType.START) && (result.getType() != TagType.EMPTY)) + { + throw new XMLBadFormatException("Start tag [" + label + "] is missing."); + } + else if (!StringUtils.equals(result.getLabel(), label)) + { + throw new XMLBadFormatException("Tag with label [" + label + "] is missing."); + } + + // + return result; + } + /** * * @param label @@ -345,9 +378,9 @@ public class XMLReader event = this.nextEvent; this.nextEvent = null; } - else if (in.hasNext()) + else if (this.in.hasNext()) { - event = in.nextEvent(); + event = this.in.nextEvent(); } else {