locked
.AppendChild not useable? too slow? got alternatives? RRS feed

  • Question

  • this code takes in excess of 100ms, meaning loading a repeater list of 20 items takes 2seconds, and having 10 of these lists, means the user has to wait for 20seconds just for the form to load 10 dropdownlists... what is microsoft thinking when they give out so many examples using .AppendChild??  I used a string += for the group and elements then used .InnerXML = string;  to populate the 10 lists, finishes the whole thing in like 400ms. down from 20seconds.. anyone tell me why all the examples use .AppendChild when it is such a dog slow piece of microsoft code?  Have I written it wrong? is there a faster way I should be using this. Is it the XmlWriter object that is the heavy beast?

    Microsofts Way:

    using (XmlWriter writer = node.AppendChild())
    {
    writer.WriteStartElement(
    "FacilityList", my);
    writer.WriteElementString(
    "FacilityValue", my, facility.Location_Code);
    writer.WriteElementString(
    "FacilityText", my, facility.Location_Text);
    writer.WriteElementString("FacilityValueAndText", my, facility.Location_Code + " (" + facility.Location_Text + ")");
    writer.WriteElementString("FacilityTextAndValue", my, facility.Location_Text + " (" + facility.Location_Code + ")");
    writer.WriteEndElement();
    writer.Close();
    }


    My Fast way:

     

    XPathNavigator myRoot = MainDataSource.CreateNavigator();
    XPathNavigator node = myRoot.SelectSingleNode("/my:AuditForm/my:MasterData/my:FacilityGroup", NamespaceManager);
    string facilityList = "";
    foreach

    XPathNavigator myRoot = MainDataSource.CreateNavigator();
    XPathNavigator node = myRoot.SelectSingleNode("/my:AuditForm/my:MasterData/my:FacilityGroup", NamespaceManager);
    string facilityList = "";
    foreach

     

    (InfoPathMasterDS.LkLocationRow facility in RefreshDataHandler.MasterData.LkLocation.Rows)
    {
    facilityList += CreateGroup("FacilityList");
    facilityList += CreateElement(
    "FacilityValue", facility.Location_Code);
    facilityList += CreateElement(
    "FacilityText", facility.Location_Text);
    facilityList += CreateElement(
    "FacilityValueAndText", facility.Location_Code + " (" + facility.Location_Text + ")");
    facilityList += CreateElement(
    "FacilityTextAndValue", facility.Location_Text + " (" + facility.Location_Code + ")");
    facilityList += EndGroup(
    "FacilityList");
    }
    node.InnerXml = facilityList;

     


     

    Saturday, February 5, 2011 5:46 AM

Answers

All replies