[jdom-interest] XPath bindings?
Elliotte Rusty Harold
elharo at metalab.unc.edu
Fri Oct 12 10:10:33 PDT 2001
At 11:20 AM -0400 10/12/01, bob mcwhirter wrote:
>> I like the first one. I object to the second. An XPath expression often
>> returns more than one node. What does this method do if the argument
>> in fact returns more than one node?
>
>It would provide you with the first one. Not unlike Element.getChild(...)
>which provides only the first child with the matching name.
>
There's no need for this. If somebody knows they only want the first node in the list, then they can append [position()=1] or even just [1] to the end of the XPath expression to get it. There's no need for a convenience method to get the first node in a list here. It's completely superfluous.
I'm more concerned, however, about programmers who aren't completely comfortable with XPath. If somebody doesn't know they want the first node in the list, but they do know they want only a single node, they're likely to pick getSingleNode() without giving it a lot of thought. They're likely to be surprised by nulls that are returned when the method doesn't return even a single node. They're likely to miss data because they got a single node when what they really needed was a list. I'm afraid this is going to lead to misuse and misunderstanding of XPath.
--
+-----------------------+------------------------+-------------------+
| Elliotte Rusty Harold | elharo at metalab.unc.edu | Writer/Programmer |
+-----------------------+------------------------+-------------------+
| The XML Bible, 2nd Edition (Hungry Minds, 2001) |
| http://www.ibiblio.org/xml/books/bible2/ |
| http://www.amazon.com/exec/obidos/ISBN=0764547607/cafeaulaitA/ |
+----------------------------------+---------------------------------+
| Read Cafe au Lait for Java News: http://www.cafeaulait.org/ |
| Read Cafe con Leche for XML News: http://www.ibiblio.org/xml/ |
+----------------------------------+---------------------------------+
More information about the jdom-interest
mailing list