use of javax.xml.stream.events.XMLEvent in project languagetool by languagetool-org.
the class AtomFeedParser method getCharacterData.
private String getCharacterData(XMLEventReader eventReader) throws XMLStreamException {
XMLEvent event = eventReader.nextEvent();
StringBuilder sb = new StringBuilder();
while (event.isCharacters()) {
sb.append(event.asCharacters().getData());
event = eventReader.nextEvent();
}
return sb.toString();
}
use of javax.xml.stream.events.XMLEvent in project hadoop by apache.
the class OfflineImageReconstructor method loadNodeChildrenHelper.
private void loadNodeChildrenHelper(Node parent, String expected, String[] terminators) throws IOException {
XMLEvent ev = null;
while (true) {
try {
ev = events.peek();
switch(ev.getEventType()) {
case XMLEvent.END_ELEMENT:
if (terminators.length != 0) {
return;
}
events.nextEvent();
return;
case XMLEvent.START_ELEMENT:
String key = ev.asStartElement().getName().getLocalPart();
for (String terminator : terminators) {
if (terminator.equals(key)) {
return;
}
}
events.nextEvent();
Node node = new Node();
parent.addChild(key, node);
loadNodeChildrenHelper(node, expected, new String[0]);
break;
case XMLEvent.CHARACTERS:
String val = XMLUtils.unmangleXmlString(ev.asCharacters().getData(), true);
parent.setVal(val);
events.nextEvent();
break;
case XMLEvent.ATTRIBUTE:
throw new IOException("Unexpected XML event " + ev);
default:
// Ignore other event types like comment, etc.
if (LOG.isTraceEnabled()) {
LOG.trace("Skipping XMLEvent " + ev);
}
events.nextEvent();
break;
}
} catch (XMLStreamException e) {
throw new IOException("Expecting " + expected + ", but got XMLStreamException", e);
}
}
}
use of javax.xml.stream.events.XMLEvent in project spring-framework by spring-projects.
the class Jaxb2XmlDecoderTests method splitOneBranches.
@Test
public void splitOneBranches() {
Flux<XMLEvent> xmlEvents = this.xmlEventDecoder.decode(Flux.just(stringBuffer(POJO_ROOT)), null, null, Collections.emptyMap());
Flux<List<XMLEvent>> result = this.decoder.split(xmlEvents, new QName("pojo"));
StepVerifier.create(result).consumeNextWith(events -> {
assertEquals(8, events.size());
assertStartElement(events.get(0), "pojo");
assertStartElement(events.get(1), "foo");
assertCharacters(events.get(2), "foofoo");
assertEndElement(events.get(3), "foo");
assertStartElement(events.get(4), "bar");
assertCharacters(events.get(5), "barbar");
assertEndElement(events.get(6), "bar");
assertEndElement(events.get(7), "pojo");
}).expectComplete().verify();
}
use of javax.xml.stream.events.XMLEvent in project languagetool by languagetool-org.
the class XmlUsageCounter method countElementsAndAttributes.
private void countElementsAndAttributes(InputStream in) throws XMLStreamException {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
XMLEventReader eventReader = inputFactory.createXMLEventReader(in);
while (eventReader.hasNext()) {
XMLEvent event = eventReader.nextEvent();
if (event.isStartElement()) {
String elementName = event.asStartElement().getName().getLocalPart();
add(elementName);
Iterator attributes = event.asStartElement().getAttributes();
while (attributes.hasNext()) {
Attribute att = (Attribute) attributes.next();
add(elementName + "/" + att.getName());
}
}
}
}
use of javax.xml.stream.events.XMLEvent in project bazel by bazelbuild.
the class ArrayXmlResourceValue method parseArray.
public static XmlResourceValue parseArray(XMLEventReader eventReader, StartElement start, Namespaces.Collector namespacesCollector) throws XMLStreamException {
List<String> values = new ArrayList<>();
for (XMLEvent element = XmlResourceValues.nextTag(eventReader); !XmlResourceValues.isEndTag(element, start.getName()); element = XmlResourceValues.nextTag(eventReader)) {
if (XmlResourceValues.isItem(element)) {
if (!element.isStartElement()) {
throw new XMLStreamException(String.format("Expected start element %s", element), element.getLocation());
}
String contents = XmlResourceValues.readContentsAsString(eventReader, element.asStartElement().getName(), namespacesCollector);
values.add(contents != null ? contents : "");
}
}
try {
return of(ArrayType.fromTagName(start), values, ImmutableMap.copyOf(XmlResourceValues.parseTagAttributes(start)));
} catch (IllegalArgumentException e) {
throw new XMLStreamException(e.getMessage(), start.getLocation());
}
}
Aggregations