Skip to content

Commit ab5bc49

Browse files
cowtowncoderalex-bel-apica
authored andcommitted
Some more work towards FasterXML#405
1 parent d28d6a9 commit ab5bc49

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

src/main/java/com/fasterxml/jackson/dataformat/xml/deser/XmlTokenStream.java

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,12 +418,13 @@ private final int _next() throws XMLStreamException
418418
// throw new IllegalStateException("No more XML tokens available (end of input)");
419419
}
420420
// Ok: must be END_ELEMENT; see what tag we get (or end)
421-
switch (_skipUntilTag()) {
421+
switch (_skipAndCollectTextUntilTag()) {
422422
case XMLStreamConstants.END_DOCUMENT:
423423
return (_currentState = XML_END);
424424
case XMLStreamConstants.END_ELEMENT:
425425
return _handleEndElement();
426426
}
427+
427428
// START_ELEMENT...
428429
return _initStartElement();
429430
}
@@ -483,6 +484,7 @@ private final String _collectUntilTag() throws XMLStreamException
483484
}
484485
}
485486

487+
// Called to simply skip tokens until start/end tag, or end-of-document found
486488
private final int _skipUntilTag() throws XMLStreamException
487489
{
488490
while (_xmlReader.hasNext()) {
@@ -499,6 +501,45 @@ private final int _skipUntilTag() throws XMLStreamException
499501
throw new IllegalStateException("Expected to find a tag, instead reached end of input");
500502
}
501503

504+
// Called to skip tokens until start/end tag (or end-of-document) found, but
505+
// also collecting cdata until then, if any found, for possible "mixed content"
506+
// to report
507+
//
508+
// @since 2.12
509+
private final int _skipAndCollectTextUntilTag() throws XMLStreamException
510+
{
511+
CharSequence chars = null;
512+
513+
while (_xmlReader.hasNext()) {
514+
int type;
515+
switch (type = _xmlReader.next()) {
516+
case XMLStreamConstants.START_ELEMENT:
517+
case XMLStreamConstants.END_ELEMENT:
518+
case XMLStreamConstants.END_DOCUMENT:
519+
_textValue = (chars == null) ? "" : chars.toString();
520+
return type;
521+
// note: SPACE is ignorable (and seldom seen), not to be included
522+
case XMLStreamConstants.CHARACTERS:
523+
case XMLStreamConstants.CDATA:
524+
{
525+
String str = _getText(_xmlReader);
526+
if (chars == null) {
527+
chars = str;
528+
} else {
529+
if (chars instanceof String) {
530+
chars = new StringBuilder(chars);
531+
}
532+
((StringBuilder)chars).append(str);
533+
}
534+
}
535+
break;
536+
default:
537+
// any other type (proc instr, comment etc) is just ignored
538+
}
539+
}
540+
throw new IllegalStateException("Expected to find a tag, instead reached end of input");
541+
}
542+
502543
private final String _getText(XMLStreamReader2 r) throws XMLStreamException
503544
{
504545
try {

0 commit comments

Comments
 (0)