There is an XML selective parsing puzzle that I haven't been able to figure out.
I've got some XML source that I'm reading using SAX (ie: SAXBuilder builder = new SAXBuilder(); Document
doc = builder.build(new StringReader(bpSource));Element root = doc.getRootElement(); ) I can get everything I need out of the XML, that's not the problem. It's a logic problem with picking and choosing what to include and what to discard based on a second input.
The inputs to the program are 1)an XML file, and 2) an array of numbers. Those numbers represent which choice statements will be active.
So if I had array = {2}, and XML like this:
The result would be "<sequence name = "B"><stuffB/></sequence>" (the case's activity matches up on the sequence name).
The problem comes when you have nested choices (besides just "<stuffB>", you might have "<case><select>..." in that sequence as well. In other words, the solution needs to handle "n-level deep choices".
There is an example input XML file at the bottom of this post. For that example, we might have a few different number array inputs:
if my input was {1}, my output would be:
if my input was {2, 1}, my output would be:
if my input was {2, 2, 1}, my output would be:
So, can anyone think of a smart way to assemble only the selected XML out of the whole, based on the number array inputs?
--Dale--
Here is the sample XML file that goes with the example outputs above. Some of you might recognize this a BPML (Business Process Modeling Language), but that doesn't matter, that is, unless you know of a BPML parser that does what I'm looking for!
[ May 04, 2006: Message edited by: Dale Seng ]