Parse XML

From Starfish ETL
Revision as of 18:39, 5 April 2019 by Jkuehlthau (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

First I add code and External Assemblies to the .NET GLobal section of the Mapping tab:

using System;
using System.Collections.Generic;
using System.Xml;
XmlDocument demographicsXML = new XmlDocument();
XmlNodeList nodes;

External Assemblies: System.dll,,System.Xml.dll,System.Data.dll

Second I populate the global variables using a Repeat Each Row Before Operation:

using System;
using System.Collections.Generic;
using System.Xml;
void CSharpProcedure()
{
	string demographicsString = "<Demographics>"+Starfish.OriginData["DEMOGRAPHICS"].ToString()+"</Demographics>";
	demographicsXML.LoadXml(demographicsString);
	nodes = demographicsXML.DocumentElement.SelectNodes("/Demographics");
}

Third, I populate a field with data from the global variable:

object ScriptedField()
{
	string res = "";
	foreach (XmlNode node in nodes)
	{
		res = node["EXTITLE"].InnerText;
	}
	return res;
}