c# - representing an XML config file with an IXmlSerializable class -
I am writing in C # and representing an XML configuration file via the IXmlSerializable
class I am trying to do How can I represent nested elements in my config file, though, such as logLevel
:
& lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; Configuration & gt; & Lt; Logging & gt; & Lt; LogLevel & gt; Error & lt; / LogLevel & gt; & Lt; / Logging & gt; & Lt; Credit & gt; & Lt; Users & gt; User123 & lt; / User & gt; & Lt; Host & gt; Local Host & lt; / Host & gt; & Lt; Password & gt; Pass123 & lt; / Password & gt; & Lt; / Credibility & gt; & Lt; Credit & gt; & Lt; Users & gt; User456 & lt; / User & gt; & Lt; Host & gt; My.other.domain.com & lt; / Host & gt; & Lt; Password & gt; Pass456 & lt; / Password & gt; & Lt; / Credibility & gt; & Lt; / Configuration & gt; There is an element called log level
which represents all possible values for the logLevel
tag. Tags within credentials
come in the form of all strings. In my class, which is called DLLConfigFile
, the following was the following:
[XmlElement (element name = "logleval", datatype = "logleval")] public logleval loglevel ;
However, this is not working because & lt; LogLevel & gt;
is not within the root node of the XML file, it is a node in depth to & lt; Logging & gt;
. & lt; Credential & gt; For nodes, I think I'll need a second class, the address of the credentials
, and there is a property in the form of:
< Code> [XmlElement (ElementName = "credentials", datatype = "address of credentials")] Public credentials [edit] AllCredentials; Edit: OK: I tried Robert Love's suggestion and created a logging address
class. However, my test fails: var xs = new XML serializer (typef (DLLConfigFile)); (Var StreamReader = New Stream Reader (Stream)) {XmlReader Reader = New XmlTextReader (Stream Reader); (Var Stream = New File Stream (_configPath, FileMode.Open, FileAccess.Read, FileShare Reid)); Var file = (DLLConfigFile) xs.Deserialize (Reader); Assert.IsNotNull (file); Logging extension logging = file. Leasing; Assert.IsNotNull (login); // here fails LogLevel logLevel = logging.LogLevel; Assert.IsNotNull (LogLevel); Assign. AEQWELL (EXPECTED_LOG_LEVEL, logelveled); }}
I'm definitely & lt; Logging & gt; I'm filing a test with
. What these squares look like:
log level
Comments
Post a Comment