# Serving XML: XML to XML

### Daniel Parker

This article describes how to tranform flatfiles to XML with the ServingXML pipeline language.

- ServingXML: Pipeline Language
- ServingXML: Flat Files
- ServingXML: Inversion of Control Container

This article discusses processing of XML content in a `ServingXML` pipeline.

The `ServingXML` framework allows streaming of a large volume of XML content to be combined with non-streamed processing of parts of that content.

## Validating XML

## Mutating a Subtree of an XML Document

Figure 1. Input flat file countries.csv

## Extracting a Selection of Subtrees, Wrapping All in Enclosing Tags

## Extracting a Selection of Subtrees, Writing Each as a Separate Document

## Comparing Two XML Documents with fn:deep-equal

              The example below shows how to compare two XML documents for equality with
              the XPATH fn:deep-equal function.

    <sx:resources xmlns:sx="http://www.servingxml.com/core"
                  xmlns:fn="http://www.w3.org/2005/xpath-functions">

      <sx:service id="test">
        <sx:transform ref="test-documents-are-equal"/>
      </sx:service>

      <sx:document id="odd-element-document">
        <document>
          <title>Title</title>
          <para>First paragraph.</para>
        </document>
      </sx:document>

      <sx:document id="another-odd-element-document">
        <document>
          <title>Title</title>
          <para>First paragraph.</para>
        </document>
      </sx:document>

      <sx:transform id="test-documents-are-equal">
        <sx:choose>
          <sx:when test="fn:deep-equal(fn:document('odd-element-document'),
                         fn:document('another-odd-element-document'))">
            <sx:document>
              <result>equal</result>
            </sx:document>
          </sx:when>
          <sx:otherwise>
            <sx:document>
              <result>unequal</result>
            </sx:document>
          </sx:otherwise>
        </sx:choose>
        <sx:assert test="text()='equal'"> Expected documents are equal.
        </sx:assert>
      </sx:transform>

    </resources>

The documents are equal, so the script produces the result <result>equal</result>