Open JenniferSimonds opened 8 years ago
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
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();
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
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?