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

I'm lost and confused! regarding functions and scope of returned objects. Why is the object returned from the first function changed?
How to remove quotes and brackets from a dict that has two keys to one value in a jinja template?
I am looking at each individual date in a Pandas dataframe and adjusting one column (weight), based on condition on another column for each date
For loop in Python working, but not doing it's job
Python error 'int' object has no attribute 'penup' (python turtle)
custome user serializer giving error on is_valid() - django
Dividing a graph into 2 disconnected subgraphs
use boto3 on GAE for Python
boto command for describing an Auto Scaling Group?
get sets of index values, grouped by column year
How to use a tensorflow model extracted from a trained keras model
How to query with many tables
python-shell on linux system indentation error
How come 1 is printed instead of 0?
How to subtracting two hyperspectral image?
Getting an error: list assignment index out of range

Categories

HOME
cluster-computing
nlp
performancecounter
webrtc
avro
concourse
flyway
docker-windows
game-maker-studio-1.4
image-recognition
cross-platform
rhapsody
internet-explorer-8
flexlm
url.action
spring-ws
piwik
memsql
bootstrap-typeahead
cortex-m3
aurelia-binding
bitcoin-testnet
superagent
pitest
pygooglechart
android-vpn-service
entity-system
picturebox
graph-databases
web-audio-api
rider
redhat-datavirt
meta-raspberrypi
agent
mediawiki-extensions
powermta
bids
email-parsing
estimation
w3-total-cache
livescribe
spring-data-hadoop
maintenance
ruby-on-rails-2
tcserver
fontconfig
efxclipse
sqldatareader
master
c#-interactive
foxit
freetype2
asteriskami
mongoskin
codesign
asp.net-mvc-partialview
sun-codemodel
android-recyclerview
loose-typing
java.util.calendar
hyperthreading
uialertview
paypal-nvp
prezto
lines-of-code
virus
ctrlp
obfuscar
belongs-to
pgagent
rhel5
tcpreplay
power-law
lumx
roxygen
wic
sim900
sqljdbc
android-contextmenu
attachevent
socketstream
web-safe-fonts
blockingqueue
cosm
userid
makefile-project
law-of-demeter
mysql-error-1045
noir
rijndael
nt4

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App