public void XmlResolverResolveUriWithXhtml10DTD() { var resolver = new XmlPreloadedResolver(XmlKnownDtds.Xhtml10); Uri result = resolver.ResolveUri(new Uri("https://JustAUri"), "-//W3C//DTD XHTML 1.0 Frameset//EN"); Assert.Equal("-//W3C//DTD XHTML 1.0 Frameset//EN", result.OriginalString); result = resolver.ResolveUri(new Uri("https://JustAUri"), "-//Invalid//Uri"); Assert.Equal("https://justauri/-//Invalid//Uri", result.OriginalString); }
public void XmlResolverResolveUriWithRss091DTD() { var resolver = new XmlPreloadedResolver(XmlKnownDtds.Rss091); Uri result = resolver.ResolveUri(new Uri("https://JustAUri"), "-//Netscape Communications//DTD RSS 0.91//EN"); Assert.Equal("-//Netscape Communications//DTD RSS 0.91//EN", result.OriginalString); result = resolver.ResolveUri(new Uri("https://JustAUri"), "-//Invalid//Uri"); Assert.Equal("https://justauri/-//Invalid//Uri", result.OriginalString); }
public void XmlResolverResolveUriWithNoneDTD() { var resolver = new XmlPreloadedResolver(XmlKnownDtds.None); Uri result = resolver.ResolveUri(new Uri("https://Uri"), "-//W3C//"); Assert.NotNull(result); }
public XSLTValidator(string languageName, XsltArgumentList xsltArgumentList) { if (null == xsltArgumentList) { throw new ArgumentNullException("xsltArgumentList"); } _xslArg = xsltArgumentList; _xslt = new XslCompiledTransform(); var assembly = this.GetType().Assembly; var resolver = new XmlPreloadedResolver(); string mainXSLT = null; string[] resourceNames = this.GetType().Assembly.GetManifestResourceNames(); foreach (string resourceName in resourceNames) { if (resourceName.EndsWith(".xslt") && resourceName.Contains(languageName)) { string templateName = resourceName.Substring(resourceName.LastIndexOf(languageName) + languageName.Length); if (templateName == ".xslt") { mainXSLT = resourceName; } else { using (var stream = assembly.GetManifestResourceStream(resourceName)) { resolver.Add(resolver.ResolveUri(null, templateName), stream); } } } } using (var stream = assembly.GetManifestResourceStream(mainXSLT)) using (var reader = XmlReader.Create(stream)) { _xslt.Load(reader, null, resolver); } }
protected override void Render(HtmlTextWriter writer) { StringBuilder sbOut = new StringBuilder(); StringWriter swOut = new StringWriter(sbOut); HtmlTextWriter htwOut = new HtmlTextWriter(swOut); base.Render(htwOut); string originalHTML = sbOut.ToString(); if ("true".Equals(Context.Items["EmailRequest"])) { XmlDocument document = new XmlDocument(); string xhtmlStr = sbOut.ToString(); XmlPreloadedResolver resolver = new XmlPreloadedResolver(); resolver.Add(resolver.ResolveUri(null, "Static/xhtml-trans10.dtd"), xhtmlStr); XmlReaderSettings readerSettings = new XmlReaderSettings(); readerSettings.XmlResolver = resolver; readerSettings.DtdProcessing = DtdProcessing.Parse; StringReader sr = new StringReader(xhtmlStr); XmlReader reader = XmlReader.Create(sr, readerSettings); document.Load(reader); XmlElement root = document.DocumentElement; XmlNamespaceManager nsmgr = new XmlNamespaceManager(document.NameTable); nsmgr.AddNamespace("h", document.DocumentElement.NamespaceURI); RewriteImageURLs(root.SelectNodes("//h:img", nsmgr)); RewriteCSSPaths(root.SelectNodes("//h:link", nsmgr)); TransformNodes(document, root.SelectNodes("//h:a", nsmgr), "span"); DeleteNodes(root.SelectNodes("//h:div[@id='inventory-graph']", nsmgr)); DeleteNodes(root.SelectNodes("//h:div[@id='chart']", nsmgr)); DeleteNodes(root.SelectNodes("//h:script", nsmgr)); DeleteNodes(root.SelectNodes("//h:input[@type='hidden']", nsmgr)); // this bit of xpath gets all elements that have onclick attributes RemoveOnClickEvents(root.SelectNodes("self::node()/descendant-or-self::node()[@onclick]", nsmgr)); string reportHTML = "<!DOCTYPE html PUBLIC \" -//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"; reportHTML += document.DocumentElement.OuterXml; _message.Body += "<br/>" + reportHTML; if (Context.Items["EmailAttachmentName"].ToString().EndsWith("pdf")) { PdfService service = new PdfService(); byte[] pdf = service.GeneratePdf(reportHTML); _message.Attachments.Add(new Attachment(new MemoryStream(pdf), Context.Items["EmailAttachmentName"].ToString())); } else if (Context.Items["EmailAttachmentName"].ToString().EndsWith("html")) { ASCIIEncoding encoder = new ASCIIEncoding(); _message.Attachments.Add(new Attachment(new MemoryStream(encoder.GetBytes(reportHTML)), Context.Items["EmailAttachmentName"].ToString())); } SmtpClient client = new SmtpClient(); client.Send(_message); } writer.Write(originalHTML); }
public void XmlResolverResolveUriWithEmptyUri() { var resolver = new XmlPreloadedResolver(XmlKnownDtds.Xhtml10); Assert.Throws <ArgumentNullException>(() => resolver.ResolveUri(null, null)); }