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

Enhancement: Other XPath features you'd like to see #3

Open
JenniferSimonds opened this issue Feb 15, 2016 · 3 comments
Open

Enhancement: Other XPath features you'd like to see #3

JenniferSimonds opened this issue Feb 15, 2016 · 3 comments

Comments

@JenniferSimonds
Copy link
Owner

Apex-XPath supports a simple core of XPath 1.0 syntax. I think it occupies the sweet spot between simplicity and comprehensiveness. It's simple enough to cover maybe 95% of your use cases directly. For the other 5%, Apex-XPath takes you close enough that you can finish filtering the results with minimal effort by using the standard Dom.Document & XmlNode classes.

So far it has covered 100% of my use cases, but I want to know if there are any features of XPath you've found yourself wishing it would support directly. Is there anything we could add to it that would greatly simplify your projects? Or should we keep the library nice & simple, and anything more would just give us diminshing returns of needless complexity?

@KeithClarke
Copy link

Hi @JenniferSimonds,

I imagine you have left this behind at this point, but would appreciate a quick thought from you about how easy adding count (https://developer.mozilla.org/en-US/docs/Web/XPath/Functions/count) would be. We would do the work.

Thanks,
Keith

@JenniferSimonds
Copy link
Owner Author

Hi @KeithClarke ,

I had decided not to add support for parsing XPath functions, since I've never had to use them myself.

For getting a count of results, since the methods return a list of XmlNodes, have you considered taking the size() of the result? Like this:

String xml = '---my xml source---';
XPath xp = new XPath(xml);
Dom.XmlNode root = xp.doc.getRootElement();
Dom.XmlNode[] nodes = xp.find(xp.root, '/a/b');

Integer count = nodes.size();

@KeithClarke
Copy link

KeithClarke commented Apr 27, 2019

Hi @JenniferSimonds,

Thanks for getting back to me on this. I did play around with the count approach you mention. In the end I went for a simpler solution than XPath syntax: XPath was great for engineers but tough for the intended configuration people.

Thanks again,
Keith

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