//[Variation(Desc = "Write into used reader (Xlinq lookup + existing hint in the Writer; same prefix)",
                //   Priority = 2,
                //   Params = new object[] { "<p1:root xmlns:p1='nsp'><p1:B /></p1:root>" })]
                public void testIntoOpenedWriterXlinqLookup2()
                {
                    XElement e = new XElement("A",
                                              new XAttribute(XNamespace.Xmlns + "p1", "nsp"),
                                              new XElement("{nsp}B"));

                    StringWriter sw = new StringWriter();

                    using (XmlWriter w = XmlWriter.Create(sw, new XmlWriterSettings()
                    {
                        NamespaceHandling = NamespaceHandling.OmitDuplicates, OmitXmlDeclaration = true
                    }))
                    {
                        // prepare writer
                        w.WriteStartDocument();
                        w.WriteStartElement("p1", "root", "nsp");
                        // write xelement
                        e.Element("{nsp}B").WriteTo(w);
                        // close the prep. lines
                        w.WriteEndElement();
                        w.WriteEndDocument();
                    }
                    sw.Dispose();

                    ReaderDiff.Compare(sw.ToString(), CurrentChild.Params[0] as string);
                }
                //[Variation(Priority = 0, Desc = "Annotation on document - Omit", Params = new object[] { typeof(XDocument), "Simple.xml", SaveOptions.OmitDuplicateNamespaces })]
                //[Variation(Priority = 1, Desc = "Annotation on document - Omit + Disable", Params = new object[] { typeof(XDocument), "Simple.xml", SaveOptions.OmitDuplicateNamespaces | SaveOptions.DisableFormatting })]
                //[Variation(Priority = 0, Desc = "Annotation on element - Omit", Params = new object[] { typeof(XElement), "Simple.xml", SaveOptions.OmitDuplicateNamespaces })]
                //[Variation(Priority = 1, Desc = "Annotation on element - Omit + Disable", Params = new object[] { typeof(XElement), "Simple.xml", SaveOptions.OmitDuplicateNamespaces | SaveOptions.DisableFormatting })]
                public void XDocAnnotation()
                {
                    Type        t        = CurrentChild.Params[0] as Type;
                    string      fileName = Path.Combine(s_MyPath, CurrentChild.Params[1] as string);
                    SaveOptions so       = (SaveOptions)CurrentChild.Params[2];

                    using (MemoryStream ms = new MemoryStream())
                    {
                        XDocument toClean = XDocument.Load(FilePathUtil.getStream(fileName));
                        using (XmlWriter w = XmlWriter.Create(ms, new XmlWriterSettings()
                        {
                            OmitXmlDeclaration = true, NamespaceHandling = NamespaceHandling.OmitDuplicates
                        }))
                        {
                            toClean.Save(w);
                        }
                        ms.Position = 0;

                        using (XmlReader r1 = XmlReader.Create(ms, new XmlReaderSettings()
                        {
                            IgnoreWhitespace = true, DtdProcessing = DtdProcessing.Ignore
                        }))
                        {
                            XContainer doc = GetContainer(fileName, t);
                            doc.AddAnnotation(so);
                            using (XmlReader r2 = doc.CreateReader())
                            {
                                ReaderDiff.Compare(r1, r2);
                            }
                        }
                    }
                }
                public void XElementConflictsNSRedefinitionToString(string xml1, string xml2)
                {
                    XElement    el = XElement.Parse(xml1);
                    SaveOptions so = SaveOptions.OmitDuplicateNamespaces | SaveOptions.DisableFormatting;

                    ReaderDiff.Compare(xml2, el.ToString(so));
                }
                //[Variation(Desc = "Conflicts: NS redefinition", Priority = 2, Params = new object[] {   "<p:A xmlns:p='nsp'><p:B xmlns:p='ns-other'><p:C xmlns:p='nsp'><D xmlns:p='nsp'/></p:C></p:B></p:A>",
                //                                                                                        "<p:A xmlns:p='nsp'><p:B xmlns:p='ns-other'><p:C xmlns:p='nsp'><D/></p:C></p:B></p:A>" })]
                //[Variation(Desc = "Conflicts: NS redefinition, default NS", Priority = 2, Params = new object[] {   "<A xmlns='nsp'><B xmlns='ns-other'><C xmlns='nsp'><D xmlns='nsp'/></C></B></A>",
                //                                                                                                    "<A xmlns='nsp'><B xmlns='ns-other'><C xmlns='nsp'><D/></C></B></A>" })]
                //[Variation(Desc = "Conflicts: NS redefinition, default NS II.", Priority = 2, Params = new object[] {   "<A xmlns=''><B xmlns='ns-other'><C xmlns=''><D xmlns=''/></C></B></A>",
                //                                                                                                        "<A><B xmlns='ns-other'><C xmlns=''><D/></C></B></A>" })]
                //[Variation(Desc = "Conflicts: NS undeclaration, default NS", Priority = 2, Params = new object[] {  "<A xmlns='nsp'><B xmlns=''><C xmlns='nsp'><D xmlns='nsp'/></C></B></A>",
                //                                                                                                    "<A xmlns='nsp'><B xmlns=''><C xmlns='nsp'><D/></C></B></A>" })]
                public void testConflicts()
                {
                    object e1 = Parse(CurrentChild.Params[0] as string);

                    TestLog.WriteLineIgnore(SaveXElement(e1, SaveOptions.OmitDuplicateNamespaces | SaveOptions.DisableFormatting));
                    ReaderDiff.Compare(SaveXElement(e1, SaveOptions.OmitDuplicateNamespaces | SaveOptions.DisableFormatting), AppendXmlDecl(CurrentChild.Params[1] as string));
                }
                //[Variation(Priority = 0, Desc = "Simulate the VB behavior - Save")]
                public void SimulateVb1()
                {
                    string        expected = "<?xml version=\"1.0\" encoding=\"utf-16\"?>\n<A xmlns=\"ns1\">\n  <B />\n  <C />\n</A>";
                    XElement      e1       = CreateVBSample();
                    StringBuilder sb       = new StringBuilder();

                    e1.Save(new StringWriter(sb));
                    ReaderDiff.Compare(sb.ToString(), expected);
                }
                //[Variation(Priority = 0, Desc = "Local settings override annotation")]
                public void LocalOverride()
                {
                    string        expected = "<?xml version=\"1.0\" encoding=\"utf-16\"?>\n<A xmlns=\"ns1\">\n  <B xmlns=\"ns1\"/>\n  <C xmlns=\"ns1\"/>\n</A>";
                    XElement      e1       = CreateVBSample();
                    StringBuilder sb       = new StringBuilder();

                    e1.Save(new StringWriter(sb), SaveOptions.None);
                    ReaderDiff.Compare(sb.ToString(), expected);
                }
                //[Variation(Desc = "Not from root IV.", Priority = 2)]
                public void testFromChildNode4()
                {
                    XElement e = new XElement("root",
                                              new XAttribute(XNamespace.Xmlns + "p1", "nsp"),
                                              new XElement("{nsp}A",
                                                           new XElement("{nsp}B")));

                    ReaderDiff.Compare(SaveXElementUsingXmlWriter(e.Descendants("{nsp}B").FirstOrDefault(), NamespaceHandling.OmitDuplicates), "<p1:B xmlns:p1='nsp'/>");
                }
                //[Variation(Desc = "Not from root", Priority = 1)]
                public void testFromChildNode1()
                {
                    XElement e = new XElement("root",
                                              new XAttribute(XNamespace.Xmlns + "p1", "nsp"),
                                              new XElement("{nsp}A",
                                                           new XElement("{nsp}B",
                                                                        new XAttribute("xmlns", "nsp"))));

                    ReaderDiff.Compare(SaveXElementUsingXmlWriter(e.Element("{nsp}A"), NamespaceHandling.OmitDuplicates), "<p1:A xmlns:p1='nsp'><B xmlns='nsp'/></p1:A>");
                }
                public void XElementConflictsNSRedefinitionSaveToStringWriterAndGetContent(string xml1, string xml2)
                {
                    XElement    el = XElement.Parse(xml1);
                    SaveOptions so = SaveOptions.OmitDuplicateNamespaces | SaveOptions.DisableFormatting;

                    using (StringWriter sw = new StringWriter())
                    {
                        el.Save(sw, so);
                        ReaderDiff.Compare(GetXmlStringWithXmlDecl(xml2), sw.ToString());
                    }
                }
Example #10
0
 public static void CompareNamespaceAware(SaveOptions so, XmlReader originalReader, XmlReader filteredReader)
 {
     if ((so & SaveOptions.OmitDuplicateNamespaces) > 0)
     {
         CompareNamespaceAware(originalReader, filteredReader);
     }
     else
     {
         ReaderDiff.Compare(originalReader, filteredReader);
     }
     return;
 }
                //[Variation(Desc = "Not from root IV.", Priority = 2)]
                private void testFromChildNode4()
                {
                    if (_type == typeof(XDocument))
                    {
                        TestLog.Skip("Test not applicable");
                    }
                    XElement e = new XElement("root",
                                              new XAttribute(XNamespace.Xmlns + "p1", "nsp"),
                                              new XElement("{nsp}A",
                                                           new XElement("{nsp}B")));

                    ReaderDiff.Compare(SaveXElement(e.Descendants("{nsp}B").FirstOrDefault(), SaveOptions.OmitDuplicateNamespaces | SaveOptions.DisableFormatting), AppendXmlDecl("<p1:B xmlns:p1='nsp'/>"));
                }
                //[Variation(Priority = 0, Desc = "Simulate the VB behavior - Reader")]
                public void SimulateVb2()
                {
                    string   expected = "<A xmlns=\"ns1\"><B /><C /></A>";
                    XElement e1       = CreateVBSample();

                    using (XmlReader r1 = XmlReader.Create(new StringReader(expected)))
                    {
                        using (XmlReader r2 = e1.CreateReader())
                        {
                            ReaderDiff.Compare(r1, r2);
                        }
                    }
                }
Example #13
0
                //[Variation(Desc = "Not from root II.", Priority = 1)]
                public void testFromChildNode2()
                {
                    if (_type == typeof(XDocument))
                    {
                        TestLog.Skip("Test not applicable");
                    }
                    XElement e = new XElement("root",
                                              new XAttribute(XNamespace.Xmlns + "p1", "nsp"),
                                              new XElement("{nsp}A",
                                                           new XElement("{nsp}B",
                                                                        new XAttribute(XNamespace.Xmlns + "p1", "nsp"))));

                    ReaderDiff.Compare(SaveXElement(e.Element("{nsp}A"), SaveOptions.OmitDuplicateNamespaces | SaveOptions.DisableFormatting), AppendXmlDecl("<p1:A xmlns:p1='nsp'><p1:B/></p1:A>"));
                }
Example #14
0
                void CompareStringThroughXmlReader(string xml1, string xml2)
                {
                    XmlReaderSettings rs = new XmlReaderSettings();

                    rs.IgnoreWhitespace = true;

                    using (StringReader sr1 = new StringReader(xml1))
                        using (StringReader sr2 = new StringReader(xml2))
                            using (XmlReader r1 = XmlReader.Create(sr1))
                                using (XmlReader r2 = XmlReader.Create(sr2))
                                {
                                    ReaderDiff.Compare(r1, r2);
                                }
                }
                //[Variation(Desc = "Default ns parent autogenerated", Priority = 1)]
                private void testFromTheRootNodeTricky()
                {
                    object e = new XElement("{nsp}A", new XElement("{nsp}B", new XAttribute("xmlns", "nsp")));

                    if (_type == typeof(XDocument))
                    {
                        XDocument d = new XDocument();
                        d.Add(e);
                        e = d;
                    }
                    string act = SaveXElement(e, SaveOptions.OmitDuplicateNamespaces | SaveOptions.DisableFormatting);
                    string exp = AppendXmlDecl("<A xmlns='nsp'><B/></A>");

                    ReaderDiff.Compare(act, exp);
                }
                //[Variation(Priority = 2, Desc = "Annotation on document without omit - None", Params = new object[] { typeof(XDocument), "Simple.xml", SaveOptions.None })]
                //[Variation(Priority = 2, Desc = "Annotation on document without omit - DisableFormating", Params = new object[] { typeof(XDocument), "Simple.xml", SaveOptions.DisableFormatting })]
                //[Variation(Priority = 2, Desc = "Annotation on element without omit - None", Params = new object[] { typeof(XElement), "Simple.xml", SaveOptions.None })]
                //[Variation(Priority = 2, Desc = "Annotation on element without omit - DisableFormating", Params = new object[] { typeof(XElement), "Simple.xml", SaveOptions.DisableFormatting })]
                public void AnnotationWithoutTheOmitDuplicates()
                {
                    Type        t        = CurrentChild.Params[0] as Type;
                    string      fileName = Path.Combine(s_MyPath, CurrentChild.Params[1] as string);
                    SaveOptions so       = (SaveOptions)CurrentChild.Params[2];

                    using (XmlReader r1 = XmlReader.Create(FilePathUtil.getStream(fileName), new XmlReaderSettings()
                    {
                        IgnoreWhitespace = true, DtdProcessing = DtdProcessing.Ignore
                    }))
                    {
                        XContainer doc = GetContainer(fileName, t);
                        doc.AddAnnotation(so);
                        using (XmlReader r2 = doc.CreateReader())
                        {
                            ReaderDiff.Compare(r1, r2);
                        }
                    }
                }
                //[Variation(Priority = 0, Desc = "No annotation - element", Params = new object[] { typeof(XElement), "Simple.xml" })]
                //[Variation(Priority = 0, Desc = "No annotation - document", Params = new object[] { typeof(XDocument), "Simple.xml" })]
                public void NoAnnotation()
                {
                    Type   t        = CurrentChild.Params[0] as Type;
                    string fileName = Path.Combine(s_MyPath, CurrentChild.Params[1] as string);

                    // create normal reader for comparison
                    using (XmlReader r1 = XmlReader.Create(FilePathUtil.getStream(fileName), new XmlReaderSettings()
                    {
                        IgnoreWhitespace = true, DtdProcessing = DtdProcessing.Ignore
                    }))
                    {
                        // create reader from Xlinq
                        XContainer c = GetContainer(fileName, t);
                        using (XmlReader r2 = c.CreateReader())
                        {
                            ReaderDiff.Compare(r1, r2);
                        }
                    }
                }
                //[Variation(Desc = "1 level down", Priority = 0, Params = new object[] { "<p:A xmlns:p='nsp'><p:B xmlns:p='nsp'><p:C xmlns:p='nsp'/></p:B></p:A>" })]
                //[Variation(Desc = "1 level down II.", Priority = 0, Params = new object[] { "<A><p:B xmlns:p='nsp'><p:C xmlns:p='nsp'/></p:B></A>" })]  // start at not root node
                //[Variation(Desc = "2 levels down", Priority = 1, Params = new object[] { "<p:A xmlns:p='nsp'><B><p:C xmlns:p='nsp'/></B></p:A>" })]
                //[Variation(Desc = "2 levels down II.", Priority = 1, Params = new object[] { "<p:A xmlns:p='nsp'><B><C xmlns:p='nsp'/></B></p:A>" })]
                //[Variation(Desc = "2 levels down III.", Priority = 1, Params = new object[] { "<A xmlns:p='nsp'><B><p:C xmlns:p='nsp'/></B></A>" })]
                //[Variation(Desc = "Siblings", Priority = 2, Params = new object[] { "<A xmlns:p='nsp'><p:B xmlns:p='nsp'/><C xmlns:p='nsp'/><p:C xmlns:p='nsp'/></A>" })]
                //[Variation(Desc = "Children", Priority = 2, Params = new object[] { "<A xmlns:p='nsp'><p:B xmlns:p='nsp'><C xmlns:p='nsp'><p:C xmlns:p='nsp'/></C></p:B></A>" })]
                //[Variation(Desc = "Xml namespace I.", Priority = 3, Params = new object[] { "<A xmlns:xml='http://www.w3.org/XML/1998/namespace'/>" })]
                //[Variation(Desc = "Xml namespace II.", Priority = 3, Params = new object[] { "<p:A xmlns:p='nsp'><p:B xmlns:p='nsp'><p:C xmlns:p='nsp' xmlns:xml='http://www.w3.org/XML/1998/namespace'/></p:B></p:A>" })]
                //[Variation(Desc = "Xml namespace III.", Priority = 3, Params = new object[] { "<p:A xmlns:p='nsp'><p:B xmlns:xml='http://www.w3.org/XML/1998/namespace' xmlns:p='nsp'><p:C xmlns:p='nsp' xmlns:xml='http://www.w3.org/XML/1998/namespace'/></p:B></p:A>" })]
                //[Variation(Desc = "Default namespaces", Priority = 1, Params = new object[] { "<A xmlns='nsp'><p:B xmlns:p='nsp'><C xmlns='nsp' /></p:B></A>" })]
                //[Variation(Desc = "Not used NS declarations", Priority = 2, Params = new object[] { "<A xmlns='nsp' xmlns:u='not-used'><p:B xmlns:p='nsp'><C xmlns:u='not-used' xmlns='nsp' /></p:B></A>" })]
                //[Variation(Desc = "SameNS, different prefix", Priority = 2, Params = new object[] { "<p:A xmlns:p='nsp'><B xmlns:q='nsp'><p:C xmlns:p='nsp'/></B></p:A>" })]
                public void testFromTheRootNodeSimple()
                {
                    string   xml  = CurrentChild.Params[0] as string;
                    XElement elem = XElement.Parse(xml);

                    // Write using XmlWriter in duplicate namespace decl. removal mode
                    string removedByWriter = SaveXElementUsingXmlWriter(elem, NamespaceHandling.OmitDuplicates);

                    // Remove the namespace decl. duplicates from the Xlinq tree
                    (from a in elem.DescendantsAndSelf().Attributes()
                     where a.IsNamespaceDeclaration && ((a.Name.LocalName == "xml" && (string)a == XNamespace.Xml.NamespaceName) ||
                                                        (from parentDecls in a.Parent.Ancestors().Attributes(a.Name)
                                                         where parentDecls.IsNamespaceDeclaration && (string)parentDecls == (string)a
                                                         select parentDecls).Any()
                                                        )
                     select a).ToList().Remove();

                    // Write XElement using XmlWriter without omitting
                    string removedByManual = SaveXElementUsingXmlWriter(elem, NamespaceHandling.Default);

                    ReaderDiff.Compare(removedByWriter, removedByManual);
                }
                //[Variation(Priority = 0, Desc = "Annotation on the parent nodes, XElement", Params = new object[] { typeof(XElement), "simple.xml" })]
                //[Variation(Priority = 0, Desc = "Annotation on the parent nodes, XDocument", Params = new object[] { typeof(XDocument), "simple.xml" })]
                public void AnnotationOnParent1()
                {
                    Type   t        = CurrentChild.Params[0] as Type;
                    string fileName = Path.Combine(s_MyPath, CurrentChild.Params[1] as string);

                    var orig = GetContainer(fileName, t).DescendantNodes().ToArray();
                    var test = GetContainer(fileName, t).DescendantNodes().ToArray();

                    for (int i = 0; i < test.Count(); i++)
                    {
                        XNode n      = test[i];
                        XNode parent = n; // verify parent and self
                        while (parent != null)
                        {                 // for all parents
                            // verify original version
                            TestLog.Compare(n.ToString(), n.ToString(SaveOptions.None), "Initial value");
                            TestLog.Compare(n.ToString(), orig[i].ToString(), "Initial value, via orig");
                            ReaderDiff.Compare(orig[i].CreateReader(), n.CreateReader());
                            // add annotation on parent
                            parent.AddAnnotation(SaveOptions.OmitDuplicateNamespaces);
                            // verify with annotation
                            TestLog.Compare(n.ToString(), n.ToString(SaveOptions.OmitDuplicateNamespaces), "with the annotation, normal");
                            ReaderDiffNSAware.CompareNamespaceAware(orig[i].CreateReader(), n.CreateReader());
                            // removeannotation
                            parent.RemoveAnnotations(typeof(SaveOptions));
                            // verify after removal
                            TestLog.Compare(n.ToString(), n.ToString(SaveOptions.None), "after removed annotation value");
                            TestLog.Compare(n.ToString(), orig[i].ToString(), "after removed annotation, via orig");
                            ReaderDiff.Compare(orig[i].CreateReader(), n.CreateReader());
                            // move parent
                            if (parent is XDocument)
                            {
                                break;
                            }
                            parent = parent.Parent ?? parent.Document as XNode;
                        }
                    }
                }
                //[Variation(Desc = "Write into used reader I. (def. ns.)", Priority = 0, Params = new object[] { "<A xmlns='nsp'/>", "<root xmlns='nsp'><A/></root>" })]
                //[Variation(Desc = "Write into used reader II. (def. ns.)", Priority = 2, Params = new object[] { "<A xmlns='ns-other'><B xmlns='nsp'><C xmlns='nsp'/></B></A>",
                //                                                                                                 "<root xmlns='nsp'><A xmlns='ns-other'><B xmlns='nsp'><C/></B></A></root>" })]
                public void testIntoOpenedWriterDefaultNS()
                {
                    XElement e = XElement.Parse(CurrentChild.Params[0] as string);

                    StringWriter sw = new StringWriter();

                    using (XmlWriter w = XmlWriter.Create(sw, new XmlWriterSettings()
                    {
                        NamespaceHandling = NamespaceHandling.OmitDuplicates, OmitXmlDeclaration = true
                    }))
                    {
                        // prepare writer
                        w.WriteStartDocument();
                        w.WriteStartElement("", "root", "nsp");
                        // write xelement
                        e.WriteTo(w);
                        // close the prep. lines
                        w.WriteEndElement();
                        w.WriteEndDocument();
                    }
                    sw.Dispose();

                    ReaderDiff.Compare(sw.ToString(), CurrentChild.Params[1] as string);
                }
                //[Variation(Desc = "1 level down", Priority = 0, Params = new object[] { "<p:A xmlns:p='nsp'><p:B xmlns:p='nsp'><p:C xmlns:p='nsp'/></p:B></p:A>" })]
                //[Variation(Desc = "1 level down II.", Priority = 0, Params = new object[] { "<A><p:B xmlns:p='nsp'><p:C xmlns:p='nsp'/></p:B></A>" })]  // start at not root node
                //[Variation(Desc = "2 levels down", Priority = 1, Params = new object[] { "<p:A xmlns:p='nsp'><B><p:C xmlns:p='nsp'/></B></p:A>" })]
                //[Variation(Desc = "2 levels down II.", Priority = 1, Params = new object[] { "<p:A xmlns:p='nsp'><B><C xmlns:p='nsp'/></B></p:A>" })]
                //[Variation(Desc = "2 levels down III.", Priority = 1, Params = new object[] { "<A xmlns:p='nsp'><B><p:C xmlns:p='nsp'/></B></A>" })]
                //[Variation(Desc = "Siblings", Priority = 2, Params = new object[] { "<A xmlns:p='nsp'><p:B xmlns:p='nsp'/><C xmlns:p='nsp'/><p:C xmlns:p='nsp'/></A>" })]
                //[Variation(Desc = "Children", Priority = 2, Params = new object[] { "<A xmlns:p='nsp'><p:B xmlns:p='nsp'><C xmlns:p='nsp'><p:C xmlns:p='nsp'/></C></p:B></A>" })]
                //[Variation(Desc = "Xml namespace I.", Priority = 3, Params = new object[] { "<A xmlns:xml='http://www.w3.org/XML/1998/namespace'/>" })]
                //[Variation(Desc = "Xml namespace II.", Priority = 3, Params = new object[] { "<p:A xmlns:p='nsp'><p:B xmlns:p='nsp'><p:C xmlns:p='nsp' xmlns:xml='http://www.w3.org/XML/1998/namespace'/></p:B></p:A>" })]
                //[Variation(Desc = "Xml namespace III.", Priority = 3, Params = new object[] { "<p:A xmlns:p='nsp'><p:B xmlns:xml='http://www.w3.org/XML/1998/namespace' xmlns:p='nsp'><p:C xmlns:p='nsp' xmlns:xml='http://www.w3.org/XML/1998/namespace'/></p:B></p:A>" })]
                //[Variation(Desc = "Default namespaces", Priority = 1, Params = new object[] { "<A xmlns='nsp'><p:B xmlns:p='nsp'><C xmlns='nsp' /></p:B></A>" })]
                //[Variation(Desc = "Not used NS declarations", Priority = 2, Params = new object[] { "<A xmlns='nsp' xmlns:u='not-used'><p:B xmlns:p='nsp'><C xmlns:u='not-used' xmlns='nsp' /></p:B></A>" })]
                //[Variation(Desc = "SameNS, different prefix", Priority = 2, Params = new object[] { "<p:A xmlns:p='nsp'><B xmlns:q='nsp'><p:C xmlns:p='nsp'/></B></p:A>" })]
                private void testFromTheRootNodeSimple()
                {
                    string xml     = CurrentChild.Params[0] as string;
                    object elemObj = Parse(xml);

                    // Write using XmlWriter in duplicate namespace decl. removal mode
                    string removedByWriter = SaveXElement(elemObj, SaveOptions.OmitDuplicateNamespaces | SaveOptions.DisableFormatting);

                    XElement elem = (elemObj is XDocument) ? (elemObj as XDocument).Root : elemObj as XElement;

                    // Remove the namespace decl. duplicates from the Xlinq tree
                    (from a in elem.DescendantsAndSelf().Attributes()
                     where a.IsNamespaceDeclaration && ((a.Name.LocalName == "xml" && (string)a == XNamespace.Xml.NamespaceName) ||
                                                        (from parentDecls in a.Parent.Ancestors().Attributes(a.Name)
                                                         where parentDecls.IsNamespaceDeclaration && (string)parentDecls == (string)a
                                                         select parentDecls).Any()
                                                        )
                     select a).ToList().Remove();

                    // Write XElement using XmlWriter without omitting
                    string removedByManual = SaveXElement(elemObj, SaveOptions.DisableFormatting);

                    ReaderDiff.Compare(removedByWriter, removedByManual);
                }
                //[Variation(Desc = "Default ns parent autogenerated", Priority = 1)]
                public void testFromTheRootNodeTricky()
                {
                    XElement e = new XElement("{nsp}A", new XElement("{nsp}B", new XAttribute("xmlns", "nsp")));

                    ReaderDiff.Compare(SaveXElementUsingXmlWriter(e, NamespaceHandling.OmitDuplicates), "<A xmlns='nsp'><B/></A>");
                }
                //[Variation(Desc = "Conflicts: NS redefinition", Priority = 2, Params = new object[] {   "<p:A xmlns:p='nsp'><p:B xmlns:p='ns-other'><p:C xmlns:p='nsp'><D xmlns:p='nsp'/></p:C></p:B></p:A>",
                //                                                                                        "<p:A xmlns:p='nsp'><p:B xmlns:p='ns-other'><p:C xmlns:p='nsp'><D/></p:C></p:B></p:A>" })]
                //[Variation(Desc = "Conflicts: NS redefinition, default NS", Priority = 2, Params = new object[] {   "<A xmlns='nsp'><B xmlns='ns-other'><C xmlns='nsp'><D xmlns='nsp'/></C></B></A>",
                //                                                                                                    "<A xmlns='nsp'><B xmlns='ns-other'><C xmlns='nsp'><D/></C></B></A>" })]
                //[Variation(Desc = "Conflicts: NS redefinition, default NS II.", Priority = 2, Params = new object[] {   "<A xmlns=''><B xmlns='ns-other'><C xmlns=''><D xmlns=''/></C></B></A>",
                //                                                                                                        "<A><B xmlns='ns-other'><C xmlns=''><D/></C></B></A>" })]
                //[Variation(Desc = "Conflicts: NS undeclaration, default NS", Priority = 2, Params = new object[] {  "<A xmlns='nsp'><B xmlns=''><C xmlns='nsp'><D xmlns='nsp'/></C></B></A>",
                //                                                                                                    "<A xmlns='nsp'><B xmlns=''><C xmlns='nsp'><D/></C></B></A>" })]
                public void testConflicts()
                {
                    XElement e1 = XElement.Parse(CurrentChild.Params[0] as string);

                    ReaderDiff.Compare(SaveXElementUsingXmlWriter(e1, NamespaceHandling.OmitDuplicates), CurrentChild.Params[1] as string);
                }