Understanding the Resulting Document of an XMLData.Compare Statement

The XMLData document (Document A) is compared to the specified document specified in the XMLDocument Argument (Document B). Each element is compared to its corresponding element. For example, the first child element of a matched element in Document A is compared to the first child element of the matched element in Document B.

The following describes the comparison process and the resulting information in the Resulting XML document.

  1. The document type declaration is compared. If difference is found, a comment is added to the result document. The comment has the following format for a document declaration found in Document A: mic_docA_decl Document A Declaration...; For a declaration found in Document B: mic_docB_decl Document B Declaration...

  2. The root elements of the result document are named mic_root and have one attribute named mic_state. The value of this attribute is one of the following:

    • match: everything under this element matches.

    • mismatch: a mismatch was found in one or more elements that are children of this element.

  3. Each element that is compared has an attribute named mic_state. The value of this attribute is one of the following:

    • match: this element and everything under this element matches.

    • mismatch: a mismatch was found in this element or other elements that are children of this element.

    • missing: this element (from Document A) is missing in the compared document (Document B).

    • added: this element was added to the compared document (Document B)/this element is missing from the original document (Document A).

  4. Attributes found in a matching element in Document A, but not in the matching element in Document B are displayed in the resulting document as the value of an attribute named mic_elemA_attr. Attributes that have been "added" to the matching element in Document B are displayed as a value of an attribute named mic_elemB_attr. If several such attributes exist, they are all displayed in the attribute value, separated by a ";" .

  5. For each element value that is missing from Document B, a child element named mic_elemA_text is added to the resulting document's matching element, and the missing value is the mic_elemA_text's element value. In the same manner, for each element value that was added to an element in Document B, an element named mic_elemB_text is added to the matching element in the resulting document and the added value is mic_elemB_text's element value.

  6. For each CDATA section element that is missing from Document B, a child element named mic_elemA_cdata is added to the resulting document's matching element, and the missing CDATA section is its CDATA section value. In the same manner, for each CDATA section that was added to an element in Document B, an element named mic_elemB_cdata is added to the matching element in the resulting document, and the text is its CDATA section value.

The following example shows two XML documents and the document that is returned by an XMLData.Compare statement.

Document A:

<?xml version="1.0" encoding="ISO-8859-1" ?> 
<rss version="0.91“>
<channel>
<item Crash="no way" abc="efg" hello="world“>
  <title>Cnet video1 review</title> 
  <link>http://www.nomadness.net/article.php?sid=353</link> 
<![CDATA[ 
 <hello world> <blah blah blah...
  ]]>  
  </item>
<item>
  <title>"Jukebox 3 info from a Creative employee" Forum post</title> 
  <link>http://www.nomadness.net/article.php?sid=351</link> 
  </item>
  </channel>
  </rss>

Document B:

<?xml version="1.0" encoding="ISO-8859-1" ?> 
  <rss version="0.91“>
  <channel>
  <item hello="world" crash="no way“>
    <title>Cnet video review</title> 
    <link>http://www.nomadness.net/article.php?sid=353</link> 
  <![CDATA[ 
   <hello1 world> <blah blah blah...
    ]]>  
    </item>
  <item>
    <title>"Jukebox 3 info from a Creative employee" Forum post</title> 
    <link>http://www.nomadness.net/article.php?sid=351</link> 
    </item>
    </channel>
    </rss>

Resulting XML Document:

<mic_root mic_state="mismatch“>
   <rss mic_state="mismatch“>
  <channel mic_state="mismatch“>
  <item mic_state="mismatch" mic_elemA_attr="abc="efg";Crash="no way"" mic_elemB_attr="crash="no way"“>
  <mic_elemA_cdata>
  <![CDATA[ 
   <hello world> <blah blah blah...
    ]]>  
    </mic_elemA_cdata>
  <mic_elemB_cdata>
  <![CDATA[ 
   <hello1 world> <blah blah blah...
    ]]>  
    </mic_elemB_cdata>
  <title mic_state="mismatch“>
    <mic_elemA_text>Cnet video1 review</mic_elemA_text> 
    <mic_elemB_text>Cnet video review</mic_elemB_text> 
    </title>
    <link mic_state="match" /> 
    </item>
    <item mic_state="match" /> 
    </channel>
    </rss>
    </mic_root>