I'm currently working on importing XML feed data into our CMS, but am struggling in how to tackle this issue.
For a course, it can have up to 9 staff members looking after it. Each having a name, phone number, email address and type of job. In the CMS for the import, i have 9 sets of these 4 fields, in order to save the data. To get around this, if there is only 5 staff out of 9, i'm targeting an XMLnodelist of course contacts - if it's null, have an empty string, otherwise populate fields.
In the code below, cclist is defined as an xmlnodelist, and test1 gets the full contents of International Admissions as a whole as a string.
What i want to be able to do, using the same format expanded, is for up to 9 course contacts, get the name, email, phone etc of the xmlnodelist item and separate them out, so they can be targeted for the import. I've tried using descendants etc, but can't seem to be able to target these individually, instead of a full string.
Any help would be greatly appreciated. Thanks.
XML
<course>
<dc:description>...</dc:description>
<dc:title>
<![CDATA[ Marketing ]]>
</dc:title>
<learningOutcome>...</learningOutcome>
<test:coursecontacts
<test:contact xsi:type="LeadAcademic">
<test:name
<![CDATA[ Tommy Thompson ]]>
</test:name
<test:phone>0123456789</test:phone>
<test:email>[email protected]</test:email>
</test:contact>
<test:contact xsi:type="Admissions Administrator">
<test:name>
<![CDATA[ International Admissions ]]>
</test:name>
<test:phone>0123456678</test:phone>
<test:email>[email protected]</test:email
</test:contact
<test:contact xsi:type="Course Leader">...</test:contact>
<test:contact xsi:type="Admissions Administrator">...</test:contact>
<test:contact xsi:type="Course Administrator">...</test:contact>
</test:coursecontacts>
</course>
C#
protected override FeedCourse MapXmlNodeToEntity(XElement p)
{
var xmlResult = new XmlDocument();
xmlResult.LoadXml(p.ToString());
var test = p.ToString();
var xmlnsManager = new XmlNamespaceManager(xmlResult.NameTable);
xmlnsManager.AddNamespace("ns", "http://xcri.org/profiles/1.2/catalog");
xmlnsManager.AddNamespace("xcriTerms", "http://xcri.org/profiles/catalog/terms");
xmlnsManager.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
xmlnsManager.AddNamespace("xhtml", "http://www.w3.org/1999/xhtml");
xmlnsManager.AddNamespace("dc", "http://purl.org/dc/elements/1.1/");
xmlnsManager.AddNamespace("dcterms", "http://purl.org/dc/terms/");
xmlnsManager.AddNamespace("credit", "http://purl.org/net/cm");
xmlnsManager.AddNamespace("mlo", "http://purl.org/net/mlo");
xmlnsManager.AddNamespace("courseDataProgramme", "http://xcri.co.uk");
xmlnsManager.AddNamespace("test", "http://www.test.com");
var elements = xmlResult.ChildNodes;
var title = xmlResult.DocumentElement.SelectSingleNode("dc:title", xmlnsManager).InnerText;
var description = xmlResult.DocumentElement.SelectSingleNode("dc:description", xmlnsManager).InnerText;
var learningOutcome = xmlResult.DocumentElement.SelectSingleNode("ns:learningOutcome", xmlnsManager).InnerText;
XmlNodeList ccList = xmlResult.DocumentElement.SelectNodes("test:coursecontacts/test:contact", xmlnsManager);
var test1 = ccList.Item(1).InnerText;
// Above line gets full contents of test:contact, but i need down to levels of xsi:type, name, phone and email
}
Had a break away, came back and decided to try a 2d array for this solution. Allows me to get the value i need, so i'm happy. Thanks anyway, and hope this helps someone else.
All the best,
Andy.