Skip to content

Instantly share code, notes, and snippets.

@paulsterling
Last active March 26, 2020 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulsterling/d17c455be4a36d0fc002bdff3b72fbea to your computer and use it in GitHub Desktop.
Save paulsterling/d17c455be4a36d0fc002bdff3b72fbea to your computer and use it in GitHub Desktop.
// Snippet for parsing numbers following the pattern from the GoCanvas Integration Sample for .NET
// Note: Original sample was VB.NET, this is my port to C#
public static CanvasResponse ParseResponse(System.Xml.XmlNode ResponseNode)
{
CanvasResponse oResponse = new CanvasResponse();
foreach (System.Xml.XmlNode oChild in ResponseNode)
{
if (oChild.Name == Constants.ResponseNode.SubNodes.LABEL)
oResponse.Label = oChild.InnerText;
if (oChild.Name == Constants.ResponseNode.SubNodes.VALUE)
oResponse.Value = oChild.InnerText;
if (oChild.Name == Constants.ResponseNode.SubNodes.TYPE)
oResponse.Type = oChild.InnerText;
// Multi Photo fields have a Numbers collection
if (oChild.Name == Constants.ResponseNode.SubNodes.NUMBERS)
{
oResponse.Numbers = ParseNumbers(oChild);
}
}
return oResponse;
}
public static ArrayList ParseNumbers(XmlNode NumbersNode)
{
ArrayList alNumbers = new ArrayList();
foreach (System.Xml.XmlNode oChild in NumbersNode)
{
alNumbers.Add(oChild.InnerText);
}
return alNumbers;
}
public class ResponseNode
{
public class SubNodes
{
public const string LABEL = "Label";
public const string VALUE = "Value";
public const string TYPE = "Type";
public const string NUMBERS = "Numbers";
}
}
public class CanvasResponse
{
private string m_strLabel;
public string Label
{
get
{
return m_strLabel;
}
set
{
m_strLabel = value;
}
}
private string m_strValue;
public string Value
{
get
{
return m_strValue;
}
set
{
m_strValue = value;
}
}
private string m_strType;
public string Type
{
get
{
return m_strType;
}
set
{
m_strType = value;
}
}
private ArrayList m_alNumbers = new ArrayList();
public ArrayList Numbers
{
get
{
return m_alNumbers;
}
set
{
m_alNumbers = value;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment