I have an xml like this:
<People>
<PersonID>5</PersonID>
<PersonID>7</PersonID>
<PersonID>9</PersonID>
</People>
I would like to create a string with all the id's, like this: "5,7,9". I know it's possible with a simple loop, but since this code will be called 100's of time a second, I would like to make it the fastest possible way.
I'm using C# framework 4.0.
My current code:
XmlDocument doc = new XmlDocument();
XmlNodeList nodeList;
StringBuilder strXml = new StringBuilder();
doc.LoadXml(sXmlQuery);
nodeList = doc.SelectNodes("//PersonID");
if (nodeList != null)
{
foreach (XmlNode node in nodeList)
{
strXml.Append(node.InnerText.Trim());
strXml.Append(",");
}
}