XML Deserialize question

  • Thread starter Thread starter Hardy Wang
  • Start date Start date
H

Hardy Wang

Hi,
I have a huge XML file, and only part of the section will be used as my
config setting. Is it possible to deserialize this section only from this
huge XML file?
 
Yes. Use a sax parser, when you hit the section you care about, save it
into a string until you reach the end of the section. After you've got what
you want, load it into memory and away you go.

Robert
 
Thanks for your reply, could you give me more detail. .Net framework does
not support SAX, at least I do not find classes for SAX.
 
Hardy Wang said:
.Net framework does not support SAX, at least I do not
find classes for SAX.

This is correct, the .NET Framework doesn't support SAX.

Instead, it supports a pull model streaming XML processing
API, through it's XmlReader and XmlWriter classes in the
System.Xml namespace.

What you'll probably need to do is subclass XmlTextReader.

It's still necessary to 'read' the whole file up to that point with
these classes, but what you avoid is building up the internal
structures supporting a DOM node tree for the XML content
you don't care about. That's why it can perform better.

Override the properties to detect (through some combination
of LocalName and NamespaceURI for that portion of the doc
you care about) when you enter the region of interest ... raise
a flag. In your overrides of other methods, capture the info
read while this flag is raised until you leave the region of
interest.

A Stack from the System Collections namespace is useful
here to track as you descend and ascend the node tree.


Derek Harmon
 
Back
Top