Serialize Task

Applies serialization options to an XML input and outputs a file.

Parameters

The following table describes the parameters of the Serialize task.

ParameterDescription
InputInputInput

Required ITaskItemITaskItemITaskItem parameter.

Specifies the path of an XML input file to use as the context item.

OutputOutputOutput

Required ITaskItemITaskItemITaskItem parameter.

Specifies the principal output file to which the input will be serialized.

OutputFilesOutputFilesOutputFiles

Optional ITaskItemITaskItemITaskItem[] output parameter.

Receives the serialized output file.

ProcessXsiSchemaLocationProcessXsiSchemaLocationProcessXsiSchemaLocation

Optional boolBooleanbool parameter.

Specifies whether xsi:schemaLocation and xsi:noNamespaceSchemaLocation attributes will be processed. If not specified, the default value is true.

SerializationParametersSerializationParametersSerializationParameters

Optional stringStringString parameter.

Specifies the values of serialization parameters. The value of this parameter should be set to a series of XML elements of the following form:

 
<Parameter Name="..." [Namespace="..."] Value="..." />
 

The Name and Namespace attributes correspond to the local name and namespace of the parameter. If the namespace is omitted, then the parameter is assumed to be in the empty namespace. The Value attribute specifies the value of the serialization parameter. The content of the element is ignored.

SerializationParameterDocumentSerializationParameterDocumentSerializationParameterDocument

Optional ITaskItemITaskItemITaskItem parameter.

Specifies a serialization parameter document from which to read serialization parameters.

StripWhitespaceStripWhitespaceStripWhitespace

Optional boolBooleanbool parameter.

Specifies whether the whitespace will be stripped from source documents. If not specified, the default value is false.

ValidationValidationValidation

Optional stringStringString parameter.

Specifies whether the source documents will be validated using a DTD ("dtd"), XML Schemas ("schema") or no validation will be performed ("none"). If not specified, the default value is none.

Remarks

In addition to having the parameters that are listed in the table, this task inherits parameters from the TaskTaskTask class. For a list of these additional parameters and their descriptions, see Task Base Class.

Example

The following example queries input document document.xml to produce result output.htm using the XQuery program query.xq. Values are supplied for stylesheet parameters 'data' (in namespace 'http://www.example.org/) 'name', 'size' and 'date' are defined. The 'method' serialization parameter is set to XHTML. Input documents are validated using XML Schema against a set of files with extension 'xsd'. Two collections are made available with URIs 'urn:foo' and 'urn:bar'.

 
        <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <Import Project="$(MSBuildExtensionsPath32)\XmlPrime.Tasks\XmlPrime.Tasks.Tasks"/>

  <ItemGroup>
    <Query Include="query.xq" />
    
    <ContextDocument Include="document.xml" />
    
    <Schemas Include="*.xsd" />
    
    <FooCollection Include="foo*.xml">
      <CollectionURI>urn:foo</CollectionURI>
    </FooCollection>
    
    <BarCollection Include="bar*.xml">
      <CollectionURI>urn:bar</CollectionURI>
    </BarCollection>
  </ItemGroup>

  <PropertyGroup>
      <SerializationParameters>
        <!-- set the serialization method to XHTML -->
        <Parameter Name="method" Value="xhtml" />
      </SerializationParameters>
      <QueryParameters>
        <!-- bind parameter 'data' in namespace 'http://www.example.org/' to the document data.xml -->
        <Parameter Name="data" Namespace="http://www.example.org/" Select="doc('data.xml')" />
        <!-- bind parameter 'name' to the string 'Jethro' -->
        <Parameter Name="name" Value="Jethro" />
        <!-- bind parameter 'size' to the XPath expression '1024 * 768' -->
        <Parameter Name="size" Select="1024 * 768" />
        <!-- bind parameter 'date' to the current date -->
        <Parameter Name="date" Select="current-date()" />
      </QueryParameters>
  </PropertyGroup>

  <!-- test passing of serialization parameters -->
  <Target Name="transform">
    <Query XQuery="@(Query)"
           Input="@(ContextDocument)"
           Collections="@(FooCollection);@(BarCollection)"
           Parameters="$(QueryParameters)"
           SerializationParameters="$(SerializationParameters)"
           Schemas="@(Schemas)"
           Validation="Schema"
           Output="output.htm">
      <Output TaskParameter="OutputFiles"
              ItemName="TransformOutputFiles" />
    </Query>
    
    <Message Text="Wrote output file @(TransformOutputFiles)" />
    
  </Target>

</Project>