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

Pip installs old version of package
Python Tkinter coordinate canvas error
How can I implement vice versa mapping in Python?
url doesn't change when moving to the next page
Display PiCamera video to an embedded video player in a python program
Parsing CSV from XML document
How to send authenticated email using Python?
Tensorflow: feeding placeholder in loop within loop fails
Get the mean of each column of data between multiple lists
matplotlib uneven group size bar charts side-by-side
Trouble setting up selenium with python3(linux)
Python : ask the number of common word you want
Azure Cognitive text analytics Tool returns 400 Bad request Python
How to sort a list of list of characters by sorted index of inner list?
always serializer is invalid
How do I flatten a hierarchical column index in a pandas DataFrame?

Categories

HOME
json
openssl
angular-cli
performancecounter
antivirus
command
bibtex
jscript
jrebel
constructor
facebook-javascript-sdk
xul
finite-group-theory
abcpdf
nuxt.js
alfresco-share
yeoman-generator
pyephem
tree-traversal
zend-framework-mvc
aws-cognito
sensu
prediction
countif
explode
searchbar
logarithm
sumo
java-ee-7
skmaps
thinking-sphinx
configure
dd-wrt
data-extraction
mapguide
reactivemongo
service-locator
google-guava-cache
oscommerce
office365connectors
socketpair
axis-labels
dql
s3cmd
cross-entropy
distributed-transactions
scalafx
uiviewpropertyanimator
jags
jenkins-jira-trigger
spring-data-hadoop
openh264
forerunnerdb
mcrypt
etherpad
scd
fedora20
in-memory-database
settimeout
typhoon
cfeclipse
easing
radians
spark-cassandra-connector
gradle-eclipse
spatial-query
dac
search-regex
magento-1.4
galaxy
function-fitting
achartengine
on-duplicate-key
divide-by-zero
debian-based
es2015
android-search
libsndfile
adcolony
hidden-field
vcl
sthttprequest
emma
adaptive-compression
pic24
kraken.js
config-files
cling
cilk-plus
nsmatrix
dig
dynamics-ax-2009
android-4.0
osi
linkedhashset
vim-powerline
feof
tfs-power-tools
driving-directions
nintendo
authenticode
ruby-debug
loadui
mvccontrib-grid
plinq

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