Are there invariants in XML processing?

Roger L Costello <[email protected]>
Newsgroups gmane.text.xml.devel
Message-ID <SA9PR09MB59527015265A13A9BB636860C8FC9@SA9PR09MB5952.namprd09.prod.outlook.com>
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

_______________________________________________________________________

XML-DEV is a publicly archived, unmoderated list hosted by OASIS
to support XML implementation and development. To minimize
spam in the archives, you must subscribe before posting.

[Un]Subscribe/change address: http://www.oasis-open.org/mlmanage/
Or unsubscribe: [email protected]
subscribe: [email protected]
List archive: http://lists.xml.org/archives/xml-dev/
List Guidelines: http://www.oasis-open.org/maillists/guidelines.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.