c# - Is there a faster way to count an XmlNodeList -


i read couple of regex definitions xml count function requires 47.3% of time. there better / faster way job done?

private string[] xmlnodestostring(xmlnodelist tagname) {     int = tagname.count;   //47,3%     int = 0;     stringbuilder sbtemp = new stringbuilder();     while (a > 0)     {         if (tagname[i].innertext != "null")//11,8%         {             sbtemp.appendline(tagname[i].innertext);         }         i++;         a--;     }     char[] csplitdef = { '\n' };     return (sbtemp.tostring().split(csplitdef, stringsplitoptions.removeemptyentries)); } 

i'm glad :)

just iterate on nodes:

private string[] xmlnodestostring(xmlnodelist tagname) {    return xmlnodelist.cast<xmlnode>()                      .select(n => n.innertext)                      .where(t => !string.isnullorempty(t))                      .toarray(); } 

you don't need nodes count, access nodes index , build string, later should splitted.


if linq not available you:

private string[] xmlnodestostring(xmlnodelist nodes) {       list<string> result = new list<string>();        foreach(xmlnode node in nodes)           if (!string.isnullorempty(node.innertext))               result.add(node.innertext);        return result.toarray(); } 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -