// -------------------------------------------------------------------------------------------------------------- // LoadXSL_Resolver_Evidence // ------------------------------------------------------------------------------------------------------------- /*public int LoadXSL_Resolver_Evidence(String _strXslFile, XmlResolver xr, Evidence e) * { * _strXslFile = FullFilePath(_strXslFile); * xslt = new XslCompiledTransform(); * * switch (_nInputXsl) * { * case XslInputType.Reader: * switch (_readerType) * { * case ReaderType.XmlTextReader: * XmlReader trTemp = XmlReader.Create(_strXslFile); * try * { * _output.WriteLine("Loading style sheet as XmlTextReader " + _strXslFile); * //xslt.Load(trTemp, xr, e); //Evidence is not supported on V2 XSLT Load * xslt.Load(trTemp, XsltSettings.TrustedXslt, xr); * } * catch (Exception ex) * { * throw (ex); * } * finally * { * if (trTemp != null) * trTemp.Dispose(); * } * break; * * case ReaderType.XmlNodeReader: * XmlDocument docTemp = new XmlDocument(); * docTemp.Load(_strXslFile); * XmlNodeReader nrTemp = new XmlNodeReader(docTemp); * try * { * _output.WriteLine("Loading style sheet as XmlNodeReader " + _strXslFile); * //xslt.Load(nrTemp, xr, e); Evidence is not supported in V2 XSLT Load * xslt.Load(nrTemp, XsltSettings.TrustedXslt, xr); * } * catch (Exception ex) * { * throw (ex); * } * finally * { * if (nrTemp != null) * nrTemp.Dispose(); * } * break; * * case ReaderType.XmlValidatingReader: * default: * XmlReaderSettings xrs = new XmlReaderSettings(); #pragma warning disable 0618 * xrs.ProhibitDtd = false; #pragma warning restore 0618 * XmlReader vrTemp = null; * try * { * vrTemp = XmlReader.Create(_strXslFile, xrs); * _output.WriteLine("Loading style sheet as XmlValidatingReader " + _strXslFile); * //xslt.Load(vrTemp, xr, e); Evidence is not supported in V2 XSLT Load * xslt.Load(vrTemp, XsltSettings.TrustedXslt, xr); * } * catch (Exception ex) * { * throw (ex); * } * finally * { * if (vrTemp != null) * vrTemp.Dispose(); * } * break; * } * break; * * case XslInputType.Navigator: * XmlReader xrLoad = XmlReader.Create(_strXslFile); * XPathDocument xdTemp = new XPathDocument(xrLoad, XmlSpace.Preserve); * xrLoad.Dispose(); * _output.WriteLine("Loading style sheet as Navigator " + _strXslFile); * xslt.Load(xdTemp.CreateNavigator(), XsltSettings.TrustedXslt, xr); * break; * } * return 1; * }*/ //VerifyResult public void VerifyResult(string expectedValue) { XmlDiff.XmlDiff xmldiff = new XmlDiff.XmlDiff(); xmldiff.Option = XmlDiffOption.InfosetComparison | XmlDiffOption.IgnoreEmptyElement | XmlDiffOption.NormalizeNewline; StreamReader sr = new StreamReader(new FileStream("out.xml", FileMode.Open, FileAccess.Read)); string actualValue = sr.ReadToEnd(); sr.Dispose(); //Output the expected and actual values _output.WriteLine("Expected : " + expectedValue); _output.WriteLine("Actual : " + actualValue); //Load into XmlTextReaders XmlTextReader tr1 = new XmlTextReader("out.xml"); XmlTextReader tr2 = new XmlTextReader(new StringReader(expectedValue)); bool result = xmldiff.Compare(tr1, tr2); //Close the readers tr1.Dispose(); tr2.Dispose(); Assert.True(result); }
//VerifyResult public void VerifyResult(string expectedValue) { lock (s_outFileMemoryLock) { XmlDiff.XmlDiff xmldiff = new XmlDiff.XmlDiff(); xmldiff.Option = XmlDiffOption.InfosetComparison | XmlDiffOption.IgnoreEmptyElement | XmlDiffOption.NormalizeNewline; string actualValue = File.ReadAllText(_strOutFile); //Output the expected and actual values _output.WriteLine("Expected : " + expectedValue); _output.WriteLine("Actual : " + actualValue); bool result; //Load into XmlTextReaders using (XmlTextReader tr1 = new XmlTextReader(_strOutFile)) using (XmlTextReader tr2 = new XmlTextReader(new StringReader(expectedValue))) { result = xmldiff.Compare(tr1, tr2); } Assert.True(result); } }
//VerifyResult which compares 2 arguments using XmlDiff. public void VerifyResult(string baseline, string outputFile) { bool bResult = false; FileStream fsExpected; baseline = FullFilePath(baseline); XmlDiff.XmlDiff diff = new XmlDiff.XmlDiff(); diff.Option = XmlDiffOption.IgnoreEmptyElement | XmlDiffOption.IgnoreAttributeOrder | XmlDiffOption.InfosetComparison | XmlDiffOption.IgnoreWhitespace; XmlParserContext context = new XmlParserContext(new NameTable(), null, "", XmlSpace.None); fsExpected = new FileStream(baseline, FileMode.Open, FileAccess.Read, FileShare.Read); FileStream fsActual = new FileStream(outputFile, FileMode.Open, FileAccess.Read, FileShare.Read); _output.WriteLine("Verifying o/p with baseline result {0}...", baseline); try { bResult = diff.Compare(new XmlTextReader(fsActual, XmlNodeType.Element, context), new XmlTextReader(fsExpected, XmlNodeType.Element, context)); } catch (Exception e) { // TO DO: Write exception msgs in ignore tags _output.WriteLine(e.ToString()); } finally { fsExpected.Dispose(); fsActual.Dispose(); } if (!bResult) { // Write out the actual and expected o/p _output.WriteLine("Expected o/p: "); using (StreamReader sr = new StreamReader(new FileStream(baseline, FileMode.Open, FileAccess.Read))) { string baseLine = sr.ReadToEnd(); _output.WriteLine(baseLine); } _output.WriteLine("Actual o/p: "); using (StreamReader sr = new StreamReader(new FileStream(outputFile, FileMode.Open, FileAccess.Read))) { string output = sr.ReadToEnd(); _output.WriteLine(output); } using (StreamWriter sw = new StreamWriter(new FileStream("diff.xml", FileMode.Open, FileAccess.Read))) { sw.WriteLine("<?xml-stylesheet href='diff.xsl' type='text/xsl'?>"); sw.WriteLine(diff.ToXml()); } } if (bResult) return; else { _output.WriteLine("**** Baseline mis-matched ****"); Assert.True(false); } }
public void ManuallyDeclaredPrefixNamespacePairIsNotReflectedInTheXElementSerialization() { var element = XElement.Parse("<A/>"); element.Add(new XAttribute(XNamespace.Xmlns + "p", "ns")); element.Add(new XElement("{ns}B", null)); MemoryStream sourceStream = new MemoryStream(); element.Save(sourceStream); sourceStream.Position = 0; // creating the following element with expected output so we can compare XElement target = XElement.Parse("<A xmlns:p=\"ns\"><p:B /></A>"); MemoryStream targetStream = new MemoryStream(); target.Save(targetStream); targetStream.Position = 0; XmlDiff.XmlDiff diff = new XmlDiff.XmlDiff(); Assert.True(diff.Compare(sourceStream, targetStream)); }
public static void VerifyTest(string actResult, string expResult) { XmlDiff.XmlDiff diff = new XmlDiff.XmlDiff(); diff.Option = XmlDiffOption.IgnoreEmptyElement | XmlDiffOption.IgnoreAttributeOrder; XmlTextReader xrActual = new XmlTextReader(new StringReader(actResult)); XmlTextReader xrExpected = new XmlTextReader(new StringReader(expResult)); bool bResult = false; try { bResult = diff.Compare(xrActual, xrExpected); } catch (Exception e) { bResult = false; s_output.WriteLine("Exception thrown in XmlDiff compare!"); s_output.WriteLine(e.ToString()); } finally { if (xrActual != null) { xrActual.Dispose(); } if (xrExpected != null) { xrExpected.Dispose(); } } s_output.WriteLine("Expected : " + expResult); s_output.WriteLine("Actual : " + actResult); if (bResult) { return; } else { Assert.True(false); } }
public void OS11(object param0, object param1) { Init(param0.ToString(), param1.ToString()); _xsl.Load(_xslFile); //Transform to Stream Stream stm1 = new FileStream("out1.xml", FileMode.Create, FileAccess.ReadWrite); _output.WriteLine("Transforming to Stream1 - 'out1.xml'"); _xsl.Transform(_xmlFile, null, stm1); //Create an XmlWriter using OutputSettings Stream stm2 = new FileStream("out2.xml", FileMode.Create, FileAccess.ReadWrite); XmlWriterSettings os = _xsl.OutputSettings; XmlWriter xw = XmlWriter.Create(stm2, os); //Transform to XmlWriter _output.WriteLine("Transforming to XmlWriter over Stream2 with XSLT OutputSettings - 'out2.xml'"); _xsl.Transform(_xmlFile, null, xw); //Close the streams stm1.Dispose(); stm2.Dispose(); //XmlDiff the 2 Outputs. XmlDiff.XmlDiff diff = new XmlDiff.XmlDiff(); XmlReader xr1 = XmlReader.Create("out1.xml"); XmlReader xr2 = XmlReader.Create("out2.xml"); //XmlDiff _output.WriteLine("Comparing the Stream Output and XmlWriter Output"); Assert.True(diff.Compare(xr1, xr2)); //Delete the temp files xr1.Dispose(); xr2.Dispose(); File.Delete("out1.xml"); File.Delete("out2.xml"); return; }
public void VerifyResult(string actualFile, string baselineFile) { XmlDiff.XmlDiff diff = new XmlDiff.XmlDiff(); diff.Option = XmlDiffOption.IgnoreEmptyElement | XmlDiffOption.IgnoreAttributeOrder; XmlParserContext context = new XmlParserContext(new NameTable(), null, "", XmlSpace.None); using (FileStream fsActual = new FileStream(actualFile, FileMode.Open, FileAccess.Read)) { using (FileStream fsExpected = new FileStream(baselineFile, FileMode.Open, FileAccess.Read)) { XmlTextReader xrActual = new XmlTextReader(fsActual, XmlNodeType.Element, context); XmlTextReader xrExpected = new XmlTextReader(fsExpected, XmlNodeType.Element, context); bool bResult = false; try { bResult = diff.Compare(xrActual, xrExpected); } catch (Exception e) { bResult = false; s_output.WriteLine("Exception thrown in XmlDiff compare!"); s_output.WriteLine(e.ToString()); } s_output.WriteLine("Actual result: "); this.WriteFile(actualFile); if (bResult) { return; } else { s_output.WriteLine("Mismatch in XmlDiff"); Assert.True(false); } } } }