Page 1 of 1

XML & StiXmlDatabase load from memory

Posted: Fri May 27, 2016 5:31 pm
by alvin
Hi, i need load xml data from memory to report, the report use 3 schemas, no database connection only XML data, and 1 xml, i try some options how i can use StiXmlDatabase to load data from memory, i use next code to work , but this save xml string to disk, and need load directly from memory:

Code: Select all

                                    string xml = "<?xml version="1.0" encoding="utf-8" standalone="yes"?......." // bla bla bla
                                    XmlDocument doc = new XmlDocument();
                                    doc.LoadXml(xml);
                                    doc.Save(@"K:\temp.xml");
                                    tempReport.Dictionary.Databases.RemoveAt(0);
                                    Stimulsoft.Report.Dictionary.StiXmlDatabase myxml = new Stimulsoft.Report.Dictionary.StiXmlDatabase();
                                    myxml.Alias = "XML";
                                    myxml.Name= "XML";
                                    myxml.XmlType = StiXmlType.Xml;
                                    myxml.PathData = @"K:\temp.xml";
                                    tempReport.Dictionary.Databases.Insert(0, myxml);
                                    tempReport.Dictionary.Synchronize();
                                    tempReport.Compile();   
the last code let me load xml from disk and runtime, but i need save before my xml data from memory to disk to work, how i can load directly xml string to report without save to disk.

thanks in advance.

Alvin

Re: XML & StiXmlDatabase load from memory

Posted: Mon May 30, 2016 10:55 am
by Alex K.
Hello,

Please try to use the following code:

Code: Select all

...
DataSet dataSet = new DataSet();
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.LoadXml(xml);

Stream stream = new MemoryStream();
System.Xml.XmlWriter xw = new System.Xml.XmlTextWriter(stream, Encoding.Default);
doc.WriteContentTo(xw);
dataSet.ReadXml(stream);

report.RegData("Data", dataSet);
report.Dictionary.Synchronize();
...
Thank you.