public static object ParseXml(this IXmlConverter converter, Type valueType, string xmlString, XmlMember member = null, XmlContract contract = null, XmlSerializerSettings settings = null) { var context = CreateContext(valueType, member, contract, settings); using (var input = new StringReader(xmlString)) using (var reader = XmlReader.Create(input, context.Settings.GetReaderSettings())) { while (reader.NodeType != XmlNodeType.Element && reader.Read()) { } if (reader.Name != "xml") { Assert.Fail("Expected start element \"xml\"."); } var isAttribute = context.Member.MappingType == XmlMappingType.Attribute; if (isAttribute) { reader.MoveToAttribute(context.Member.Name.LocalName, context.Member.Name.NamespaceUri); } var value = converter.ReadXml(reader, context); if (isAttribute) { reader.MoveToElement(); if (reader.NodeType != XmlNodeType.Element || reader.Name != "xml") { Assert.Fail("Expected element \"xml\"."); } } else if (reader.NodeType != XmlNodeType.None) { Assert.Fail("Expected end of xml."); } return(value); } }