axelpale / filterxml

Simplify your XML by removing XML nodes that match XPath expressions
MIT License
2 stars 2 forks source link

Know anything about a solution that does the opposite #12

Open cavanaug opened 1 month ago

cavanaug commented 1 month ago

Im looking for something that takes an xml document and list of xpaths to keep and thus delete everything else.

axelpale commented 1 month ago

That sounds like the basic use case for XPath but I am not aware if such tool exists.

It should not be hard to build something like that. Basically, see the line 55 in index.js: nodes = selector(pattern, root). That selects specific XML nodes that match the xpath patterns. Maybe those nodes and all their ancestors could then be reinserted to another tree. The resulting tree would then contain only the matched nodes and their ancestors.