Handling XPATH input from a user
Can I ask why you're trying to do this? If this is homework or a way to "practice Java/Object-Oriented programming", please say so. If it's a real question, the best way to represent XPath input is actually a string. XPath is way more complicated than what you've (XPath 2.0 even more so), and you would need a lot of more work to model this properly. If it's a subset of XPAth, then what subset?

Edit: A few examples.


Valid XPath expressions:

ancestor-or-self::*
../employee[@secretary and @assistant]
substring("12345", 1.5, 2.6)
child::para[position()=5][attribute::type="warning"]

Valid XPath 2.0 expressions:

($x div $y) + xs:decimal($z)
fn:error(xs:QName("app:err057"), "Unexpected value", fn:string($v))



Also note that you can evaluate XPath expressions using the standard javax.xml.xpath, thus not needing rolling your own. If you need something else, maybe reuse the source code of javax.xml.xpath to suit your needs?