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 unicode to original text character when being used as string not when printing
Pygubu Load new Window from UI File
How to use do Homographic key matching using AKAZE in opencv
Script execution time on different computers (python 3.5, miniconda)
Loss of precision while converting floats to strings in pandas
PySide application crashes when setting a new widget to QScrollArea
Python - Download File Created From ASPX Form Submission
Find number of weeks in a month
breaking up a list entry in several lists at every /n Python 3
How can I get the default colors in GTK?
Ndb entry .put() not executed?
Tensorflow: NaNs propagating throughout network, even though using sparse_softmax etc
How to do a Python argparse mutually required argument group
scaling websocket game application server
Is there a way to find a character's Unicode code point in Python 2.7?
figtext datetime function matplotlib

Categories

HOME
signalr
websphere
system-verilog
bing
visual-studio-2013
json-ld
zend-framework2
is-empty
wampserver
apple-numbers
jpanel
rfid
cortex-a
glpk
lenskit
sendkeys
ejs
sql-tuning
linq-to-sql
zoho
propel2
url.action
os161
bcrypt
searchbar
philips-hue
continuous-deployment
guile
kong
cep
image-quality
i3
smart-mobile-studio
hotmail
geomesa
bigcartel
liquid-xml
tic-tac-toe
flex4.5
rule
wcf-security
pdftk
pytest-django
matlab-cvst
asmx
fqdn
nsjsonserialization
webdatagrid
livescribe
multi-agent
azureportal
rollback
workflow-foundation-4.5
slidesjs
tcserver
modelattribute
photography
quintus
pycurl
backstop.js
icefaces
cron-task
gitweb
webkit2
spoofing
windows-nt
listadapter
ng2-material
git-rebase
altbeacon
jta
sevenzipsharp
abas
built-in
achartengine
castle-windsor-3
type-mismatch
viper-architecture
custom-url
ticket-system
android-search
activity-streams
dmp
formvalidation-plugin
ember-addon
colt
alertifyjs
help-viewer
opensocial
internal
shiva3d
zend-lucene
zend-framework-modules
pys60
maven-ear-plugin
moq-3
couchdb-lucene
getusermedia
mpmovieplayer
redirectstandardoutput
parameterization
makefile-project
law-of-demeter
v4l
handwriting
for-xml-path
gethashcode
quick-search
revert
boost-date-time
chdatastructures
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