Reputation: 357
I'm creating a Windows Phone application and I need to implement quite a big database (made of 288,000 items) but whenever I try to run it, the program gives me a System.Xml.XmlException
.
The problem is that if I only put 100 or less items in the XML database it works, and allows me to query it.
Do you have any idea about why it acts like this?
Here is the code :
loadCustomData = XDocument.Load("vocabolario.xml");
var domanda = from c in loadCustomData.Descendants("Parola")
where c.Attribute("id").Value == "1"
select c.Attribute("Contenuto").Value;
lol.Text = domanda.First();
Upvotes: 0
Views: 95
Reputation: 308
From the article by Jon Skeet.
If you're happy reading everything into memory, use XDocument. It'll make your life much easier. LINQ to XML is a lovely API.
Use an XmlReader (such as XmlTextReader) if you need to handle huge XML files in a streaming fashion, basically. It's a much more painful API, but it allows streaming (i.e. only dealing with data as you need it, so you can go through a huge document and only have a small amount in memory at a time).
There's a hybrid approach, however - if you have a huge document made up of small elements, you can create an XElement from an XmlReader positioned at the start of the element, deal with the element using LINQ to XML, then move the XmlReader onto the next element and start again.
Check the Example below
// Create a DOM document with some content.
XmlDocument doc = new XmlDocument();
XmlElement child = doc.CreateElement("Child");
child.InnerText = "child contents";
XmlElement root = doc.CreateElement("Root");
root.AppendChild(child);
doc.AppendChild(root);
// Create a reader and move to the content.
using (XmlNodeReader nodeReader = new XmlNodeReader(doc)) {
// the reader must be in the Interactive state in order to
// Create a LINQ to XML tree from it.
nodeReader.MoveToContent();
XElement xRoot = XElement.Load(nodeReader);
Console.WriteLine(xRoot);
}
This is Just an example try similar thing.
Upvotes: 1