HomeGuidesRecipesAPI
HomeGuidesAPILog In

XML Data Connector

It is possible to use an XML file as a Data Source, accessible to the SmartIQ application instance.

Key Concepts

XML (Extensible Markup Language) is a simple text-based format for representing structured information derived from SGML (ISO 8879). Originally designed to meet the challenges of large-scale electronic publishing.

XSD (XML Schema Definition) is a World Wide Web Consortium (W3C) recommendation that specifies how to formally describe the elements in an Extensible Markup Language (XML) document.

1. Create an XML and Schema files

SmartIQ XML Data Source requires two files (xl and xsd). Create and save these files in SmartIQ App Server.
XML: File with data to be used within SmartIQ.

<?xml version="1.0" encoding="utf-8"?>
<students>
  <student id="0001">
    <name>Justin</name>
    <lastName>Example</lastName>
    <subjects>
      <subject>
        <name>Science</name>
      </subject>
      <subject>
        <name>Nature History</name>
      </subject>
      <subject>
        <name>Biology</name>
      </subject>
    </subjects>
  </student>
  <student id="0002">
    <name>Adam</name>
    <lastName>Smith</lastName>
    <subjects>
      <subject>
        <name>Software Development</name>
      </subject>
      <subject>
        <name>Cumputers1</name>
      </subject>
    </subjects>
  </student>
  <student id="0003">
    <name>Alex</name>
    <lastName>Weiss</lastName>
    <subjects>
      <subject>
        <name>Financial Engineering</name>
      </subject>
      <subject>
        <name>Accounting</name>
      </subject>
      <subject>
        <name>Excel III</name>
      </subject>
    </subjects>
  </student>
</students>

XML Schema: Definition that specifies filter and display fields used in Data Object

<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="students">
    <xs:complexType>
      <xs:sequence>
        <xs:element maxOccurs="unbounded" name="student">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="name" type="xs:string" />
              <xs:element name="lastName" type="xs:string" />
              <xs:element name="subjects">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element maxOccurs="unbounded" name="subject">
                      <xs:complexType>
                        <xs:sequence>
                          <xs:element name="name" type="xs:string" />
                        </xs:sequence>
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
            <xs:attribute name="id" type="xs:string" use="required" />
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

2. Create a SmartIQ XML Data Source in Manage

Navigate to SmartIQ Manage and click on Data Sources in the right side menu.

  1. Change Data Source Name to "XML Data Source".
  2. Select Connection Type as XML.
  3. Connection string has to reference both path files within SmartIQ App Server, using the key words: xsd and xml.
xsd=C:\inetpub\wwwroot\Infiniti\Datasource\studentsDatabase.xsd; xml=C:\inetpub\wwwroot\Infiniti\Datasource\studentsDatabase.xml;
  1. Click "Test Connection" to validate SmartIQ is able to establish the connection with the xml and schema files.
  2. Click "Save".
10211021

👍

Good Practice

It is recommended to enable "Allow Connection Export" as it will make the data source part of a project definition allowing to import it in a different environment.

3. Create a Hierarchical XPath Data Object

After saving the XML Data Source in Manage, click on "Data Objects" button. This will bring a new window with all available Data Objects for this particular Data Source.

  1. Click on **"New Data Object". Provide following information:

    Object Type: Hierarchical XPath
    Data Object Name / Definition: students\student
    Display Name: Students

  2. Add all filter fields clicking on "Add All >>" button.

  3. Click "Save" button.

14261426

4. XML Validation

From V10.1 it is possible to require that the XML file refereced in connection string be validated against the XSD when accessed. For example if the xml is dynamically generated by some other system. To do this we add an additional parameter to the connection string.

Connection String Parameters

Description

validate

Value must be equal to 1. Requires that the XML be validated against the XSD everytime the XML is used in a project.

Example Connection String##

xsd=C:\temp\Books.xsd; xml=C:\temp\Books.xml; validate=1

If the parameter is present and the value is equal to 1 the XML will be validated against the supplied XSD each time the XML is loaded in a project. An error thrown if the XML is not valid. Error messages are stored in the ErrorLog table.
Using this option will slow down the loading time of the XSD every time it is used in a project.

📘

More Information

If you want to know more about XPath, please click here