Skip to main content
... Parsing XML so I can write it to SQL?

To expand, I have a list held in a process-level XML field that contains active directory groups. It looks like this:

<Root>
<CriticalProfiles>eShare Users</CriticalProfiles>
<CriticalProfiles>eShare Managers</CriticalProfiles>
<CriticalProfiles>eShare Advisers</CriticalProfiles>
<CriticalProfiles>eShare Corporate</CriticalProfiles>
</Root>

I need to write each item in that list to a seperate row in a SQL table.

Using a SQL Data Event, it works - but it only writes the first item in the list.

I need it to loop through and write each item on a new row.

A search on the forum found the following for parsing XML for email:

.Value, "my:myXMLRoot/my:EmailElements");
for (int i = 0; i < xmlNodeList.Count; i++)
{
//do something with the value of the element, maybe append it to a string
emailText += xmlNodeList.Item(i).InnerXml;
}


Any kind soul out there feel like helping me modify this for a SQL event?

Many thanks,

Rich
Hi Richard,

If you are using SQL Server there is an XML data load process that you can follow. Just use the XML schema defined there as the basis for you K2 process variable.

Hope this helps

Graham
Hi Graham,

Thanks very much for the reply.

I now have this *nearly* working... Through a combination of bad coding and mashing together various snippets...

Here is my code:

" + 
" ) Values ( ";

string nsUri = XmlNode.GetNamespaceOfPrefix("");

// CriticalGroup_Name
strVar = "";
strVar += ;
sqlComm.CommandText += "'" + strVar.ToString().Replace("'", "''") + "'" + ")";

sqlComm.ExecuteNonQuery();



And it very nearly works. The problem is with this line:


strVar += ;


If I enter a value in there, it writes to the table the correct number of times so I know it's basically working.

However, I can't seem to work out what to set that to in order that it writes the group names.....

If I set it to XmlNode.Value, it writes the first group name but leaves the rest as nulls?

Anybody feel like helping out here? It would be greatly appreciated.

Many thanks in advance,

Rich

Reply