python


Convert Logical/Conditional XML blocks to conditional statement in Python


I have an xml as :
<condition>
<comparison compare="or">
<comparison compare="or">
<comparison compare="eq">
<operand idref="MaterialsInUse" type="boolean" />
<operand idref="False" type="int" />
</comparison>
<comparison compare="eq">
<operand idref="RiskFactor" type="boolean" />
<operand idref="True" type="int" />
</comparison>
</comparison>
<operand idref="AmountOfGoods" type="boolean" />
</comparison>
</condition>
I want to construct the expression:
(((MaterialsInUse = False) Or (RiskFactor = True)) Or (AmountOfGoods))
The steps will be as follows:
Step 1: Get element where inner element is "comparison" tag
Step 2:Foreach comparison tag, it gets two inner elements (either comparison or operand) as two operands and makes a statement using operator (value of compare attribute)
and two operands and put the statement in open and close brackets i.e ().
So first operand will be:
<comparison compare="or">
<comparison compare="eq">
<operand idref="MaterialsInUse" type="boolean" />
<operand idref="False" type="int" />
</comparison>
<comparison compare="eq">
<operand idref="RiskFactor" type="boolean" />
<operand idref="True" type="int" />
</comparison>
</comparison>
And second operand will be:
<operand idref="AmountOfGoods" type="boolean" />
Step 3: If the operand is a "comparison" element, then it again considers its inner two tags as operands and "compare" attribute value to generate the statement. So the first operand shown previously can further be splitted to:
<comparison compare="eq">
<operand idref="MaterialsInUse" type="boolean" />
<operand idref="False" type="int" />
</comparison>
And
<comparison compare="eq">
<operand idref="RiskFactor" type="boolean" />
<operand idref="True" type="int" />
</comparison>
The expression then will be:
((MaterialsInUse = False) Or (RiskFactor = True))
Combining it with the last operand :
<operand idref="AmountOfGoods" type="boolean" />
we finally have the expression as:
(((MaterialsInUse = False) Or (RiskFactor = True)) Or (AmountOfGoods))
Kindly help me with the approach.
Thanks in Advance. And also I would like to know of there is a way to reverse this process and create the xml back from the expression.


Related Links

Python bokeh: Multiple color segments on same line
Python Mechanize: download a file
Python List of Two Columns from Excel
Filtering a list of tuples with lambda expressions in Python
add() argument after * must be a sequence, not Settings
cannot convert to egg file for panda3d
Strange LSTM cell histograms?
How to use Selenium to get this index?
Heatmap from large CSV file
tkinter traceback error on python 3.5.1 windows 8.1 [duplicate]
eglInitialize failure using ANGLE dll from python 64 bits
Finding if user input has key words from a list
Why is timeit slower when called from a python file with map and a predefined function over being called via cli with map and a lambda expression?
write console output to excel sheet using DataFrame python
While loop incrementer not functioning properly
How to trace what cause “IndexError: list index out of range” and how to find prod(column)?

Categories

HOME
paypal
erlang
textwatcher
angular2-routing
fparsec
vs-team-services
steam
qpython3
windows-store-apps
codeeffects
aruco
facebook-javascript-sdk
wordpress-theming
ssms-2016
bootstrap-popover
phpbb
anychart
internet-explorer-8
zend-framework-mvc
android-fragmentactivity
sonarqube-msbuild-runner
statusbar
autolayout
jflex
auditing
image-quality
upnp
dss
ab-initio
rowcount
percentage
postgresql-9.2
precedence
jquery-cycle2
geomesa
openshift-enterprise
s3cmd
rule
lexical-analysis
matlab-cvst
worker
startapp
jtds
floor
livefyre
jenkins-jira-trigger
applepayjs
photon-controller
collapsingtoolbarlayout
lotus
gradle-script-kotlin
alter
uistackview
excon
visible
spatial-query
spring-repositories
usb-drive
xmp
galaxy
datasnap
registrykey
vine
xjc
chaining
jcr-sql2
python-ggplot
cloudpebble
sortable
sid
ember-addon
getimagedata
joox
slick-2.0
magic-numbers
hamsterdb
bfd
real-time-updates
loop-invariant
dig
manage.py
cgimageref
pep8
qtgui
fileconveyor
objcmongodb
gdataxml
socketstream
pitch
datacontract
coff
datamember
cookieless
dcpu-16
dashcode
squeel
pantheios
open-graph-beta
msn
graph-layout
lazy-c++
associativity





Mobile Apps Dev
Database Users
javascript
java
csharp
php
android


MS Developer
developer works
python
ios
c
html
jquery


RDBMS discuss