Skip to content

Allow nested xpath filter - #20

Closed
jwundrak wants to merge 1 commit into
hakre:developfrom
jwundrak:nested-xpath-filter
Closed

jwundrak wants to merge 1 commit into
hakre:developfrom
jwundrak:nested-xpath-filter

Conversation

@jwundrak

Copy link
Copy Markdown

Hi @hakre . Thanks for the library.

This PR resolves #12 . The problem is, that the current XPathFilter only check for exactly one match. If there nested matches, they are not found.

Behavior:

Using example in #12 (comment) with this script:

$xml = <<<XML
<response>
  <entry>
    <log>
      <logs count="3">
        <entry id="1">
          <baz>1</baz>
        </entry>
        <entry id="2">
          <baz>2</baz>
        </entry>
        <entry id="3">
          <baz>3</baz>
        </entry>
      </logs>
    </log>
  </entry>
</response>
XML;


$reader = XMLReader::open('data://text/plain,' . urlencode($xml));
$iterator = new XMLElementIterator($reader);
$list = new \XMLElementXpathFilter($iterator, '//entry');


/** @var \XMLReaderNode $result */
foreach($list as $item) {
    var_dump($item->getName());
    var_dump($item->getAttribute('id'));
}

Before patch

string(5) "entry"
NULL

After patch

string(5) "entry"
NULL
string(5) "entry"
string(1) "1"
string(5) "entry"
string(1) "2"
string(5) "entry"
string(1) "3"

@jwundrak jwundrak mentioned this pull request Aug 16, 2022
4 tasks done
@hakre
hakre changed the base branch from master to develop August 17, 2022 19:22
@hakre

hakre commented Aug 17, 2022

Copy link
Copy Markdown
Owner

@jwundrak Thanks for the fix, will be released in v0.1.12.

@hakre hakre closed this Aug 17, 2022
@jwundrak
jwundrak deleted the nested-xpath-filter branch August 18, 2022 22:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot iterate over the contents of multiple matched XPath elements

2 participants