XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
RE: Are there invariants in XML processing?

Hi Folks,

I learned some interesting things about putting invariants in code that processes XML documents.

One person wrote:
----------------------------------------------------------------
One can find invariants in any program. The notion is well-defined and meaningful in any program (whether it is useful in practice is a different question).

Normally identifying invariants is most useful whenever there are loops (or recursion). Straight-line code is usually easy to reason about, so there is usually no need to identify invariants, but when we have loops (or recursion), that's more challenging to reason about and so it can sometimes be more useful to identify invariants.

To learn more, see https://en.wikipedia.org/wiki/Loop_invariant, loop-invariants, and https://en.wikipedia.org/wiki/Hoare_logic.
----------------------------------------------------------------
Also, I found this interesting paper on "Invariant based programming: basic approach and teaching experiences" (https://hal.archives-ouvertes.fr/hal-00477903/document)

/Roger

-----Original Message-----
From: Roger L Costello <costello@mitre.org> 
Sent: Friday, April 29, 2022 2:59 PM
To: xml-dev@lists.xml.org
Subject: Are there invariants in XML processing?

Hi Folks,

I have read that it is good to identify relations -- invariants -- that should hold true throughout processing, and it is good to insert assertions throughout your code to check that the invariants are maintained during processing. 

I can see how programs that involve mathematics can have invariants, i.e., some mathematical relation must be true throughout the code's manipulations. 

Are there invariants in non-mathematical problems?

Are there invariants in processing XML?

Suppose the processing problem is to transform one XML vocabulary to another. Are there invariants in this problem? 

Let's take a specific example. The first XML vocabulary has an element TYPE whose value is A, B, C, or D. The second XML vocabulary has an element publicMilitaryIndicator whose value is Civil, Joint, Military, or Private. After reading the documentation it is determined that the mapping is as follows:

A maps to Civil.
B maps to Joint.
C maps to Military.
D has a different meaning than Private so whenever D is encountered an error should be generated.

Here is XSLT code to do the mapping:

<xsl:template match="publicMilitaryIndicator">
    <xsl:param name="ARPT_row" as="element(row)"/>
    <publicMilitaryIndicator>
        <xsl:variable name="ind" select="$ARPT_row/TYPE"/>
        <xsl:choose>
            <xsl:when test="$ind eq 'A'">Civil</xsl:when>
            <xsl:when test="$ind eq 'B'">Joint</xsl:when>
            <xsl:when test="$ind eq 'C'">Military</xsl:when>
            <xsl:when test="$ind eq 'D'">**error**</xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="'Invalid TYPE'"/>
            </xsl:otherwise>
        </xsl:choose>
    </publicMilitaryIndicator>
</xsl:template>

Is there an invariant in that mapping?

When you process XML documents do you identify invariants and then insert assertions throughout your code to check that the invariants are maintained during processing?

/Roger


[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS