Results 1 to 2 of 2
Thread: Determining which choice exists
- 12-15-2011, 09:49 AM #1
Determining which choice exists
I'm using XPath to read a document. One of my nodes contains a choice element with minOccurs="0". The tag can be PushState, PopState, or SetState.
I've been calling XPath.evaluate(...) for each of those possibilities and testing if the result is null. Is there a more straightforward way to find out which tag, if any, is present?
Java Code:Node transitionNode = (Node) xp.evaluate("PushState", node, XPathConstants.NODE); if(transitionNode != null) { transitionType = TransitionType.PUSH; transitionState = transitionNode.getTextContent(); } else { transitionNode = (Node) xp.evaluate("PopState", node, XPathConstants.NODE); if(transitionNode != null) { transitionType = TransitionType.POP; transitionState = null; } else { transitionNode = (Node) xp.evaluate("SetState", node, XPathConstants.NODE); if(transitionNode != null) { transitionType = TransitionType.SET; transitionState = transitionNode.getTextContent(); } } }Get in the habit of using standard Java naming conventions!
- 12-16-2011, 12:27 AM #2
Banned
- Join Date
- Dec 2011
- Posts
- 143
- Rep Power
- 0
Re: Determining which choice exists
It depends on the schema and how much you can assume about the node's position and attributes, etc. If it is guaranteed to be the first or last child node, you could use a predicate, for example. If its position is complex, could you search for a signature attribute if there is a unique one. Either way, you could then retrieve and test the node's name. But if has no identifying signature or position, I guess you'd have to enumerate them by name, as you have done.
Similar Threads
-
Determining whether a queen can attack another piece
By sonofshirt in forum New To JavaReplies: 9Last Post: 10-09-2010, 02:23 AM -
Determining ActionListener
By siamino in forum New To JavaReplies: 12Last Post: 05-25-2009, 11:04 PM -
Need Help with determining the problem in my Code
By KillingKiller in forum New To JavaReplies: 3Last Post: 03-27-2009, 12:24 AM -
Determining the readiness of another program
By jmHoekst in forum New To JavaReplies: 10Last Post: 06-19-2008, 08:56 AM -
Determining Midi Length
By Usagi in forum New To JavaReplies: 0Last Post: 12-08-2007, 11:45 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks