An ETL task enables the user to import data from XML files if values are formed in one of two types:
Fields are located in child nodes.
Fields are located in node attributes.
Sometimes an XML file has mixed structure and the part of required data is located in the child nodes and the part is in the node attributes. In this case it is impossible to write an XPath query. Import from an XML file with mixed structure is available by using the Fore macro and the ETL task that is User Provider. Consider the example of import from an XML file with mixed structure.
Structure of the file to be imported:
Class implementing the Fetch method, which imports data:
Class UserProvider: Object, IDtRecordsetProvider
Public Function Fetch: Array Of Variant;
Var
Xml: IXmlDomDocument;
Nodes, ChildNodes: IXmlDomNodeList;
Node: IXmlDomNode;
Date, Val1, Val2: Variant;
Result: Array Of Variant;
i: integer;
Begin
Xml := New DOMDocument.Create;
Xml.load("c:\Data.xml");
Nodes := Xml.getElementsByTagName("Data").item(0).childNodes;
Result := New Variant[Nodes.length, 3];
For i := 0 To Nodes.length - 1 Do
Node := Nodes.item(i);
Date := Node.attributes.getNamedItem("Date").nodeTypedValue;
ChildNodes := Node.childNodes;
Val1 := ChildNodes.item(0).nodeTypedValue;
Val2 := ChildNodes.item(1).nodeTypedValue;
Result[i, 0] := Date;
Result[i, 1] := Val1;
Result[i, 2] := Val2;
End For;
Return Result;
End Function Fetch;
End Class UserProvider;
The name of this class must be specified in settings of user provider.
See also: