@@ -418,12 +418,13 @@ private final int _next() throws XMLStreamException
418
418
// throw new IllegalStateException("No more XML tokens available (end of input)");
419
419
}
420
420
// Ok: must be END_ELEMENT; see what tag we get (or end)
421
- switch (_skipUntilTag ()) {
421
+ switch (_skipAndCollectTextUntilTag ()) {
422
422
case XMLStreamConstants .END_DOCUMENT :
423
423
return (_currentState = XML_END );
424
424
case XMLStreamConstants .END_ELEMENT :
425
425
return _handleEndElement ();
426
426
}
427
+
427
428
// START_ELEMENT...
428
429
return _initStartElement ();
429
430
}
@@ -483,6 +484,7 @@ private final String _collectUntilTag() throws XMLStreamException
483
484
}
484
485
}
485
486
487
+ // Called to simply skip tokens until start/end tag, or end-of-document found
486
488
private final int _skipUntilTag () throws XMLStreamException
487
489
{
488
490
while (_xmlReader .hasNext ()) {
@@ -499,6 +501,45 @@ private final int _skipUntilTag() throws XMLStreamException
499
501
throw new IllegalStateException ("Expected to find a tag, instead reached end of input" );
500
502
}
501
503
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
+
502
543
private final String _getText (XMLStreamReader2 r ) throws XMLStreamException
503
544
{
504
545
try {
0 commit comments