public MapXmlAttributeNameToPropertyName ( |
||
type | The type for which to make the xml name. | |
xmlName | string | Name of the XML attribute. |
return | string |
/// <summary> /// Generates an object from its XML representation. /// </summary> /// <param name="reader">The <see cref="T:System.Xml.XmlReader"/> stream from which the object is deserialized.</param> void IXmlSerializable.ReadXml(XmlReader reader) { if (reader.IsEmptyElement) { return; } var type = GetType(); var settings = new XmlReaderSettings(); settings.ConformanceLevel = ConformanceLevel.Auto; settings.IgnoreComments = true; settings.IgnoreProcessingInstructions = true; settings.IgnoreWhitespace = true; var newReader = XmlReader.Create(reader, settings); //if (!string.Equals(type.Name, newReader.LocalName, StringComparison.OrdinalIgnoreCase)) //{ // if (!newReader.Read()) // { // return; // } //} bool isAtXmlRoot = string.IsNullOrEmpty(newReader.LocalName) || string.Equals(newReader.LocalName, "xml", StringComparison.OrdinalIgnoreCase); if (isAtXmlRoot) { newReader.MoveToContent(); } // Read attributes if (newReader.MoveToFirstAttribute()) { do { if (PropertyDataManager.IsXmlAttributeNameMappedToProperty(type, newReader.LocalName)) { var propertyName = PropertyDataManager.MapXmlAttributeNameToPropertyName(type, reader.LocalName); ReadValueFromXmlNode(newReader, propertyName); } } while (newReader.MoveToNextAttribute()); } // This might be the node itself or a wrapping node (in case of web services), // so check if that is true and step into child element if (string.IsNullOrEmpty(newReader.LocalName) || !PropertyDataManager.IsXmlElementNameMappedToProperty(type, newReader.LocalName)) { newReader.Read(); newReader.MoveToElement(); } while (newReader.NodeType != XmlNodeType.EndElement) { if (string.IsNullOrEmpty(reader.LocalName)) { Log.Debug("reader.LocalName is null or empty, trying to skip current node"); reader.Skip(); if (string.IsNullOrEmpty(reader.LocalName)) { Log.Warning("reader.LocalName is null or empty, cannot read empty xml tag"); continue; } } if (PropertyDataManager.IsXmlElementNameMappedToProperty(type, reader.LocalName)) { var propertyName = PropertyDataManager.MapXmlElementNameToPropertyName(type, reader.LocalName); ReadValueFromXmlNode(newReader, propertyName); } else { newReader.Skip(); } while (newReader.NodeType == XmlNodeType.Whitespace) { newReader.Skip(); } } FinishDeserialization(); }