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

Finding nodes by type or id #40

Closed
thomas-kl1 opened this issue Jan 29, 2018 · 2 comments
Closed

Finding nodes by type or id #40

thomas-kl1 opened this issue Jan 29, 2018 · 2 comments
Assignees
Labels
feature New feature or request

Comments

@thomas-kl1
Copy link
Contributor

Does it exists a feature which allows to search nodes by type and id in the svg dom?

@meyfa meyfa added the feature New feature or request label Jan 30, 2018
@meyfa
Copy link
Owner

meyfa commented Jan 30, 2018

There is no such feature as of yet, but it would be a good addition. I will try to draft something up as soon as possible.

@meyfa meyfa self-assigned this Jan 31, 2018
@meyfa meyfa changed the title Search Nodes feature Finding nodes by type or id Jan 31, 2018
@meyfa
Copy link
Owner

meyfa commented Jan 31, 2018

I implemented getElementById($id) (936d22c) and getElementsByTagName($tagName) (2283a21). They behave exactly like their JavaScript counterparts.

Example:

$image = SVGImage::fromFile('file.svg');
$doc = $image->getDocument();

$byId = $doc->getElementById('foobar');
// $byId is now set to the element with id="foobar"

$byTagName = $doc->getElementsByTagName('rect');
// $byTagName is now set to an array with all <rect /> nodes

Note that getElementById can only be invoked on the document (as usual, since ids are unique across the document). getElementsByTagName can be invoked on any node.

@meyfa meyfa closed this as completed Jan 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants