Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Walk from root through all children - change Attributes #50

Open
SarahTrees opened this issue Feb 14, 2022 · 1 comment
Open

Walk from root through all children - change Attributes #50

SarahTrees opened this issue Feb 14, 2022 · 1 comment

Comments

@SarahTrees
Copy link

I come from simplehtmldom and have found your library, thank you very much for OpenSource!

I need to go through all the elements in parent-child order, recursively. I really like how easy it is to read and change attributes with this library.

$dom= new IvoPetkov\HTML5DOMDocument();
$dom->loadHTML('
<div class="row">
       <div class="col-6" data-attr="redcolumn">
              <div class="row">
                      <div class="col-10" data-attr="bluecolumn"><p>Text in a p</p></div>
              </div>
       </div>
</div>');

When starting I can start with
$dom->querySelectorAll('body > *'),
because my fragments are automatically integrated into a body by the library.
But how do I get all the direct divs which are included in my current elemts and not all the divs which are children of the children of the children ... ?

Per $childElement->querySelectorAll('*') I get all objects, not only the direct children - but I can very well read their attributes.
Per $childElement->childNodes I get the direct children, but I can't read their attributes, because the result is an object from the DOMParster, right? Is it possible to convert DomNode elements into HTML5DomNode objects?

Thank you for the support!

@ivopetkov
Copy link
Owner

That's a really interesting situation. I expected that childNodes should handle that (because there is a DOMDocument::registerNodeClass call). Did you manage to find a solution?

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

No branches or pull requests

2 participants