Re: reading, writing xml and encoding question
- From: "Jon Skeet [C# MVP]" <skeet@xxxxxxxxx>
- Date: Thu, 1 May 2008 00:19:46 -0700 (PDT)
On May 1, 12:12 am, billsahi...@xxxxxxxxx wrote:
I made some good progress, thanks to your generate program. Seems that
mine was the problem. I put the code below. Not sure what the
underlying problem with it is. One difference is that it writes with
the streamwriter, not textwriter. another is that it writes each
element on a separate line.
I used your program but changed the tag names to what I was using,
added spaces for indents, added two more levels, but put it all on one
line and I have no problem reading the output file upto 3Gb so far.
I should add that using my CreateRawXml method, I generated a small
file with the same structure and IE had no problem with it -I did this
to see if I had violated a tag name rule or orther rule of some sort.
So what do you think caused the problem I had?
I now know exactly what caused the problem. Your code generates a
different element name for *every element*. Now, XmlReader has an
XmlNameTable - the idea being to avoid generating too many strings,
instead using a dictionary of element and attribute names that it's
already seen. That's great for almost all real-world XML, which uses a
small set of element/attribute names throughout even large documents.
It breaks completely on your XML though.
As far as I can tell, you can't ask XmlReader not to use an
XmlNameTable at all, but you can provide a no-op one which *doesn't*
cache things:
class NoOpNameTable : XmlNameTable
{
public override string Add(string array)
{
return array;
}
public override string Add(char[] array, int offset, int
length)
{
if (length == 0)
{
return string.Empty;
}
return new string(array, offset, length);
}
public override string Get(string array)
{
return array;
}
public override string Get(char[] array, int offset, int
length)
{
if (length == 0)
{
return string.Empty;
}
return new string(array, offset, length);
}
}
Pass an instance of that into the constructor to XmlTextReader, and I
think you'll find everything works fine.
Alternatively, try to avoid creating such pathological XML
documents :)
Jon
.
- Follow-Ups:
- Re: reading, writing xml and encoding question
- From: billsahiker
- Re: reading, writing xml and encoding question
- References:
- Re: reading, writing xml and encoding question
- From: billsahiker
- Re: reading, writing xml and encoding question
- Prev by Date: Re: Dynamic Field in C#?
- Next by Date: Re: Binding.FormatString rendering curly braces & trick to Bind to List<T>.Count property?
- Previous by thread: Re: reading, writing xml and encoding question
- Next by thread: Re: reading, writing xml and encoding question
- Index(es):
Relevant Pages
|