This is my table
<table class="DataRows" frame="myFrames" rules="Standard" width="100%">
<colgroup><col width="70" align="CENTER">
<col width="200" align="LEFT">
<col width="80" align="LEFT">
<col align="LEFT">
<col align="RIGHT">
</colgroup><thead>
<col width="70" align="CENTER">
<col width="200" align="LEFT">
<col width="80" align="LEFT">
<col align="LEFT">
<col align="RIGHT">
<thead>
<tr>
<td valign="TOP"><span class="classicBold"> 20 </span> Kg.
<td class="BOLD" valign="TOP" nowrap="">
PA Passion Foods Inc.
<td class="BOLD">Fax:
<td>
222-555666
<td class="BOLD">
Processed foods and juices
<tr>
<td><a target="_blank" href="">See on Map </a>
<td>
120 NW 157TH AVE
<td class="BOLD">Warehouse Hours:
<td colspan="2">
<tr>
<td>
<td><span class="BOLD">
Jacksonville,
</span>
FL 300000
<td class="BOLD">Url:
<td colspan="2">
<a target="_blank" href="">PA Passion</a>
  
<span class="BOLD">E-mail:</span>
zoro#xyz.com
<tr>
<td>
<td class="REDBOLD" colspan="4">
<tr>
<td>
<td colspan="4" align="LEFT">Franchisee for:<span class="BOLD">
Nutrella
</span>
<tr>
<td>
<td colspan="4" align="LEFT">Franchisee for:<span class="BOLD">
APPLE Foods, Constants
</span>
<tr>
<td>
<td colspan="4" align="LEFT"><span class="BOLD">
</span>
<tr>
<td>
<td colspan="4" align="LEFT">We service:<span class="BOLD">
All occasions and hospitality services
</span>
<tr>
<td>
<td colspan="4" align="LEFT">We sell :<span class="BOLD">
----
</span>
</td></td></tr></td></td></tr></td></td></tr></td></td></tr></td></td></tr></td></td></tr></td></td></td></td></tr></td></td></td></td></tr></td></td></td></td></td></tr>
</thead>
</table>
I am looping through each node in my Html document using the code below
foreach (HtmlNode node in htmlAgilityPackDoc.DocumentNode.SelectNodes("//table[contains(#class,'DataRows')]"))
{
}
When I use the following
node.SelectSingleNode(".//tr[1]/td[1]").InnerHtml
I get the following html
<span class="classicBold"> 20 </span> Kg.
<td class="BOLD" valign="TOP" nowrap="">
PA Passion Foods Inc.
<td class="BOLD">Fax:
<td>
222-555666
<td class="BOLD">
Processed foods and juices
<tr>
<td><a target="_blank" href="">See on Map </a>
<td>
120 NW 157TH AVE
<td class="BOLD">Warehouse Hours:
<td colspan="2">
<tr>
<td>
<td><span class="BOLD">
Jacksonville,
</span>
FL 300000
<td class="BOLD">Url:
<td colspan="2">
<a target="_blank" href="">PA Passion</a>
  
<span class="BOLD">E-mail:</span>
zoro#xyz.com
<tr>
<td>
<td class="REDBOLD" colspan="4">
<tr>
<td>
<td colspan="4" align="LEFT">Franchisee for:<span class="BOLD">
Nutrella
</span>
<tr>
<td>
<td colspan="4" align="LEFT">Franchisee for:<span class="BOLD">
APPLE Foods, Constants
</span>
<tr>
<td>
<td colspan="4" align="LEFT"><span class="BOLD">
</span>
<tr>
<td>
<td colspan="4" align="LEFT">We service:<span class="BOLD">
All occasions and hospitality services
</span>
<tr>
<td>
<td colspan="4" align="LEFT">We sell :<span class="BOLD">
----
</span>
</td></td></tr></td></td></tr></td></td></tr></td></td></tr></td></td></tr></td></td></tr></td></td></td></td></tr></td></td></td></td></tr></td></td></td></td></td>
How do I extract the address 120 NW 157TH AVE from this ?
When I tried using
node.SelectSingleNode(".//td[#class='BOLD'][4]/preceding-sibling::td").InnerText;
I get an error:
Object reference not set to an instance of an object
Your html is a mess tags are overlapping i suggest you use text nodes as your identifiers rather than indices for example
.//td[./a[contains(text(),'See on Map')]]/td/text()
to get
120 NW 157TH AVE
Here is a full example that gets you everything
var table = doc.DocumentNode.SelectSingleNode("//table[contains(#class,'DataRows')]");
var name = table.SelectSingleNode(".//td[#class='BOLD']/text()").InnerText.Trim();
var fax = table.SelectSingleNode(".//td[contains(text(),'Fax')]/td/text()").InnerText.Trim();
var email = table.SelectSingleNode(".//span[contains(text(),'E-mail')]/following-sibling::text()").InnerText.Trim();
var address = table.SelectSingleNode(".//td[./a[contains(text(),'See on Map')]]/td/text()").InnerText.Trim();
var city = table.SelectSingleNode(".//tr[./td/a[contains(text(),'See on Map')]]//tr/td/td/span").InnerText.Trim(',');
var zip = table.SelectSingleNode(".//tr[./td/a[contains(text(),'See on Map')]]//tr/td/td/span/following-sibling::text()").InnerText.Trim();
Note because of how messy your html is the xpaths has to be as messy, trying to access the tr element by index won't work because all tr elements are children of the previous tr, what is .//tr[4] in a normal table is .//tr/tr/tr/tr in your table.
Related
After taking a whole weekend on google and here, without success, I ask for help.
I have this html table:
<TABLE id=tabella width="100%" border=1>
<TBODY>
<TR>
<TD class=ListTitle width=55></TD>
<TD class=ListTitle width=55>Data</TD>
<TD class=ListTitle width=45>Paziente</TD>
<TD class=ListTitle width=150>Prestazioni</TD>
<TD class=ListTitle width=41>Stato</TD>
<TD class=ListTitle width=41>Sede</TD>
<TD class=ListTitle width=70>Unità</TD>
<TD class=ListTitle width=100>Specialista</TD>
<TD class=ListTitle width=41>Contatto (codice,data, n.impegnat.)</TD>
<TD class=ListTitle width=15>Stato pag.</TD>
<TD class=ListTitle width=20></TD>
<TD class=ListTitle width=20></TD>
<TD class=ListTitle width=20></TD>
</TR>
<!-- riga sotto: "title" sostituisce "name" (compatibilità browser) STP 08/05/13 -->
<TR id=riga_0 title=201503548353>
<TD class=ListElement>
<INPUT onclick=selectPatientName(this);abilitaCambiaStato() type=checkbox value="PALMA ROCCO" name=patientSelect>
</TD>
<TD class=ListElement style="FONT-SIZE: 12px">
<CENTER>Giovedi
<BR>03/12/2015
<BR>10:45</CENTER>
</TD>
<TD class=ListElement style="FONT-SIZE: 11px">
<B>xxxxx xxxx</B>
<BR>[xxxxxxxx, 25/05/1965, tel.0000000000]</TD>
<TD class=ListElement style="FONT-SIZE: 12px">RM COLONNA LOMBOSACRALE</TD>
<TD class=ListElement style="FONT-SIZE: 12px">
<CENTER>Eseguito</CENTER>
</TD>
<TD class=ListElement style="FONT-SIZE: 12px">11 - xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</TD>
<TD class=ListElement style="FONT-SIZE: 12px">xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx </TD>
<TD class=ListElement style="FONT-SIZE: 12px">EQUIPE</TD>
<TD class=ListElement style="FONT-SIZE: 12px">
<CENTER>PB14310408
<BR>09/11/2015
<BR>16015-44444444</CENTER>
</TD>
<TD class=ListElement style="FONT-SIZE: 12px">niente</TD>
<TD class=ListElement>
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD>
<IMG onclick=void(0) title="Appuntamento prenotato" class=button style="CURSOR: pointer" alt="Appuntamento prenotato" src="Images/app_noconfBW.gif">
</TD>
</TR>
<TR>
<TD class=Button></TD>
</TR>
</TBODY>
</TABLE>
<BR>
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD>
<IMG onclick="doAppointmentChangeStatus('201503548353')" title="Cambia stato appuntamento" class=button style="CURSOR: pointer" alt="Cambia stato appuntamento" src="Images/app_status.gif">
</TD>
</TR>
<TR>
<TD class=Button></TD>
</TR>
</TBODY>
</TABLE>
<BR>
<IMG alt="" src="Images/empty.gif"> </TD>
<TD class=ListElement>
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD>
<IMG onclick=void(0) title="Appuntamento non revocabile" class=button style="CURSOR: pointer" alt="Appuntamento non revocabile" src="Images/iconDeleteBW.gif">
</TD>
</TR>
<TR>
<TD class=Button></TD>
</TR>
</TBODY>
</TABLE>
<BR>
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD>
<IMG onclick=void(0) title="Appuntamento non spostabile" class=button style="CURSOR: pointer" alt="Appuntamento non spostabile" src="Images/iconRightArrow_BW.gif">
</TD>
</TR>
<TR>
<TD class=Button></TD>
</TR>
</TBODY>
</TABLE>
<BR>
<IMG alt="" src="Images/empty.gif"> </TD>
<TD class=ListElement>
<!-- ....LER, 07/06/12 -->
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD>
<IMG onclick="doAppointmentDetails('201503548353')" title="Dettagli appuntamento" class=button style="CURSOR: pointer" alt="Dettagli appuntamento" src="Images/iconDetails.gif">
</TD>
</TR>
<TR>
<TD class=Button></TD>
</TR>
</TBODY>
</TABLE>
<BR>
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD>
<IMG onclick="doModificaRichiesta('201503548353')" title="Modifica Richiesta" class=button style="CURSOR: pointer" alt="Modifica Richiesta" src="Images/ModificaRichiesta.gif">
</TD>
</TR>
<TR>
<TD class=Button></TD>
</TR>
</TBODY>
</TABLE>
<BR>
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD>
<IMG onclick="doPagaRichiesta('PB14310408')" title="Effettua pagamento" class=button style="CURSOR: pointer" alt="Effettua pagamento" src="Images/fCash2.gif">
</TD>
</TR>
<TR>
<TD class=Button></TD>
</TR>
</TBODY>
</TABLE>
</TD>
</TR>
<TD class=ListElement>
<INPUT onclick=selectPatientName(this);abilitaCambiaStato() type=checkbox value="PAIANO ADDOLORATA" name=patientSelect>
</TD>
<TD class=ListElement style="FONT-SIZE: 12px">
<CENTER>Giovedi
<BR>03/12/2015
<BR>11:00</CENTER>
</TD>
<TD class=ListElement style="FONT-SIZE: 11px">
<B>PAIANO ADDOLORATA</B>
<BR>[MAGLIE, 21/03/1956, tel.0836210592]</TD>
<TD class=ListElement style="FONT-SIZE: 12px">RM COLONNA LOMBOSACRALE</TD>
<TD class=ListElement style="FONT-SIZE: 12px">
<CENTER>Eseguito</CENTER>
</TD>
<TD class=ListElement style="FONT-SIZE: 12px">11 - Istituto Santa Chiara - Castrignano dei Greci</TD>
<TD class=ListElement style="FONT-SIZE: 12px">Istituto S. Chiara RMN - Castrignano de' Greci </TD>
<TD class=ListElement style="FONT-SIZE: 12px">EQUIPE</TD>
<TD class=ListElement style="FONT-SIZE: 12px">
<CENTER>PB14108241
<BR>28/09/2015
<BR>16015-0371711463</CENTER>
</TD>
<TD class=ListElement style="FONT-SIZE: 12px">niente</TD>
<TD class=ListElement>
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD>
<IMG onclick=void(0) title="Appuntamento prenotato" class=button style="CURSOR: pointer" alt="Appuntamento prenotato" src="Images/app_noconfBW.gif">
</TD>
</TR>
<TR>
<TD class=Button></TD>
</TR>
</TBODY>
</TABLE>
<BR>
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD>
<IMG onclick="doAppointmentChangeStatus('201503040650')" title="Cambia stato appuntamento" class=button style="CURSOR: pointer" alt="Cambia stato appuntamento" src="Images/app_status.gif">
</TD>
</TR>
<TR>
<TD class=Button></TD>
</TR>
</TBODY>
</TABLE>
<BR>
<IMG alt="" src="Images/empty.gif"> </TD>
<TD class=ListElement>
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD>
<IMG onclick=void(0) title="Appuntamento non revocabile" class=button style="CURSOR: pointer" alt="Appuntamento non revocabile" src="Images/iconDeleteBW.gif">
</TD>
</TR>
<TR>
<TD class=Button></TD>
</TR>
</TBODY>
</TABLE>
<BR>
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD>
<IMG onclick=void(0) title="Appuntamento non spostabile" class=button style="CURSOR: pointer" alt="Appuntamento non spostabile" src="Images/iconRightArrow_BW.gif">
</TD>
</TR>
<TR>
<TD class=Button></TD>
</TR>
</TBODY>
</TABLE>
<BR>
<IMG alt="" src="Images/empty.gif"> </TD>
<!-- LER, 07/06/12...faccio diventare la colonna di tipo List element per poter aggiungere altro pulsante -->
<TD class=ListElement>
<!-- ....LER, 07/06/12 -->
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD>
<IMG onclick="doAppointmentDetails('201503040650')" title="Dettagli appuntamento" class=button style="CURSOR: pointer" alt="Dettagli appuntamento" src="Images/iconDetails.gif">
</TD>
</TR>
<TR>
<TD class=Button></TD>
</TR>
</TBODY>
</TABLE>
<BR>
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD>
<IMG onclick="doModificaRichiesta('201503040650')" title="Modifica Richiesta" class=button style="CURSOR: pointer" alt="Modifica Richiesta" src="Images/ModificaRichiesta.gif">
</TD>
</TR>
<TR>
<TD class=Button></TD>
</TR>
</TBODY>
</TABLE>
<BR>
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD>
<IMG onclick="doPagaRichiesta('PB14108241')" title="Effettua pagamento" class=button style="CURSOR: pointer" alt="Effettua pagamento" src="Images/fCash2.gif">
</TD>
</TR>
<TR>
<TD class=Button></TD>
</TR>
</TBODY>
</TABLE>
</TD>
</TR>
<!-- riga sotto: "title" sostituisce "name" (compatibilità browser) STP 08/05/13 -->
<TR>
<TD class=Button></TD>
</TR>
</TBODY>
</TABLE>
</TD>
</TR>
</TBODY>
</TABLE>
And want extract the data nodes.
Most pepole use HtmlAgilityPack and i tried this:
HtmlAgilityPack.HtmlNodeCollection aNodi = doc.DocumentNode.SelectNodes("//table[#id=tabella]/tbody/tr");
Also have tested most parameters in SelectNodes, but return always NULL!
What am i doing wrong?
Thank you all for the help!
If you want to select it by id in SelectNodes you have to wrap tabella in apostrophes:
var aNodi = doc.DocumentNode.SelectNodes("//table[#id='tabella']//tbody//tr");
You could also use GetElementbyId:
var aNodi = doc.GetElementbyId("tabella").SelectNodes("//tbody//tr");
Net c# website i have an html report is there.Now i want to take a printout of the same.So i used Javascript and its showing only the popup box ,not the content.how to solve this issue.
Javascript
<script type="text/javascript">
function PrintDiv() {
var divToPrint = document.getElementById('widget-content');
var popupWin = window.open('', '_blank', 'width=300,height=400,location=no,left=200px');
popupWin.document.open();
popupWin.document.write('<html><body onload="window.print()">' + divToPrint.innerHTML + '</html>');
popupWin.document.close();
}
</script>
button Click
<input type="button" onclick="PrintDiv()" value="Print" />
HTML Content
<div class="widget-content">
<div class="invoice-content">
<div class="invoice-head">
<div class="invoice-meta">
<%--Invoice <span class="invoice-number">#96558 </span><span class="invoice-date">Date:
2012-07-15</span>--%>
</div>
<h5 style="margin-left: 40%; height: 20px; font-size: large">
Order Form</h5>
<div class="invoice-to">
<ul>
<li><span>Booking Date:<asp:Label ID="dispbookingDate" runat="server"></asp:Label></span>
<span>Name<asp:Label TextMode="MultiLine" runat="server" ID="dispName"></asp:Label></span>
<span>Address:<asp:Label TextMode="MultiLine" runat="server" ID="dispAddress"></asp:Label></span>
</li>
</ul>
</div>
<div class="invoice-from">
<ul>
<li><span>Order No.<asp:Label ID="dispOrderNo" runat="server"></asp:Label></span> <span>
Wedding Date:<asp:Label runat="server" ID="dispWeddingDate"></asp:Label></span>
<span>Malayalam Date:<asp:Label runat="server" ID="dispWeddingMalayam"></asp:Label></span>
</li>
</ul>
</div>
</div>
<div>
<table class="table table-bordered table-striped table-hover">
<thead>
<tr>
<th class="style1">
Description
</th>
<th class="style2">
Rs.
</th>
<th>
Ps.
</th>
</tr>
</thead>
<tfoot>
<tr>
<th class="total-label" colspan="2">
Total:
</th>
<th class="total-amount">
<asp:Label ID="dispTotal" runat="server"></asp:Label>
</th>
</tr>
<tr>
<th class="total-label" colspan="2">
Adavance:
</th>
<th class="total-amount">
<asp:Label ID="dispAvance" runat="server"></asp:Label>
</th>
</tr>
<tr>
<th class="total-label" colspan="2">
Balance:
</th>
<th class="total-amount">
<asp:Label ID="dispBalance" runat="server"></asp:Label>
</th>
</tr>
</tfoot>
<tbody>
<tr>
<td class="style1">
Auditorium Rent
</td>
<td class="style2">
<asp:Label ID="dispRent" runat="server"></asp:Label>
</td>
<td>
<asp:Label ID="Label2" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td class="style1">
Dining Hall Rent
</td>
<td class="style2">
</td>
<td>
</td>
</tr>
<tr>
<td class="style1">
Kathir Mandapam
</td>
<td class="style2">
</td>
<td>
</td>
</tr>
<tr>
<td class="style1">
Tables and chairs
</td>
<td class="style2">
</td>
<td>
</td>
</tr>
<tr>
<td class="style1">
Electricity charge for water
</td>
<td class="style2">
</td>
<td>
</td>
</tr>
<tr>
<td class="style1">
Luxuary Tax
</td>
<td class="style2">
<asp:Label ID="dispLTax" runat="server"></asp:Label>
</td>
<td>
</td>
</tr>
<tr>
<td class="style1">
Central Service Tax
</td>
<td class="style2">
<asp:Label ID="dispCTax" runat="server"></asp:Label>
</td>
<td>
</td>
</tr>
</tbody>
</table>
</div>
<%-- <p class="amount-word">
Amount in Word: <span>
<asp:Label ID="dispAmountWord" runat="server"></asp:Label></span>
</p>--%>
</div>
<input type="button" onclick="PrintDiv()" value="Print" />
</div>
In your javascript you are searching for the div with id widget-content
your code: var divToPrint = document.getElementById('widget-content');
but in your html you have <div class="widget-content"> and it has no id, it only has a class.
So you have 2 options.
OPTION 1
Change class to id
OPTION 2
Change your javascript to search for the class like so
var divToPrint = document.getElementsByClassName('widget-content')
NOTE: this will return an array of elements with that class, whether theres only one or more.
So in order to select the one you want; assuming there is only 1 div with this class you do like so:
var divToPrint = document.getElementsByClassName('widget-content')[0]
I'm trying to manipulate a html table open in webbrowser control, this tool will be used ti access a sharepoint page with an autologin option. This far this is what i have:
HtmlElementCollection htmlcol =
wb.Document.GetElementsByTagName("formTextfield277");
for (int i = 0; i < htmlcol.Count; i++)
{
if (htmlcol[i].Name == "portal_id")
{
htmlcol[i].SetAttribute("VALUE",
Properties.Settings.Default.sharepoint_user);
}
else if (htmlcol[i].Name == "password")
{
htmlcol[i].SetAttribute("VALUE",
Properties.Settings.Default.sharepoint_pw);
}
}
This C# code if for manipulate this HTML page:
<TABLE CELLSPACING="0" CELLPADDING="0" WIDTH="100%" BORDER="0">
<TR>
<TD CLASS="txtRedBold10" WIDTH="4"> </TD>
<TD CLASS="txtRedBold10" COLSPAN="2" HEIGHT="30">Please log in</TD>
</TR>
<TR>
<TD CLASS="txtBlackReg10" WIDTH="4"> </TD>
<TD CLASS="txtBlackReg10">Username:</TD>
<TD><INPUT CLASS="formTextfield277" TYPE="text" NAME="portal_id" VALUE="" VCARD_NAME="vCard.Email" SIZE="28"></TD>
</TR>
<TR>
<TD CLASS="txtBlackReg10" COLSPAN="3"> </TD>
</TR>
<TR>
<TD CLASS="txtBlackReg10" COLSPAN="2"> </TD>
<TD CLASS="txtBlackReg10">Please enter your username or E-Mail Address</TD>
</TR>
<TR>
<TD CLASS="txtBlackReg10" COLSPAN="3"> </TD>
</TR>
<TR>
<TD CLASS="txtBlackReg10" WIDTH="4"> </TD>
<TD CLASS="txtBlackReg10">Password:</TD>
<TD><INPUT CLASS="formTextfield277" TYPE="password" NAME="password" SIZE="28" AUTOCOMPLETE="off"></TD>
</TR>
<TR>
<TD CLASS="txtBlackReg10" COLSPAN="3"> </TD>
</TR>
<TR>
<TD CLASS="txtBlackReg10" COLSPAN="2"> </TD>
<TD CLASS="txtBlackReg10">Please enter your network or Intranet password</TD>
</TR>
<TR>
<TD CLASS="txtBlackReg10" COLSPAN="3"> </TD>
</TR>
<TR>
<TD CLASS="txtBlackReg10" COLSPAN="2"> </TD>
<TD CLASS="txtBlackReg10">
<TABLE CELLSPACING="0" CELLPADDING="0" BORDER="0">
<TR>
<TD><INPUT TYPE="image" HEIGHT="24" WIDTH="20" SRC="images/cp_arrow.gif" VALUE="Log In"
BORDER="0"></TD>
<TD><A CLASS="linkTxtRedBold10" HREF="javascript:signin()"
onClick="saveForm()">Login</A>
</TD>
</TR>
</TABLE>
</TD>
</TR>
<TR>
<TD CLASS="txtBlackReg10" COLSPAN="3"> </TD>
</TR>
</TABLE>
Any sugestions?
Thanks in advance!
wb.Document.GetElementsByTagName("input") not wb.Document.GetElementsByTagName("formTextfield277");
HtmlElementCollection inputHtmlCollection = Document.GetElementsByTagName("input");
foreach (HtmlElement anInputElement in inputHtmlCollection)
{
if (anInputElement.Name.Equals("portal_id"))
{
anInputElement.SetAttribute("VALUE", Properties.Settings.Default.sharepoint_user);
}
if (anInputElement.Name.Equals("password"))
{
anInputElement.SetAttribute("VALUE", roperties.Settings.Default.sharepoint_pw);
}
}
hope this help!
In my program user will select template message and it will show up in the body textbox. The template is in HTML Format.
if(templatelistbox.SelectedItem.ToString().Equals("Order Processing"))
{
string m;
i want to store the below html to string.
<body>
<table width="580" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
<tbody>
<tr>
<td colspan="2" align="right" valign="middle" width="580" height="60" bgcolor="00496f"><div wotsearchtarget="flipkart.com"></div></td>
</tr>
<tr>
<td colspan="2" align="left" valign="middle" width="580" bgcolor="3bb1d7"><p><strong>Order Confirmed!</strong></p></td>
</tr>
<tr>
<td colspan="2" align="left" valign="top" width="580" bgcolor="ffffff"><p> </p>
<p>Dear <strong>Praveen,</strong></p>
<p>Greetings from Prostyle PC Kart</p>
<p>We thank you for your order. This email contains your order summary. When the item(s) in your order are ready to ship, you will receive an email with the Courier Tracking ID and the link where you can track your order. You can also check the status of your order on <strong>ebay.in</strong></p>
Please find below the summary of your order <strong> OD3</strong></a>
at Prostyle Pc Kart Seller of eBay.in:
</p></td>
</tr>
<tr>
<td colspan="2" align="left" valign="top" width="580" bgcolor="ffffff"><table border="0" cellspacing="0" cellpadding="0" width="580">
<tbody>
<tr>
<td colspan="7"><p><strong>Order ID: OD3
| Seller ID : eshop.prostylepc.in</strong></p>
<p> <strong>Item (s) Ordered:</strong></p></td>
</tr>
<tr>
<td width="274" valign="top"><p><strong>Product Details</strong></p></td>
<td width="112" valign="top"><p><strong>Shipping Date</strong></p></td>
<td width="62" valign="top"><p><strong>Ordered Quantity</strong></p></td>
<td width="132" valign="top"><p><center><strong>Price</strong></center></p></td>
</tr>
<tr>
<td width="274" valign="top"><p>XOLO Q800</p>
</td>
<td width="112" valign="top"><p> </p></td>
<td width="62" valign="top"><center><p>1</p></center></td>
<td width="132" valign="top" align="center"><p>Rs. 9700</p></td>
<tr>
<td width="274" valign="top"><p>Samsung BHM1100NBEGINU In-the-ear Headset without Charger</p>
</td>
<td width="112" valign="top"><p> </p></td>
<td width="62" valign="top"><center><p>1</p></center></td>
<td width="132" valign="top" align="center"><p>Rs. 699</p></td>
</tr>
<tr>
<td colspan="2"><p>Shipping Charge</p></td>
<td width="62"><center><p>FREE</p></center></td>
</tr>
<tr>
<td valign="top" colspan="3"><p><strong>Total</strong></p></td>
<td width="132" valign="top"><p><strong>Rs. 9700</strong></p></td>
</tr>
<tr>
.......................................................
bodytbox.Text = m;
}
Tell me any way to insert this html code in c# or variable or how to send this template via a email.(Alternative)
I alos need to put some parameter in the template.For Eg OrderNo.xxxxxx replaced with pid(static contain some value).
Thanks In advance
save it to file and load that file to string , or in the application setting ( project -> properties -> setting )
string htmlCode = System.IO.File.ReadAllText("File Path");
with application setting :
string htmlCode = properties.Default.HtmlCode;
after that you can do what ever you want that.
you can use Template parser
Codeplex library and Documentation
I have a HTML document of the structure
<table width="85%" border="1" height="315" align="center">
<tr>
<td colspan="2" align="center"><font color="#400040"><b>Register No</b></font></td>
<th colspan="2"><font color="Brown">42209104069</font></th>
<td colspan="2" align="center"><font color="#400040"><b>Name</b></font></td>
<th colspan="2"><font color="Brown">SATHISH KUMAR R</font></th>
</tr>
<tr>
<td colspan="2"><font color="blue"><center><b>Subject</b></font></td>
<td colspan="2"><font color="blue"><center><b>Credits</b></font></td>
<td colspan="2"><font color="blue"><center><b>Grade</b></font></td>
<td colspan="2"><font color="blue"><center><b>Result</b></font></td>
</tr>
<tr>
<td colspan="2"><center> CS2301</td> //1
<td colspan="2"><center> 3</td> //2
<td colspan="2"><center> E</td> //3
<td colspan="2"><center> PASS</td> //4
</tr>
</table>
I want to extract the contents of the tag of lines 1,2,3,4 and save to a string. I want to know how to achieve this using Majestic13 in my C# project.
PM> Install-Package Majestic13
var html=#"<table width="85%" border="1" height="315" align="center">
<tr>
<td colspan="2" align="center"><font color="#400040"><b>Register No</b></font></td>
<th colspan="2"><font color="Brown">42209104069</font></th>
<td colspan="2" align="center"><font color="#400040"><b>Name</b></font></td>
<th colspan="2"><font color="Brown">SATHISH KUMAR R</font></th>
</tr>
<tr>
<td colspan="2"><font color="blue"><center><b>Subject</b></font></td>
<td colspan="2"><font color="blue"><center><b>Credits</b></font></td>
<td colspan="2"><font color="blue"><center><b>Grade</b></font></td>
<td colspan="2"><font color="blue"><center><b>Result</b></font></td>
</tr>
<tr>
<td colspan="2" class="a"><center> CS2301</td> //1
<td colspan="2" class="a"><center> 3</td> //2
<td colspan="2" class="a"><center> E</td> //3
<td colspan="2" class="a"><center> PASS</td> //4
</tr>
</table>";
var paser = new HtmlParser();
var node = paser.Pasrse(html);
var finder = new FindTagsVisitor(TagBuilder => tag.Name == "td" && tag.Attributes.ContainsKey("class"));
node.AcceptVisitor(finder);