Ejemplo n.º 1
0
        public static void SerializeXmlElement(object obj, BinaryWriter writer, MemoryStream ms, ISurrogateContext context)
        {
            var node     = obj as System.Xml.XmlElement;
            var document = node.OwnerDocument;

            string xpath;
            var    isFullXpath = XmlElementHelper.FindXPath(node, out xpath);

            writer.Write(isFullXpath);
            writer.Write(xpath);

            if (!isFullXpath)
            {
                //In the case a node is not attached to a document (any node in its hierarchy has a null parent)
                //the node is serialized by itself independently from the document.
                writer.Write(XmlElementHelper.GetTopParentOuterXml(node));
            }
        }