private void _PreParse(string xmlContent, string filename, XMLSerializerParams parameters, List <SerializedData> result, Dictionary <SerializedData, string> filenameMappings, List <SerializerError> errors) { var xElement = XElement.Parse(xmlContent); // Validity checks if (!SerializerValidation.ContainerElementName(parameters, xElement, filename, errors)) { return; } // Iterate over nodes foreach (var xNode in xElement.Nodes()) { var nodeXElement = xNode as XElement; // Validity checks if (!SerializerValidation.NodeIsElement(parameters, xNode, filename, errors)) { continue; } var elementType = SerializerCache.GetSerializableTypeCacheFor(nodeXElement.Name.LocalName, parameters.standardNamespace); if (!SerializerValidation.RootTypeFound(parameters, nodeXElement.Name.LocalName, nodeXElement, elementType, filename, errors)) { continue; } // Prepare var data = new SerializedData(elementType, nodeXElement); result.Add(data); filenameMappings.Set(data, filename); } }
public override string Serialize(List <ISerializableRoot> roots, out List <SerializerError> errors) { errors = ListPool <SerializerError> .Get(); XDocument document = new XDocument(); XElement rootElement = new XElement(parameters.rootElementName); document.Add(rootElement); foreach (var root in roots) { var typeName = root.GetType().Name; var element = new XElement(typeName); element.SetAttributeValue(AttributeIdentifier, root.identifier); var data = new SerializedData(SerializerCache.GetSerializableTypeCacheFor(typeName, parameters.standardNamespace), element); data.WriteFromObject(root, errors, parameters); rootElement.Add(element); } return(document.ToString()); }