Left side table is distorted while comparing two HTML table data using daisydiff.jar.
I need your support to fix this issue. Thanks in advance
Using below code
StringWriter finalResult = new StringWriter();
SAXTransformerFactory tf = (SAXTransformerFactory) SAXTransformerFactory.newInstance(); TransformerHandler result = tf.newTransformerHandler();
result.getTransformer().setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
result.getTransformer().setOutputProperty(OutputKeys.INDENT, "no");
result.getTransformer().setOutputProperty(OutputKeys.METHOD, "html");
result.getTransformer().setOutputProperty(OutputKeys.ENCODING, "UTF-8");
result.setResult(new StreamResult(finalResult));
ContentHandler postProcess = result;
Locale locale = Locale.getDefault();
String prefix = "diff";
NekoHtmlParser cleaner = new NekoHtmlParser();
InputSource oldSource = new InputSource (new String reader(html1));
InputSource newSource = new InputSource (new String reader(html2));
DomTreeBuilder oldHandler = new DomTreeBuilder ();
cleaner.parse(oldSource, oldHandler);
TextNodeComparator leftComparator = new TextNodeComparator (oldHandler, locale);
DomTreeBuilder newHandler = new DomTreeBuilder ();
cleaner.parse(newSource, newHandler);
TextNodeComparator rightComparator = new TextNodeComparator (newHandler, locale);
HtmlSaxDiffOutput output = new HtmlSaxDiffOutput (postProcess, prefix);
HTMLDiffer differ = new HTMLDiffer(output);
differ.diff(leftComparator, rightComparator);
Related
Hello guys I am generating a Payment Invoice order in PDF from my html content and sending it by e-mail with the following code:
***//Generates PDF Payment Invoice***
StringBuilder sb = new StringBuilder();
sb.Append(#"<meta http-equiv=""Content-Type"" content=""text/html; charset=utf-8"">");
sb.Append(boletoBancario.MontaHtml());
StringReader sr = new StringReader(sb.ToString());
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
byte[] bytes;
memoryStream = new MemoryStream();
PdfWriter writer = PdfWriter.GetInstance(pdfDoc, memoryStream);
pdfDoc.Open();
iTextSharp.text.html.simpleparser.StyleSheet ST = new iTextSharp.text.html.simpleparser.StyleSheet();
ST.LoadTagStyle("body", "encoding", "Identity-H");
htmlparser.SetStyleSheet(ST);
htmlparser.Parse(sr);
pdfDoc.Close();
bytes = memoryStream.ToArray();
memoryStream.Close();
memoryStream = new MemoryStream(bytes);
***//Sends E-mail with PDF PAYMENT INVOICE Attached***
MailAddress de = new MailAddress(enderecoOrigem, HttpUtility.HtmlDecode(nomeOrigem));
MailAddress para = new MailAddress(enderecoDestino, HttpUtility.HtmlDecode(nomeDestino));
MailMessage mensagem = new MailMessage(de, para);
NetworkCredential credential = new NetworkCredential(usuarioConta, senhaConta);
SmtpClient smtp = new SmtpClient();
smtp.Host = servidorSMTP;
smtp.Port = Convert.ToInt32(porta);
MailAddressCollection comCopia;
Attachment att = new Attachment(memoryStream, "Boleto.pdf", MediaTypeNames.Application.Pdf);
mensagem.Attachments.Add(att);
mensagem.Subject = "Payment Invoice";
mensagem.Body = String.Format("Your payment invoice is available.");
mensagem.IsBodyHtml = true;
smtp.UseDefaultCredentials = true;
smtp.EnableSsl = false;
smtp.Send(mensagem);
The problem is that the PDF attached to the email does not render correctly the HTML so it stills unformmated. Otherwise when i create a blank file and put the entire HTML and open it using Chrome it's pretty well formated.
I need to get this PDF correctly attached to the e-mail.
Could somebody help me?Here You can see the Rendering Problem
Finally I've found the solution to my problem!
It was necessary to use itextSharp.xmlWorker library and do some changes in the code-behind. The reason is HTMLWorker really does not resolve CSS, so I had to use XMLWorker instead and do like following:
//Geração de PDF
StringBuilder sb = new StringBuilder();
StringReader sr;
Document pdfDoc;
PdfWriter writer;
byte[] bytes;
sb.Append(boletoBancario.MontaHtml());
sr = new StringReader(sb.ToString().Replace("<br />","<b></b>").Replace("<br>","<br></br>"));
pdfDoc = new Document(PageSize.A4, 30, 30, 30, 30);
writer = PdfWriter.GetInstance(pdfDoc, memoryStream);
HtmlPipelineContext htmlContext = new HtmlPipelineContext(null);
htmlContext.SetTagFactory(Tags.GetHtmlTagProcessorFactory());
ICSSResolver cssResolver = XMLWorkerHelper.GetInstance().GetDefaultCssResolver(false);
IPipeline pipeline = new CssResolverPipeline(cssResolver, new HtmlPipeline(htmlContext, new PdfWriterPipeline(pdfDoc, writer)));
XMLWorker worker = new XMLWorker(pipeline, true);
XMLParser xmlParser = new XMLParser(worker);
pdfDoc.Open();
xmlParser.Parse(sr);
pdfDoc.Close();
bytes = memoryStream.ToArray();
memoryStream.Close();
return new MemoryStream(bytes);
Thanks you all btw!
Is there a simpler way to do this? I am sincerely concerned that this LinqPad doodle might be too verbose:
var xml = #"
<root attr1=""attribute one"" attr2=""attribute two"">
<title>this is the root</title>
<xhtml>
<div id=""wrapper"">
<p style=""first""><em>hello</em> world!</p>
</div>
</xhtml>
</root>
";
var xDoc = XDocument.Parse(xml);
Func<XNode, string> getXhtml = node =>
{
var s = string.Empty;
StringWriter wr = null;
try
{
wr = new StringWriter();
using(var jsonWriter = new JsonTextWriter(wr))
{
jsonWriter.StringEscapeHandling = StringEscapeHandling.EscapeHtml;
new JsonSerializer().Serialize(jsonWriter, node.ToString());
}
s = wr.ToString();
}
finally
{
if(wr != null) wr.Dispose();
}
return s;
};
var escaped_xhtml = getXhtml(xDoc.Root.Element("xhtml").Element("div"));
escaped_xhtml.Dump("escaped xhtml");
var placeholder = "#rx-xhtml";
xDoc.Root.Element("xhtml").Value = placeholder;
var json = JsonConvert.SerializeXNode(xDoc.Root, Newtonsoft.Json.Formatting.Indented);
var json_final =json
.Replace(string.Format(#"""{0}""",placeholder), escaped_xhtml);
json_final.Dump("json with escaped xhtml");
var jDoc = JObject.Parse(json_final);
escaped_xhtml = (string)jDoc["root"]["xhtml"];
escaped_xhtml.Dump("decoded xhtml");
It may be reasonable to assume that JSON.NET already has, say, the equivalent of my getXhtml() routine. JSON.NET has so many great features I am concerned that I might be missing out.
Is this what you want? It produces the same result for json_final:
// Parse the XML
var xDoc = XDocument.Parse(xml);
// Extract the "div" element.
var div = xDoc.Root.Element("xhtml").Element("div");
div.Remove();
// Convert the remainder to a JObject.
var jDoc = JObject.FromObject(xDoc.Root, JsonSerializer.CreateDefault(new JsonSerializerSettings { Converters = new[] { new XmlNodeConverter() } }));
// Store the Div element as a string literal.
jDoc["root"]["xhtml"] = div.ToString();
// Stringify the JSON using StringEscapeHandling = StringEscapeHandling.EscapeHtml
var json_final = JsonConvert.SerializeObject(jDoc, new JsonSerializerSettings { Formatting = Formatting.Indented, StringEscapeHandling = StringEscapeHandling.EscapeHtml });
It eliminates the string replacement and the getXhtml delegate. Note that StringEscapeHandling applies during the final conversion to string, not to intermediate conversions to Joken (where string literals are not escaped).
Even simpler still, replace the <Div> element with a corresponding XML string literal before converting to JSON:
// Parse the XML
var xDoc = XDocument.Parse(xml);
// Replace the DIV element with its XML string literal value
var div = xDoc.Root.Element("xhtml").Element("div");
div.Remove();
xDoc.Root.Element("xhtml").Value = div.ToString();
// Convert to JSON using StringEscapeHandling = StringEscapeHandling.EscapeHtml
var json_final = JsonConvert.SerializeObject(xDoc, new JsonSerializerSettings { Converters = new[] { new XmlNodeConverter() }, Formatting = Formatting.Indented, StringEscapeHandling = StringEscapeHandling.EscapeHtml });
I am trying to add an element in existing isolated folder in xml
code:
public void writeToXML(List<AppTile> appList)
{
// Write to the Isolated Storage
XmlWriterSettings x_W_Settings = new XmlWriterSettings();
x_W_Settings.Indent = true;
using (IsolatedStorageFile ISF = IsolatedStorageFile.GetUserStoreForApplication())
{
if (!ISF.FileExists("config.xml"))
{
using (IsolatedStorageFileStream stream = ISF.OpenFile("config.xml", FileMode.CreateNew))
{
XmlSerializer serializer = new XmlSerializer(typeof(List<AppTile>));
using (XmlWriter xmlWriter = XmlWriter.Create(stream, x_W_Settings))
{
serializer.Serialize(xmlWriter, appList);
}
stream.Close();
}
}
else
{
string tileName = null;
string url = null;
string key = null;
byte [] tilePic = null;
XDocument loadedData;
if (appList != null)
{
foreach (AppTile app in appList)
{
tileName = app.TileName;
url = app.Url;
key = app.Key;
tilePic = app.TilePic;
// tilePic = Encoding.UTF8.GetString(app.TilePic,0,app.TilePic.Length);
// tilePic = Encoding.Unicode.GetString(app.TilePic,0,app.TilePic.Length);
// var writer = new BinaryWriter(tilePic);
}
using (Stream stream = ISF.OpenFile("config.xml", FileMode.Open, FileAccess.ReadWrite))
{
loadedData = XDocument.Load(stream);
var RootNode = new XElement("AppTile");
RootNode.Add(new XElement("TileName", tileName));
RootNode.Add(new XElement("Key", key));
RootNode.Add(new XElement("Url", url));
RootNode.Add(new XElement("TilePic", tilePic));
// Find Root Element And Descedents and Append New Node After That
var root = loadedData.Element("ArrayOfAppTile");
var rows = root.Descendants("AppTile");
var lastRow = rows.Last();
lastRow.AddAfterSelf(RootNode);
}
// Save To ISOconfig.xml File
using (IsolatedStorageFileStream newStream = new IsolatedStorageFileStream("config.xml", FileMode.Create, ISF))
{
loadedData.Save(newStream);
newStream.Close();
}
}
}
}
}
while reading from xml i am using xmlWriter and deserialize it to get List
when ever i am trying to acces the tilePic of AppTile type i am getting error :The component cannot be found. with the following code::
Image img = new Image();
MemoryStream imgStream = new MemoryStream(NewApp.TilePic);//NewApp is AppTile type
BitmapImage imgSource = new BitmapImage();
imgSource.SetSource(imgStream);//here i get error
img.Source = imgSource;
Its most likely with the TilePic i am saving is not formatted correctly to be retrieved.
Please Help!!
Why don't you use the SaveJpeg extension methodoogy in creating the byte array?
This one might help you!
Windows Phone - byte array to BitmapImage converter throws exception
solved the issue:
while saving the byte array it is encoded to some format not recognizable while reading,So what i have done is saved it as a string.So the updated code is:
else
{
string tileName = null;
string url = null;
string key = null;
string tilePicString = null;
XDocument loadedData;
System.Windows.Media.Imaging.BitmapImage imgSource = new System.Windows.Media.Imaging.BitmapImage();
if (appList != null)
{
foreach (AppTile app in appList)
{
tileName = app.TileName;
url = app.Url;
key = app.Key;
//changed here
tilePicString = System.Convert.ToBase64String(app.TilePic);
}
//same code as above
I've got a JSON string:
query = {"action":"do","password":"c","name":"s"}
When using HTTPService's send method:
_service = new HTTPService();
_service.url = "http://localhost:8080";
_service.method = "POST";
_service.contentType = "application/json";
_service.resultFormat = "text";
_service.useProxy = false;
_service.makeObjectsBindable = true;
_service.addEventListener(FaultEvent.FAULT,faultRX);
_service.addEventListener(ResultEvent.RESULT,resultRX);
_service.showBusyCursor = true;
var _request:Object = new Object();
_request.query = query;
_service.request = _request;
_service.send();
I don't know what I am doing wrong but on my HTTP server I get:
{["object","Object"]}
Any clues please?
Thanks
You are declaring an object of an object.
Try:
_service.request = query;
_service.send();
you get
{["object","Object"]}
because of this
var _request:Object = new Object();
_request.query = query;
_service.request = _request;
do this
var jsonOBJ:Object = {};
jsonOBJ.action = "do";
jsonOBJ.password = "c";
jsonOBJ.name = "s";
var _service:HTTPService = new HTTPService();
_service.url = "http://localhost:8080";
_service.method = "POST";
_service.contentType = "application/json";
_service.resultFormat = "text";
_service.useProxy = false;
_service.makeObjectsBindable = true;
_service.addEventListener(FaultEvent.FAULT,faultRX);
_service.addEventListener(ResultEvent.RESULT,resultRX);
_service.showBusyCursor = true;
_service.send( JSON.encode( jsonOBJ ) );// encode the json object with AS3Corelib
Don't forget top JSON decode the string on the server side.
I want to subscribe report on specific schedule in reporting services 2008. i.e report will dilever to user automatically on schedule. I am using visual studio 2008. I have done the configuration setting (rsreportserver.config, app.config after adding refrences of asmx files) by refrence msdn. The code is running fine (no exception occur) and I also get subscription id through calling create subscription indicate all going fine. But after running the code no entry made in Subscription table of ReportServer database. And also not get any mail. While through report server web tool, I can get email and also entery made in database but not from coe. Please someone help me. What I am missing. Plz help
Code is given follow: (Keep in mind, I am using VS2008)
void SendReportEmail()
{
RSServiceReference.ReportingService2005SoapClient rs=new RSServiceReference.ReportingService2005SoapClient();
rs.ClientCredentials.Windows.AllowedImpersonationLevel = new System.Security.Principal.TokenImpersonationLevel();
string batchID = string.Empty;
RSServiceReference.ServerInfoHeader infoHeader = rs.CreateBatch(out batchID);
BatchHeader bh = new BatchHeader()
{
BatchID = batchID,
AnyAttr = infoHeader.AnyAttr
};
string report = "/PCMSR6Reports/PaymentRequestStatusMIS";
string desc = "Send email from code to Hisham#comsoft.com";
string eventType = "TimedSubscription";
string scheduleXml="<ScheduleDefinition xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><StartDateTime xmlns=\"http://schemas.microsoft.com/sqlserver/2006/03/15/reporting/reportingservices\">2010-03-06T15:15:00.000+05:00</StartDateTime></ScheduleDefinition>";
RSServiceReference.ParameterValue[] extensionParams = new RSServiceReference.ParameterValue[7];
extensionParams[0] = new RSServiceReference.ParameterValue();
extensionParams[0].Name = "TO";
extensionParams[0].Value = "Hisham#comsoft.com";
extensionParams[1] = new RSServiceReference.ParameterValue();
extensionParams[1].Name = "IncludeReport";
extensionParams[1].Value = "True";
extensionParams[2] = new RSServiceReference.ParameterValue();
extensionParams[2].Name = "RenderFormat";
extensionParams[2].Value = "MHTML";
extensionParams[3] = new RSServiceReference.ParameterValue();
extensionParams[3].Name = "Subject";
extensionParams[3].Value = "#ReportName was executed at #ExecutionTime";
extensionParams[4] = new RSServiceReference.ParameterValue();
extensionParams[4].Name = "Comment";
extensionParams[4].Value = "Here is your test report for testing purpose";
extensionParams[5] = new RSServiceReference.ParameterValue();
extensionParams[5].Name = "IncludeLink";
extensionParams[5].Value = "True";
extensionParams[6] = new RSServiceReference.ParameterValue();
extensionParams[6].Name = "Priority";
extensionParams[6].Value = "NORMAL";
RSServiceReference.ParameterValue[] parameters = new RSServiceReference.ParameterValue[10];
parameters[0] = new RSServiceReference.ParameterValue();
parameters[0].Name = "BranchId";
parameters[0].Value = "1";
parameters[1] = new RSServiceReference.ParameterValue();
parameters[1].Name = "UserName";
parameters[1].Value = "admin";
parameters[2] = new RSServiceReference.ParameterValue();
parameters[2].Name = "SupplierId";
parameters[2].Value = "0";
string matchData = scheduleXml;
RSServiceReference.ExtensionSettings extSettings = new RSServiceReference.ExtensionSettings();
extSettings.ParameterValues = extensionParams;
extSettings.Extension = "Report Server Email";
try
{
string sub="";
RSServiceReference.ServerInfoHeader SubID = rs.CreateSubscription(bh, report, extSettings, desc, eventType, matchData, parameters, out sub);
rs.FireEvent(bh, "TimedSubscription", sub);
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
Detail response will be highly appricated.
Try adding # at the beginning of your xml string #"