XmlReader Question
- From: "Mitch" <go@xxxxxxxx>
- Date: Mon, 23 Oct 2006 01:14:11 -0600
Hello,
I have a singleton class that loads a config file (for an assembly) into an
internal stream object. I designed this class as singleton because it
parses the config file many times and I do not want to load the config file
everytime. The problem is I am using XMLReader because of speed and after I
read an item (multiple nodes so pass node name and element name) and try to
read another item I get an error "root element missing". Is the error
caused by XMLReader object or should I change this a load the config file
into XMLDocument and parse it. Am I even acheiving that much performance
gain using XMLReader? Any ideas?
public string GetXMLValue(string nodeName, string elementName)
{
string NS = "";
string xmlValue = "";
XmlReaderSettings settings = new XmlReaderSettings();
settings.IgnoreWhitespace = true;
settings.ProhibitDtd = true;
settings.IgnoreComments = true;
settings.IgnoreProcessingInstructions = true;
settings.ConformanceLevel = ConformanceLevel.Document;
XmlReader reader = null;
using (reader = XmlReader.Create(mappingStream, settings))
{
try
{
reader.Read();
reader.ReadToDescendant(nodeName, NS);
while (reader.ReadToFollowing(elementName, NS))
{
xmlValue = reader.ReadElementContentAsString();
}
return xmlValue;
}
catch
{
return xmlValue;
.....
}
}
}
.
- Follow-Ups:
- Re: XmlReader Question
- From: Marc Gravell
- Re: XmlReader Question
- From: Marc Gravell
- Re: XmlReader Question
- From: _xarky
- Re: XmlReader Question
- Prev by Date: Re: How to open an URL
- Next by Date: Re: Createing new files
- Previous by thread: Drawing a simple pixel to the foreground
- Next by thread: Re: XmlReader Question
- Index(es):
Relevant Pages
|