@@ -28,6 +28,9 @@ class XmlProcessor
2828 /** @var iterable<bool> */
2929 private iterable $ parserProperties ;
3030
31+ private bool $ skipCurrentNode = false ;
32+ private bool $ selfClosing = false ;
33+
3134 /**
3235 * @param iterable<NodeProcessorInterface> $processors
3336 * @param iterable<bool> $parserProperties
@@ -43,7 +46,7 @@ public function __construct(
4346 $ this ->context = new XmlProcessorContext (
4447 $ this ->xml ,
4548 $ this ->processors ,
46- fn () => $ this ->skipNode ()
49+ fn () => $ this ->skipCurrentNode = true
4750 );
4851 }
4952
@@ -75,13 +78,12 @@ public function processFile(string $filename): void
7578 $ this ->eventCloseElement ();
7679 break ;
7780 case \XMLReader::ELEMENT :
78- $ selfClosing = $ this ->xml ->isEmptyElement ;
81+ $ this -> selfClosing = $ this ->xml ->isEmptyElement ;
7982 $ this ->eventOpenElement ();
80- if ($ this ->shouldSkipNode ()) {
81- $ this ->skipNode ();
82- break ;
83+ if ($ skip = $ this ->shouldSkipNode ()) {
84+ $ this ->xml ->next ();
8385 }
84- if ($ selfClosing ) {
86+ if ($ skip || $ this -> selfClosing ) {
8587 $ this ->eventCloseElement ();
8688 }
8789 break ;
@@ -106,6 +108,10 @@ private function skipNode(): bool
106108
107109 private function shouldSkipNode (): bool
108110 {
111+ if ($ this ->skipCurrentNode ) {
112+ $ this ->skipCurrentNode = false ;
113+ return true ;
114+ }
109115 if ($ this ->skipNodes === NULL ) {
110116 return false ;
111117 }
@@ -186,6 +192,9 @@ private function popNodePath(): void
186192 private function createContext (string $ contextClass ): NodeProcessorContext
187193 {
188194 $ context = new $ contextClass ($ this ->context , $ this ->nodePath );
195+ if (method_exists ($ context , 'setSelfClosing ' )) {
196+ $ context ->setSelfClosing ($ this ->selfClosing );
197+ }
189198 if (method_exists ($ context , 'setAttributes ' )) {
190199 $ context ->setAttributes ($ this ->getAttributes ());
191200 }
0 commit comments