1
// Copyright 2004-2008 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle
.Core
.Configuration
.Xml
24 public class XmlConfigurationDeserializer
27 /// Deserializes the specified node into an abstract representation of configuration.
29 /// <param name="node">The node.</param>
30 /// <returns></returns>
31 public IConfiguration
Deserialize(XmlNode node
)
33 return Deserialize(node
);
36 public static IConfiguration
GetDeserializedNode(XmlNode node
)
38 MutableConfiguration config
;
39 ConfigurationCollection configChilds
= new ConfigurationCollection();
41 StringBuilder configValue
= new StringBuilder();
43 if (node
.HasChildNodes
)
45 foreach(XmlNode child
in node
.ChildNodes
)
47 if (IsTextNode(child
))
49 configValue
.Append(child
.Value
);
51 else if (child
.NodeType
== XmlNodeType
.Element
)
53 configChilds
.Add(GetDeserializedNode(child
));
58 config
= new MutableConfiguration(node
.Name
, GetConfigValue(configValue
.ToString()));
60 foreach(XmlAttribute attribute
in node
.Attributes
)
62 config
.Attributes
.Add(attribute
.Name
, attribute
.Value
);
65 config
.Children
.AddRange(configChilds
);
71 /// If a config value is an empty string we return null, this is to keep
72 /// backward compability with old code
74 public static string GetConfigValue(string value)
78 return value == String
.Empty
? null : value;
81 public static bool IsTextNode(XmlNode node
)
83 return node
.NodeType
== XmlNodeType
.Text
|| node
.NodeType
== XmlNodeType
.CDATA
;