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: How to shutdown a threaded HTTP server with persistent connections (how to kill readline() from another thread)?
New transport and reader type in Twisted
Resizing image with Python with locked aspect ratio
Single player 'pong' game
Facebook API non-interactive authorization/login
__getattr__ keeps returning None even when I attempt to return values
python foreign character in csv
How to pack python files and its dependencies in a single executable file?
Printing Variable names and contents as debugging tool; looking for emacs/Python shortcut
Cheking added file to upload python, pylons?
How to refer to the local module in Python?
Is close() necessary when using iterator on a Python file object [duplicate]
Django Admin “Edit Selection” Action?
How to change firefox proxy from webdriver?
Is it possible to hook up a more robust HTML parser to Python mechanize?
Enable Unicode “globally” in Python

Categories

HOME
xbox-live
ibm-watson-cognitive
itext
voip
raspbian
cpu-architecture
memory-leaks
wms
deep-linking
extract
bibtex
search-engine
value
avl-tree
metronic
android-source
camera-calibration
viber
eclipse-luna
reduction
scenebuilder
python-unicode
jpeg2000
sonarqube-msbuild-runner
countif
kitematic
rworldmap
azure-servicebus-queues
pptp
spring-data-neo4j
xilinx-ise
multichoiceitems
superagent
pari
rhomobile
mmdrawercontroller
readfile
axis-labels
deepstream.io
equivalence
s3cmd
intellij-idea-2016
stdclass
rich-text-editor
worker
filepath
prototypejs
archer
jtds
istorage
laravel-query-builder
sqldatareader
inject
rstudio-server
uiprogressview
spark-cassandra-connector
nssplitview
ng2-material
gmsmapview
mpeg-4
spinlock
concur
post-processing
java.util.calendar
geodjango
document-oriented-db
mirrorlink
uialertview
twython
stream-framework
ffserver
leadtools-sdk
viper-architecture
pgm
pylearn
guzzle6
low-level
grunt-express
ember-components
humanizer
adaptive-compression
boost-test
pic24
magic-numbers
factors
lov
visual-c++-2010-express
windows-mobile-6
facebook-sdk-3.1
vertical-rhythm
installshield-2009
jqmobi
sttwitter
dropdownlistfor
xgettext
static-variables
flexicious
charts4j
testunit
ets
post-redirect-get
requestfactory
quick-search
revert
delegatecommand
chdatastructures
callgrind

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