Query Task

Queries XML inputs by using an XQuery program and outputs a file.

Parameters

The following table describes the parameters of the Query task.

ParameterDescription
CollectionsCollectionsCollections

Optional ITaskItemITaskItemITaskItem[] parameter.

Specifies the available collections. If the CollectionURI metadata is defined the item will be added to the specified collection. Otherwise the items will be set as the default collection.

EnableStaticTypingEnableStaticTypingEnableStaticTyping

Optional boolBooleanbool parameter.

Specifies whether the static typing feature is enabled. If not specified, the default value is false.

InputInputInput

Optional ITaskItemITaskItemITaskItem parameter.

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

OptimizationLevelOptimizationLevelOptimizationLevel

Optional intIntegerint parameter.

Specifies the compilation optimization level. The default value is 3. If the value is less than zero or greater than 4, the default optimization level is used.

OutputOutputOutput

Required ITaskItemITaskItemITaskItem parameter.

Specifies the principal output file from evaluating the query.

OutputFilesOutputFilesOutputFiles

Optional ITaskItemITaskItemITaskItem[] output parameter.

Receives the output file created by evaluating the query.

ParametersParametersParameters

Optional stringStringString parameter.

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

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

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. Either the Value, Select or Path attributes should be present, but only one of these. If the Value attribute is present then the value of the parameter is set to an xs:untypedAtomic value defined by this attribute. If the Select attribute is present then the value of the parameter is set to the result of evaluating the XPath expression defined by this attribute. If the Path attribute is present then the value of the parameter is set to the document loaded from the location specified by this attribute. The content of the element is ignored.

ProcessXsiSchemaLocationProcessXsiSchemaLocationProcessXsiSchemaLocation

Optional boolBooleanbool parameter.

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

XQueryXQueryXQuery

Required ITaskItemITaskItemITaskItem parameter.

Specifies the path of the XQuery program.

SchemasSchemasSchemas

Optional ITaskItemITaskItemITaskItem[] parameter.

Specifies the set of XML Schema files used for validation.

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>