Morning Everyone,
This may be way to deep-geek for most of you, but I ran into something this morning that may be of interest to those of you who work with CRM's XML config files.
I was extending the IsvConfigCustomizer code that ships as part of the ISVReadiness sample code from the CRM SDK to iterate through the Entities section of the ISV.Config file to pull the names of CRM Entities that have had ISV customizations added.
The XML looks like this:
<Entity name="campaignactivity" /> <Entity name="campaignresponse" /> <Entity name="incident" /> <!-- Case --> <Entity name="quote" /> <Entity name="salesorder" /> <!-- Order -->
Everything worked fine, until I hit that comment line containing the word Case. Since it is a comment, it has no attributes. Since I am looking for an attribute called name, my code was failing.
Luckily, the .NET XmlNode class has a corresponding XmlNodeType property that allows me to see if I have encountered a comment or not. The following code ensures I have not encountered a comment before I add the Entity name to my array:
XmlNode docRoot = GetConfigurationNode().SelectSingleNode("Entities");
int iCount = docRoot.ChildNodes.Count;
ArrayList sArray = new ArrayList();
for(int i = 0; i < iCount; i++)
{
if (docRoot.ChildNodes[i].NodeType != XmlNodeType.Comment)
{
XmlAttribute xAttrib = docRoot.ChildNodes[i].Attributes["name"];
if xAttrib!= null)
{
sArray.Add(xAttrib.InnerText);
}
}
}
Leave a reply