XML Data Sources

When you create an XML data source, you must use XML as the type of connection and specify the location of the XML document in the connection string.

You can specify the connection string for an XML data source as:

  • an HTTP URL that identifies the content store required to connect to the XML document.

    An example is HTTP://xmltestserver.cognos.com/XML/countryregion.xml.

    Ensure that you create a Web alias for the directory that contains the XML file and that you enable directory browsing.

  • a file path

    A Microsoft Windows operating system file path example is \\servername\XML\countryregion.xml.

    A UNIX operating system file path example is /mount name/XML/countryregion.xml.

  • a local file

    An example is C:\XML\countryregion.xml;VALIDATE=ON.

To access a local file, use a file path that uses platform-specific syntax.

To test an XML connection string, you must type the following code at the end of the string:

;VALIDATE=ON

The text of this code is not case sensitive.

You specify connection parameters when you create a data source or modify a data source connection. For more information, see Data source connections.

Table 1. XML data source parameters
Parameter Description

Connection string

Enter the connection string.

Validating your XML data source

The file xmldata.xsd is used to validate XML data sources. It describes the structure of an XML file that contains both datatype description, and the actual data.

The root element of XML file is the <schema> element, which is called <dataset>. The root element <dataset> contains two elements:
  • <metadataType>
  • <data>
<metadataType>

The <metadataType> element describes data types of the content of the <data> element. The <metadataType> element contains one or more <item> elements. Each <item> element describes a datatype, similar to a datatype of a relational column.

The <item> element has the following attributes to describe a data type:

  • attribute <name>: the name of data, such as the column name in the relational table
  • attribute <length>: the length of string data
  • attribute <scale>: the scale of numeric data
  • attribute <precision>: the precision of string data, or the precision of a decimal/numeric datatype.
<data>

The <data> element contains the actual data. It contains none, one or more <row> elements.

Each <row> element contains <value> elements. The number of <value> elements in the <row> element should be the same as the number of <item> elements in the <metadataType> element.

The <value> element contains the actual data. The data is interpreted as string, numeric, or other type according to the description in the <item> element.

Here is the content of xmldata.xsd:

<?xml version="1.0" encoding="UTF-8"?>
<!-- 
Licensed Materials - Property of IBM 
BI and PM: UDA 
(C) Copyright IBM Corp. 2005, 2009 
US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
--> 
<xs:schema xmlns:d="http://developer.cognos.com/schemas/xmldata/1/" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://developer.cognos.com/schemas/xmldata/1/" elementFormDefault="qualified">
	<xs:element name="dataset">
		<xs:complexType>
			<xs:sequence>
				<xs:element name="Fault" type="xs:string" minOccurs="0" maxOccurs="1"/>
				<xs:element name="metadata" type="d:metadataType"/>
				<xs:element name="data" type="d:dataType"/>
			</xs:sequence>
		</xs:complexType>
	</xs:element>
	<xs:complexType name="metadataType">
		<xs:sequence>
			<xs:element name="item" type="d:itemType" maxOccurs="unbounded"/>
		</xs:sequence>
	</xs:complexType>
	<xs:complexType name="itemType">
		<xs:attribute name="name" type="xs:token" use="required"/>
		<xs:attribute name="type" use="required">
			<xs:simpleType>
				<xs:restriction base="xs:NMTOKEN">
					<xs:enumeration value="xs:ENTITIES"/>
					<xs:enumeration value="xs:ENTITY"/>
					<xs:enumeration value="xs:ID"/>
					<xs:enumeration value="xs:IDREF"/>
					<xs:enumeration value="xs:IDREFS"/>
					<xs:enumeration value="xs:NCName"/>
					<xs:enumeration value="xs:NMTOKEN"/>
					<xs:enumeration value="xs:NMTOKENS"/>
					<xs:enumeration value="xs:NOTATION"/>
					<xs:enumeration value="xs:Name"/>
					<xs:enumeration value="xs:QName"/>
					<xs:enumeration value="xs:anyURI"/>
					<xs:enumeration value="xs:base64Binary"/>
					<xs:enumeration value="xs:boolean"/>
					<xs:enumeration value="xs:byte"/>
					<xs:enumeration value="xs:date"/>
					<xs:enumeration value="xs:dateTime"/>
					<xs:enumeration value="xs:decimal"/>
					<xs:enumeration value="xs:double"/>
					<xs:enumeration value="xs:duration"/>
					<xs:enumeration value="xs:float"/>
					<xs:enumeration value="xs:gDay"/>
					<xs:enumeration value="xs:gMonth"/>
					<xs:enumeration value="xs:gMonthDay"/>
					<xs:enumeration value="xs:gYear"/>
					<xs:enumeration value="xs:gYearMonth"/>
					<xs:enumeration value="xs:hexBinary"/>
					<xs:enumeration value="xs:int"/>
					<xs:enumeration value="xs:integer"/>
					<xs:enumeration value="xs:language"/>
					<xs:enumeration value="xs:long"/>
					<xs:enumeration value="xs:negativeInteger"/>
					<xs:enumeration value="xs:nonNegativeInteger"/>
					<xs:enumeration value="xs:nonPositiveInteger"/>
					<xs:enumeration value="xs:normalizedString"/>
					<xs:enumeration value="xs:positiveInteger"/>
					<xs:enumeration value="xs:short"/>
					<xs:enumeration value="xs:string"/>
					<xs:enumeration value="xs:time"/>
					<xs:enumeration value="xs:token"/>
					<xs:enumeration value="xs:unsignedByte"/>
					<xs:enumeration value="xs:unsignedInt"/>
					<xs:enumeration value="xs:unsignedLong"/>
					<xs:enumeration value="xs:unsignedShort"/>
				</xs:restriction>
			</xs:simpleType>
		</xs:attribute>
		<xs:attribute name="length" type="xs:int" use="optional"/>
		<xs:attribute name="scale" type="xs:int" use="optional"/>
		<xs:attribute name="precision" type="xs:int" use="optional"/>
		<!--precision is usually tied to decimal type (xs:decimal), but it is also used specify the interval qualifier for interval type (xs:duration).  In this case the following values represent different interval qualifier: 0 for unknown, 1 for second, 2 for minute, 3 for minute to second, 4 for hour, 6 for hour to minute, 7 for hour to second, 8 for day, 12 for day to hour, 14 for day to minute, 15 for day to second, 16 for month, 32 for year, 48 for year to month.-->
	</xs:complexType>
	<xs:complexType name="dataType">
		<xs:sequence>
			<xs:element ref="d:row" minOccurs="0" maxOccurs="unbounded"/>
		</xs:sequence>
	</xs:complexType>
	<xs:element name="row">
		<xs:complexType>
			<xs:sequence>
				<xs:element name="value" nillable="true" maxOccurs="unbounded">
					<xs:complexType mixed="true">
						<xs:simpleContent>
							<xs:extension base="xs:string">
								<xs:attribute name="currency"/>
							</xs:extension>
						</xs:simpleContent>
					</xs:complexType>
				</xs:element>
			</xs:sequence>
		</xs:complexType>
	</xs:element>
</xs:schema>

Parameterized XML Connection Strings

In an HTTP URL connection string for an XML data source, you can use parameters to send additional information. You can embed a prompt definition string in the parameter component.

If the prompt definition is specified in the report, that value is used. Otherwise, the user is prompted to supply a value. Prompting is not supported for other types of connection strings.

An example of a URL component is addressing_scheme://network_location/path;parameters?query#fragment_identifier

Encode the parameter component with the definition string in between two sets of question marks. A prompt cannot cross a component boundary.

An example of a parameterized XML string is http://My_Network_Location/My_Path/myxml.asp?countryregionsid=??CanadaPrompt??

Parameterized XML connection strings have these restrictions:

  • When a URL component is a prompt, it cannot contain other data.
  • Prompts embedded in XML connection strings do not work in Framework Manager. You cannot import data from a parameterized XML connection string.
  • When you set up a parameterized XML connection string, the Test button does not work.
  • Validation of the query specification in Reporting does not work if you are connected to a parameterized XML connection string.