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 I call my functions correctly in python?
TensorFlow module cant be found. even though its installed on Anancoda
Pandas group by filter based on conditions
How do I find all the businesses names and ids and urls using yelp api?
read every 5th line in a data file and append to a new list
How to Pivot a table in csv horizontally in Python using Pandas df?
Cannot concatenate 'str' and 'int' objects(cant sum)
Pexpect is not working for different promt other than bash
How to optimize code for deleting n position in all the lists from a list of lists
Creating python scrabble function
How to convert a matrix to 3D arrays or vice versa?
Merge table on either of the 2 columns in pandas
Best way to sort table based on headers using Flask
python-get a sublist without changing position
tkinter: binding a function to a button that opens a simpledialog
diffrent views according to if user is logged in or not

Categories

HOME
tensorflow
visual-studio-2015
sas
payment-gateway
webrtc
bing
nuxeo
bower
facebook-graph-api
translation
jbehave
avro
devstack
jpanel
keystore
jboss7.x
future
sendkeys
jpeg2000
movies
zend-framework-mvc
ios10.3
ng2-dragula
autolayout
fop
source-maps
logarithm
lync-2013
mangodb
superagent
superscript
backup-strategies
edb
xamarin.uitest
initializer
topic-modeling
html-agility-pack
lftp
ivona
uiviewpropertyanimator
broadcast
text-classification
react-native-fbsdk
launch
static-code-analysis
iron.io
emgu
restivejs
onresume
pdfkit
createobject
libtiff.net
sql-import-wizard
angularjs-ng-pattern
spark-cassandra-connector
qregexp
pagekit
gradle-eclipse
uwp-maps
sun-codemodel
axes
brackets-shell
except
getrusage
intellitest
vips
sourcegear-vault
p-np
coypu
adobe-indesign
mdm-zinc
rhel5
cpu-speed
tcpreplay
odftoolkit
grunt-express
driver-signing
leptonica
entity-framework-4.1
qss
dropdownlistfor
fotoware
ninject-extensions
surf
datacontract
easygui
post-redirect-get
asp.net-routing
osx-leopard
delegatecommand
communicationexception
scala-2.8
trampolines
project-lifecycle
database-diagramming
interface-design

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