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

Matplotlib xticks as days
Renaming tuple column name in dataframe
Jupyter Notebook Toggle Scrolling using Magic Command
Multiple linear regressions according to first column in pandas
Passing tensorflow placeholders as function parameters
Python(3.6)-How can I create a demo program that will create an object from the VotingMachine class I have created?
Python and Plotly offline: create (empty) graph and add traces with for-loop
Installing python on Mac not working
Extracting values from a dataframe column with dtype 'o'
Theano tensor type keeps changing and won't let me pass data
append items from shuffled list to a new list
Authenticate and Authorize for appfolder scope access with OneDrive Business Python SDK
Python logging across open source modules
How to transform nested strings in array to separated words?
Data to be read by humans in Python (large data sets)
How can I rename strings of indices?

Categories

HOME
arrays
cakephp-3.x
dotnetrdf
cluster-computing
pug
crate
meshlab
reverse-engineering
puzzle
facebook-graph-api
mapbox-gl-js
ubuntu-12.04
csvhelper
apple-numbers
webdav
phaser-framework
apiconnect
browserify
slim-3
click
jboss-eap-7
spinnaker
uiview
sign
jacoco
event-log
sendkeys
attask
thumbnails
mousewheel
onsen-ui
cronet
philips-hue
auditing
continuous-deployment
configure
strophe
spring-profiles
idl
receipt
viewstate
hashcat
shibboleth
concrete5-5.7
equivalence
web-development-server
tripwire
distributed-transactions
service-fabric-stateful
spring-bean
resuming-training
apiary
php-ews
rapidweaver
shutdown
cgcontext
slot
gce
selenium-firefoxdriver
packagemaker
glkit
firepath
gameanalytics
dts
pagekit
image-editing
faraday
proxygen
flexjson
brackets-shell
loopj
approval-tests
acm
asymptote
getrusage
matcaffe
webhdfs
ytplayerview
cpu-cores
mdm-zinc
utf-32
microblaze
vcl
ssms-addin
magic-numbers
delphi-xe3
map-force
openkinect
json-patch
winrt-httpclient
healthvault
installshield-2011
onselect
vt100
cadisplaylink
scrollto
mpmovieplayer
hinstance
dashcode
search-path
external-assemblies
file-encodings
graniteds
filetime
configurable

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