How to model logical/boolean expressions in XML efficiently?

boolean-logic, xml

Solution

Armatus answer looks good to me. I consider the left and right element as redundant. Having a logical expression it doesn't matter if i evaluate them left right or right left.

 <expr type="or">
    <expr type="and">
        <sig>x</sig>
        <sig>y</sig>
    </expr>
    <expr type="and">
        <sig>p</sig>
        <sig>q</sig>
    </expr>
</expr>

for example: `(x & y) | (p & q)` is the same as `(q & p) | (y & x)`

furthermore its possible to add more than just two signals.

Problem

Little xml modeling exercise here. Let's say we have some logical expression: (x & y) | (p & q) and it needs to be expressed in XML for whatever reason. Here is a quick stab, but I think this is clumsy: ``` <expr> <or> <and> <e>x</e> <e>y</e> </and> <and> <e>p</e> <e>q</e> </and> </or> </expr> ``` Another stab, which doesn't smell right to me: ``` <expr> <or> <and l="x" r="y"/> <and l="p" r="q"/> </or> </expr> ``` How would you go about it?

Original source