0

Maybe someone can help me out with the following problem. Im streaming a xml file(40mb) from sharepoint with client object model:

  protected void Page_Load(object sender, EventArgs e)
        {
        FileInformation fileInfo = Microsoft.SharePoint.Client.File.OpenBinaryDirect(ccontext, listItem.File.ListItemAllFields["FileRef"].ToString());
     XmlDocument xmldoc = xmlDocument1(fileInfo.Stream);
     TextBox1.Text = xmldoc.Innerxml;
        }



 private XmlDocument xmlDocument1(Stream text1)
        {
            XmlDocument xdoc = new XmlDocument();
            using (XmlReader xmlReader = XmlReader.Create(text1)) 
            {
                while (xmlReader.Read())
                {
                    xdoc.Load(xmlReader);
                }
                xmlReader.Close();
            }
            return xdoc;
        }

It takes to long to load de documents innerxml in to the textbox. Any ideas to make this faster?

Thanks

user3114347
  • 349
  • 1
  • 5
  • 19
  • 1
    XmlDocument performs XML parsing and builds DOM. For a very large XML files it may take some time. If you just need to read raw XML text (as in your example) then you don't need anything else than a plain read over the stream, no XmlReader and no XmlDocument. If you actually need to parse such document and it's big then you'd better to roll out your own code using XmlReader alone – Adriano Repetti Jun 17 '16 at 09:13
  • i need the nodes values from the xml file so i have to read it as a xml. – user3114347 Jun 17 '16 at 09:20
  • 1
    Then you'd better drop XmlDocument, it's relatively slow because it parses full document and build a full usable DOM. If XmlReader is too complex (it is, most of times) then switch to LINQ-to-XML. XDocument is pretty easy to use and faster than XmlDocument (if you query a reasonable subset of document nodes...) – Adriano Repetti Jun 17 '16 at 09:36
  • 1) What kind of performance do you get if you just `while (xmlReader.Read()) ;` -- i.e. use the `XmlReader` to loop through the file without doing anything? 2) If you just need certain values form the file, see [Improving XML Performance](https://msdn.microsoft.com/en-us/library/ff647804.aspx#scalenetchaptch09%20_topic8), [How to: Stream XML Fragments from an XmlReader](https://msdn.microsoft.com/en-us/library/mt693184.aspx) and maybe [How to: Perform Streaming Transform of Large XML Documents (C#)](https://msdn.microsoft.com/en-us/library/mt693229.aspx). – dbc Jun 17 '16 at 16:37

0 Answers0