List of usage examples for javax.xml.stream XMLStreamReader isEndElement
public boolean isEndElement();
From source file:Main.java
public static void printEndElement(XMLStreamReader xmlr) { if (xmlr.isEndElement()) { } }
From source file:Main.java
/** * Load text of the current element.//ww w. j a va 2 s . c o m * @param reader XML reader. * @return Text of the element. * @throws XMLStreamException when the text cannot be read or XML is malformed. */ public static String loadElementText(XMLStreamReader reader) throws XMLStreamException { reader.next(); if (reader.isEndElement()) { return ""; } reader.require(XMLStreamConstants.CHARACTERS, null, null); String text = reader.getText(); reader.next(); reader.require(XMLStreamConstants.END_ELEMENT, null, null); return text; }
From source file:StaxCursorTest.java
private static void printEndElement(XMLStreamReader xmlr) { if (xmlr.isEndElement()) { System.out.print("</" + xmlr.getName().toString() + ">"); }/*from w w w.ja v a 2 s .co m*/ }
From source file:Main.java
public static void consumeEnd(XMLStreamReader xmlRdr, String elementName) throws XMLStreamException { while (xmlRdr.hasNext()) { if (xmlRdr.isEndElement() && xmlRdr.getLocalName().equals(elementName)) { xmlRdr.next();//from w w w . j a va2 s . c o m return; } xmlRdr.next(); } throw new IllegalStateException( "expected start tag <" + elementName + ">, found '" + xmlRdr.getText() + "'"); }
From source file:Main.java
public static void skipToEndElement(XMLStreamReader in) throws XMLStreamException { if (!in.isStartElement()) { return;//from w ww .ja v a2 s .co m } int tagDepth = 1; while (tagDepth > 0 && in.hasNext()) { in.next(); if (in.isStartElement()) { tagDepth++; } else if (in.isEndElement()) { tagDepth--; } } }
From source file:Main.java
/** * Skips an element's complete content. This method assumes that the * <code>START_ELEMENT</code> has already be passed, and when it terminates, * the stream will be positioned at the <code>END_ELEMENT</code>. * // w ww. j a va 2 s . c om * @param reader The stream reader to read. * @throws XMLStreamException If an error occurs reading the stream. */ public static final void skipElementContent(XMLStreamReader reader) throws XMLStreamException { int depth = 0; while (depth >= 0) { reader.next(); if (reader.isStartElement()) { depth++; } else if (reader.isEndElement()) { depth--; } } }
From source file:Main.java
public boolean accept(XMLStreamReader reader) { if (!reader.isStartElement() && !reader.isEndElement()) { return false; } else {//from w w w . ja va 2s. c o m return true; } }
From source file:com.predic8.membrane.core.config.AbstractXmlElement.java
protected void parseChildren(XMLStreamReader token, String child) throws Exception { int count = 0; while (true) { // ignore child token.next();// w w w. ja v a 2 s. c om if (token.isEndElement() && child.equals(token.getName().getLocalPart())) { if (count == 0) return; count--; } else if (token.isStartElement() && child.equals(token.getName().getLocalPart())) { count++; } } }
From source file:com.predic8.membrane.core.config.AbstractXmlElement.java
/** * Needed to resolve interceptor IDs into interceptor beans *///from w w w .j a v a 2 s .c om public XMLElement parse(XMLStreamReader token) throws Exception { move2RootElementIfNeeded(token); log.debug("<" + token.getLocalName() + ">"); parseAttributes(token); while (token.hasNext()) { token.next(); if (token.isStartElement()) { parseChildren(token, token.getName().getLocalPart()); } else if (token.isCharacters()) { parseCharacters(token); } else if (token.isEndElement()) { log.debug("</" + token.getLocalName() + ">"); break; } } doAfterParsing(); return this; }
From source file:com.predic8.membrane.core.http.xml.Response.java
@Override protected void parseChildren(XMLStreamReader token, String child) throws Exception { if (Headers.ELEMENT_NAME.equals(child)) { headers = (Headers) new Headers().parse(token); } else if ("status".equals(child)) { statusCode = Integer//w w w. j a va 2 s . c o m .parseInt(StringUtils.defaultIfBlank(token.getAttributeValue("", "status-code"), "0")); statusMessage = ""; while (token.hasNext()) { token.next(); if (token.isStartElement()) { parseChildren(token, token.getName().getLocalPart()); } else if (token.isCharacters()) { statusMessage += token.getText(); } else if (token.isEndElement()) { break; } } } }