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

How do you apply the same action to multiple variables efficiently in Python?
Repeat input by a certain amount of times in python [duplicate]
What is the most efficient way to subdivide a large list?
Colour percentiles in python matplotlib
Having problems with installing py2exe-0.6.9.win32-py2.6.exe
NotADirectoryError from ctypes with matplotlib and cx_Freeze
django-allauth Custom Sociallogin Signup Form with keyOrder
UnicodeDecodeError: 'ascii' codec can't decode '\xc3\xa8' together with '\xe8'
Python : NaN value in Pandas for a single value only
Add duration to time in python
Python When to OOP and When Not to OOP
Changing an arg in __new__ is not carrying over to __init__
Python : which importing module is calling my function at runtime
Python regression with bounded Y values?
how do you replace every value in a list with another value?
Randomness algorithm in python that integrates a demi-Gaussian curve?

Categories

HOME
crystal-reports
batch-processing
winapi
sed
formal-verification
wms
travis-ci
apollo
phonegap-cli
adsense
aruco
metronic
camera-calibration
abcpdf
qt-installer
alfresco-share
arraylist
zoho
shippo
uiautomator
epicor
rworldmap
activepython
ab-initio
sharp
ioc-container
entity-system
picturebox
hawtio
google-drive-realtime-api
gettext
von-neumann
viewstate
topic-modeling
concrete5-5.7
android-preferences
xbim
paho
nsjsonserialization
chrome-remote-desktop
httplib2
static-code-analysis
svn-merge
atlassian-crowd
visible
freetype2
gmsmapview
search-regex
financial
unity5.3
programming-paradigms
sparse-file
mdm-zinc
jazz
subversion-edge
es2015
word-2013
ejabberd-saas
activity-streams
fragment-tab-host
x-ua-compatible
factors
logentries
carddav
surveyor-gem
digital-design
fieldset
arbor.js
icsharpcode
dynamic-data
deploying
macruby
objective-c-protocol
supersized
objectbrowser
galaxy-tab
newsstand-kit
gethashcode
clients
idictionary
asp.net-mvc-controller
inline-if





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