예제 #1
0
        public void TestXPointerIndentationBug()
        {
            XmlUrlResolver resolver = new XmlUrlResolver();

            resolver.Credentials = CredentialCache.DefaultCredentials;
            XsltSettings xsltSettings = new XsltSettings();

            xsltSettings.EnableDocumentFunction = true;
            XmlReaderSettings settings = new XmlReaderSettings();

            settings.ProhibitDtd = false;
            XmlReader        reader       = XmlReader.Create("../../XInclude/tests/Transform.xsl", settings);
            XIncludingReader xInputReader = new XIncludingReader("../../XInclude/tests/FileA.xml");

            try
            {
                MvpXslTransform processor = new MvpXslTransform(false);
                processor.Load(reader, xsltSettings, resolver);
                //xInputReader.XmlResolver = new XMLBase();
                XmlDocument xInputDoc = new XmlDocument();
                xInputDoc.Load(xInputReader);
                XmlInput     xInput  = new XmlInput(xInputDoc);
                StringWriter stringW = new StringWriter();
                XmlOutput    xOutput = new XmlOutput(stringW);
                processor.Transform(xInput, null, xOutput);
                processor.TemporaryFiles.Delete();
                Assert.AreEqual("<?xml version=\"1.0\" encoding=\"utf-16\"?>NodeA Content", stringW.ToString());
            }
            finally
            {
                reader.Close();
                xInputReader.Close();
            }
        }
예제 #2
0
        public void TwoFallbacks()
        {
            XIncludingReader xir = new XIncludingReader("../../XInclude/tests/twofallbacks.xml");

            while (xir.Read())
            {
                ;
            }
            xir.Close();
        }
예제 #3
0
        public void UnknownParseAttribute()
        {
            XIncludingReader xir = new XIncludingReader("../../XInclude/tests/unknownparseattr.xml");

            while (xir.Read())
            {
                ;
            }
            xir.Close();
        }
예제 #4
0
        public void FallbackNotChildOfInclude()
        {
            XIncludingReader xir = new XIncludingReader("../../XInclude/tests/fallbacknotchildinclude.xml");

            while (xir.Read())
            {
                ;
            }
            xir.Close();
        }
예제 #5
0
        public void IncludeChildOfInclude()
        {
            XIncludingReader xir = new XIncludingReader("../../XInclude/tests/includechildofinclude.xml");

            while (xir.Read())
            {
                ;
            }
            xir.Close();
        }
예제 #6
0
        public void NoHrefAndNoXPointerAttributes()
        {
            XIncludingReader xir = new XIncludingReader("../../XInclude/tests/nohref.xml");

            while (xir.Read())
            {
                ;
            }
            xir.Close();
        }
예제 #7
0
        //[Ignore("XmlSerialization doesn't work on dynamic AppDomains")]
        public void WizardLoad()
        {
            XIncludingReader ir = new XIncludingReader(BaseDir + "wizard.xml");

            ir.MoveToContent();
            Console.WriteLine(ir.ReadOuterXml());
            ir = new XIncludingReader(BaseDir + "wizard.xml");

            XmlSerializer ser = new XmlSerializer(typeof(Wizard));
            Wizard        wz  = (Wizard)ser.Deserialize(ir);

            ir.Close();

            Assert.IsNotNull(wz.Types);
            Assert.AreEqual(2, wz.Types.Length);
        }
예제 #8
0
        public void InnerXmlTest()
        {
            XIncludingReader xir = new XIncludingReader("../../XInclude/tests/document.xml");

            xir.MoveToContent();
            string innerXml = xir.ReadInnerXml();

            xir.Close();
            xir = new XIncludingReader("../../XInclude/tests/document.xml");
            xir.MoveToContent();
            XmlDocument doc = new XmlDocument();

            doc.PreserveWhitespace = true;
            doc.Load(xir);
            string innerXml2 = doc.DocumentElement.InnerXml;

            Assert.AreEqual(innerXml, innerXml2);
        }
예제 #9
0
        /// <summary>
        /// Utility method for running tests.
        /// </summary>
        public static void RunAndCompare(string source, string result, bool textAsCDATA, XmlResolver resolver)
        {
            XmlDocument doc = new XmlDocument();

            doc.PreserveWhitespace = true;
            XIncludingReader xir = new XIncludingReader(source);

            if (resolver != null)
            {
                xir.XmlResolver = resolver;
            }
            xir.ExposeTextInclusionsAsCDATA = textAsCDATA;
//            while (xir.Read())
//            {
//                Console.WriteLine("{0} | {1} | {2} | {3}", xir.NodeType, xir.Name, xir.Value, xir.IsEmptyElement);
//            }
//            throw new Exception();
            try
            {
                doc.Load(xir);
            }
            catch (Exception e)
            {
                xir.Close();
                throw e;
            }
            xir.Close();
            XmlReaderSettings s = new XmlReaderSettings();

            s.ProhibitDtd      = false;
            s.IgnoreWhitespace = true;
            XmlReader r1 = XmlReader.Create(new StringReader(doc.OuterXml), s, doc.BaseURI);
            XmlReader r2 = XmlReader.Create(result, s);

            try
            {
                while (r1.Read())
                {
                    Assert.IsTrue(r2.Read());
                    while (r1.NodeType == XmlNodeType.XmlDeclaration ||
                           r1.NodeType == XmlNodeType.Whitespace)
                    {
                        r1.Read();
                    }
                    while (r2.NodeType == XmlNodeType.XmlDeclaration ||
                           r2.NodeType == XmlNodeType.Whitespace)
                    {
                        r2.Read();
                    }
                    Assert.AreEqual(r1.XmlLang, r2.XmlLang);
                    switch (r1.NodeType)
                    {
                    case XmlNodeType.Attribute:
                        Assert.AreEqual(r2.NodeType, XmlNodeType.Attribute);
                        Assert.AreEqual(r1.Name, r2.Name);
                        Assert.AreEqual(r1.LocalName, r2.LocalName);
                        Assert.AreEqual(r1.NamespaceURI, r2.NamespaceURI);
                        Assert.AreEqual(r1.Value, r2.Value);
                        break;

                    case XmlNodeType.CDATA:
                        Assert.IsTrue(r2.NodeType == XmlNodeType.CDATA || r2.NodeType == XmlNodeType.Text);
                        Assert.AreEqual(r1.Value, r2.Value);
                        break;

                    case XmlNodeType.Comment:
                        Assert.AreEqual(r2.NodeType, XmlNodeType.Comment);
                        Assert.AreEqual(r1.Value, r2.Value);
                        break;

                    case XmlNodeType.DocumentType:
                        Assert.AreEqual(r2.NodeType, XmlNodeType.DocumentType);
                        Assert.AreEqual(r1.Name, r2.Name);
                        //Ok, don't compare DTD content
                        //Assert.AreEqual(r1.Value, r2.Value);
                        break;

                    case XmlNodeType.Element:
                        Assert.AreEqual(r2.NodeType, XmlNodeType.Element);
                        Assert.AreEqual(r1.Name, r2.Name);
                        Assert.AreEqual(r1.LocalName, r2.LocalName);
                        Assert.AreEqual(r1.NamespaceURI, r2.NamespaceURI);
                        Assert.AreEqual(r1.Value, r2.Value);
                        break;

                    case XmlNodeType.Entity:
                        Assert.AreEqual(r2.NodeType, XmlNodeType.Entity);
                        Assert.AreEqual(r1.Name, r2.Name);
                        Assert.AreEqual(r1.Value, r2.Value);
                        break;

                    case XmlNodeType.EndElement:
                        Assert.AreEqual(r2.NodeType, XmlNodeType.EndElement);
                        break;

                    case XmlNodeType.EntityReference:
                        Assert.AreEqual(r2.NodeType, XmlNodeType.EntityReference);
                        Assert.AreEqual(r1.Name, r2.Name);
                        Assert.AreEqual(r1.Value, r2.Value);
                        break;

                    case XmlNodeType.Notation:
                        Assert.AreEqual(r2.NodeType, XmlNodeType.Notation);
                        Assert.AreEqual(r1.Name, r2.Name);
                        Assert.AreEqual(r1.Value, r2.Value);
                        break;

                    case XmlNodeType.ProcessingInstruction:
                        Assert.AreEqual(r2.NodeType, XmlNodeType.ProcessingInstruction);
                        Assert.AreEqual(r1.Name, r2.Name);
                        Assert.AreEqual(r1.Value, r2.Value);
                        break;

                    case XmlNodeType.SignificantWhitespace:
                        Assert.AreEqual(r2.NodeType, XmlNodeType.SignificantWhitespace);
                        Assert.AreEqual(r1.Value, r2.Value);
                        break;

                    case XmlNodeType.Text:
                        Assert.IsTrue(r2.NodeType == XmlNodeType.CDATA || r2.NodeType == XmlNodeType.Text);
                        Assert.AreEqual(r1.Value.Replace("\r\n", "\n").Replace("\r", "").Trim(), r2.Value.Replace("\r\n", "\n").Replace("\r", "").Trim());
                        break;

                    default:
                        break;
                    }
                }
                Assert.IsFalse(r2.Read());
                Assert.IsTrue(r1.ReadState == ReadState.EndOfFile || r1.ReadState == ReadState.Closed);
                Assert.IsTrue(r2.ReadState == ReadState.EndOfFile || r2.ReadState == ReadState.Closed);
            }
            catch (Exception e)
            {
                r1.Close();
                r1 = null;
                r2.Close();
                r2 = null;
                ReportResults(result, doc);
                throw e;
            }
            finally
            {
                if (r1 != null)
                {
                    r1.Close();
                }
                if (r2 != null)
                {
                    r2.Close();
                }
            }
            ReportResults(result, doc);
        }
예제 #10
0
        /// <summary>
        /// Perform the transformation.
        /// </summary>
        /// <param name="inputFile">Input (XML) file.</param>
        /// <param name="xsltFile">Transformation (XSLT) file.</param>
        /// <param name="outputFile">Output file.</param>
        private void Transform(string inputFile, string xsltFile, string outputFile)
        {
            try
            {
                XIncludingReader xIncludingReader	= new XIncludingReader(inputFile);
                XPathDocument xPathDocument			= new XPathDocument(xIncludingReader);

                XslCompiledTransform xslTransform	= new XslCompiledTransform(true);
                xslTransform.Load(xsltFile);

                System.IO.StreamWriter streamWriter = new StreamWriter(outputFile, false, System.Text.Encoding.ASCII);
                xslTransform.Transform(xPathDocument, new XsltArgumentList(), streamWriter);

                xIncludingReader.Close();
                streamWriter.Close();
            }
            catch (Exception exception)
            {
                // Add error handling here.
                MessageBox.Show(this, exception.Message, "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                return;
            }
        }