XmlReader Question

Tech-Archive recommends: Fix windows errors by optimizing your registry



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;
.....
}
}
}


.



Relevant Pages

  • Re: Pluggable Modules
    ... >properties file with plugins specified? ... obscure file somewhere he has to load into a text editor to edit ... themselves and update the config file. ...
    (comp.lang.java.programmer)
  • YAML config files with environment specific settings
    ... cod I'm able to load the file within my initializer and ... Since this setting is a server location that varies by environment, ... tried to use the by-environment structure and changed my config file to ... error: Uncaught exception: syntax error on line 1, ...
    (comp.lang.ruby)
  • Re: Urlscan with multiple .ini files?
    ... Just to confirm, you can load multiple instances of UrlScan, but they will ... instances will refer to the config file of the first loaded instance. ... > - config'd each ini so the logging is to separate locations ...
    (microsoft.public.inetserver.iis.security)
  • Re: Keyboard model under XFree86-4.3 on a ThinkpPad T40
    ... It doesn't load it, you do. ... You load it by editing the config file to ... say what keyboard you want, or you do it key by key with xmodmap. ... Then modify to taste with xmodmap. ...
    (comp.os.linux.portable)
  • Re: Package siunitx Error: Unit em already defined!
    ... I've redefine the command \degree used by my to \mydegree then I ... load the sinuitx like this and it works well: ... Each config file sets up certain units. ...
    (comp.text.tex)