Re: reading, writing xml and encoding question

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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
.



Relevant Pages

  • Re: Latest version of glossary
    ... such as XML, refer to the use of the term within that "namespace" using ... An n-dimensional data structure, S, is one where each element of S ... Whenever mathematics is applied to anything, ... associative array (while trying to do something in JavaScript, ...
    (comp.databases.theory)
  • Re: Serialization with XmlSerializer: how to set the XML root node to something different from <
    ... Daniel Cazzulino [MVP XML] ... >> So if it is an array of Foo that is being returned, ... > The point here is not controlling the serialization of the elements of an ... >> modified root node should de-serialize just fine. ...
    (microsoft.public.dotnet.xml)
  • Re: xml
    ... XML has no good array structure representation. ... of pointers into the DOM and as you iterate over the DOM, you fill the array in with these ... There are so many XML reader packages out there that there is no one way to do this. ...
    (microsoft.public.vc.mfc)
  • XML help
    ... I'm 4 months new to python and 4 hours new to XML. ... understand and use the DOM tree walk sample shown at this site: ... walk the tree I temporarily store IDs and DeptValues in lists. ... I then intend to create an array of size determined by the maximum ...
    (comp.lang.python)
  • Re: Serialization with XmlSerializer: how to set the XML root node to something different from <
    ... > So if it is an array of Foo that is being returned, ... The point here is not controlling the serialization of the elements of an ... array, but of the array itself, in other words of the xml root element. ... array is indeed very simple (XmlArrayAttribute and XmlArrayItemAttribute is ...
    (microsoft.public.dotnet.xml)