D
DRS.Usenet
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:
<choice>
<select>
<case activity="A"/> <!-- this is "1" -->
<case activity="B"/> <!-- this is "2" -->
</select>
<sequence name = "A"><stuffA/></sequence>
<sequence name = "B"><stuffB/></sequence>
</choice>
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:
<sequence name = "Run Option 1">
<assign to="/Some1">run option 1 was chosen</assign>
</sequence>
if my input was {2, 1}, my output would be:
<sequence name = "Run Option 2">
<assign to="/Some2">run option 2 was chosen</assign>
<sequence name="Simple1">
<assign to="/SomeVar1">simple 1 was chosen</assign>
</sequence>
<assign to="/Some2b">run option 2 ending</assign>
</sequence> <!-- end Run Option 2 -->
if my input was {2, 2, 1}, my output would be:
<sequence name = "Run Option 2">
<assign to="/Some2">run option 2 was chosen</assign>
<sequence name="Deep Nested">
<sequence name="Run Deep 1">
<assign to="/D1">d1</assign>
</sequence>
</sequence>
<assign to="/Some2b">run option 2 ending</assign>
</sequence> <!-- end Run Option 2 -->
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!
<process name="aProcess">
<sequence name="Main Sequence">
<choice name="Outer Choice">
<select>
<case ref="option 1" activity="Run Option 1"/>
<case ref="option 2" activity="Run Option 2"/>
</select>
<sequence name = "Run Option 1">
<assign to="/Some1">run option 1 was chosen</assign>
</sequence>
<sequence name = "Run Option 2">
<assign to="/Some2">run option 2 was chosen</assign>
<choice name="Nested choice">
<select>
<case ref="option 1" activity="Simple1"/>
<case ref="option 2" activity="Deep Nested"/>
<case ref="option 3" activity="Simple2"/>
</select>
<sequence name="Simple1">
<assign to="/SomeVar1">simple 1 was chosen</assign>
</sequence>
<sequence name="Deep Nested">
<choice name="It's getting deep">
<select>
<case ref="deepoption 1" activity="Run Deep 1"/>
<case ref="deepoption 2" activity="Run Deep 2"/>
</select>
<sequence name="Run Deep 1">
<assign to="/D1">d1</assign>
</sequence>
<sequence name="Run Deep 2">
<assign to="/D2">d2</assign>
</sequence>
</choice> <!-- end Deep Nested choice -->
</sequence>
<sequence name="Simple2">
<assign to="/SomeVar2">simple 2 was chosen</assign>
</sequence>
</choice> <!-- end Nested choice -->
<assign to="/Some2b">run option 2 ending</assign>
</sequence> <!-- end Run Option 2 -->
</choice> <!-- end Outer Choice -->
</sequence> <!-- end Main Sequence -->
</process>
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:
<choice>
<select>
<case activity="A"/> <!-- this is "1" -->
<case activity="B"/> <!-- this is "2" -->
</select>
<sequence name = "A"><stuffA/></sequence>
<sequence name = "B"><stuffB/></sequence>
</choice>
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:
<sequence name = "Run Option 1">
<assign to="/Some1">run option 1 was chosen</assign>
</sequence>
if my input was {2, 1}, my output would be:
<sequence name = "Run Option 2">
<assign to="/Some2">run option 2 was chosen</assign>
<sequence name="Simple1">
<assign to="/SomeVar1">simple 1 was chosen</assign>
</sequence>
<assign to="/Some2b">run option 2 ending</assign>
</sequence> <!-- end Run Option 2 -->
if my input was {2, 2, 1}, my output would be:
<sequence name = "Run Option 2">
<assign to="/Some2">run option 2 was chosen</assign>
<sequence name="Deep Nested">
<sequence name="Run Deep 1">
<assign to="/D1">d1</assign>
</sequence>
</sequence>
<assign to="/Some2b">run option 2 ending</assign>
</sequence> <!-- end Run Option 2 -->
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!
<process name="aProcess">
<sequence name="Main Sequence">
<choice name="Outer Choice">
<select>
<case ref="option 1" activity="Run Option 1"/>
<case ref="option 2" activity="Run Option 2"/>
</select>
<sequence name = "Run Option 1">
<assign to="/Some1">run option 1 was chosen</assign>
</sequence>
<sequence name = "Run Option 2">
<assign to="/Some2">run option 2 was chosen</assign>
<choice name="Nested choice">
<select>
<case ref="option 1" activity="Simple1"/>
<case ref="option 2" activity="Deep Nested"/>
<case ref="option 3" activity="Simple2"/>
</select>
<sequence name="Simple1">
<assign to="/SomeVar1">simple 1 was chosen</assign>
</sequence>
<sequence name="Deep Nested">
<choice name="It's getting deep">
<select>
<case ref="deepoption 1" activity="Run Deep 1"/>
<case ref="deepoption 2" activity="Run Deep 2"/>
</select>
<sequence name="Run Deep 1">
<assign to="/D1">d1</assign>
</sequence>
<sequence name="Run Deep 2">
<assign to="/D2">d2</assign>
</sequence>
</choice> <!-- end Deep Nested choice -->
</sequence>
<sequence name="Simple2">
<assign to="/SomeVar2">simple 2 was chosen</assign>
</sequence>
</choice> <!-- end Nested choice -->
<assign to="/Some2b">run option 2 ending</assign>
</sequence> <!-- end Run Option 2 -->
</choice> <!-- end Outer Choice -->
</sequence> <!-- end Main Sequence -->
</process>