xpath query to parse html page - html

I have an html file that looks like
<HTML>
<BODY>
<TABLE width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="400" align="right" valign="top" class="text_rail_left"></td>
<td width="100%" align="left" valign="top" class="text_back_color"><table border="0" cellPadding="0" cellSpacing="0" width="100%"><tr>
</tr><tr>
<td width="100%" align="left" align="top"><table width="100%" border="0" cellspacing="2" cellpadding="0">
<tr>
<td align="center" valign="top" class="inside_heading_text">Train Names with Details</td>
</tr> <tr>
<td><b><BR><BR> SORRY !!! No Matching buses Found</b></td></tr>
<tr><td>
</td></tr></table>
<td align="left" valign="top" class="pad_self"><table width="100%" border="0" cellspacing="2" cellpadding="2">
<tr><td align="right" valign="top"> </td>
</tr></table></td>
</tr></table></td>
<td align="left" valign="top" class="text_rail_right"> </td>
</tr>
<tr>
<td width="10" align="left" valign="top"><img src="http://www.indianrail.gov.in/main_text_left_bottom2.gif" alt="" width="8"/></td>
<td width="100%" align="left" valign="top" class="text_rail_bottom"><img src="http://www.indianrail.gov.in/blank.gif" alt="" width="1" height="8" /></td>
<td width="10" align="right" valign="top"> <img src="http://www.indianrail.gov.in/main_text_right_bottom2.gif" alt="" width="8" /></td>
</tr></table><body>
<FONT size=1>No. of Queries : 0839425885
, Server : YAMUNA
, Dated : 15-05-2014 Time:07:15:26 Hrs</font></td></tr></table></td></tr> </table></td></tr></table></td></tr></table></td></tr><tr><td align="left"valign="top"><table width="970" border="0" cellspacing="0" cellpadding="0"><tr> <td width="9" align="left" valign="top"><img src="http://www.indianrail.gov.in/images/footer_upper_lft.gif" alt="" width="9" height="49" /></td><td width="100%%" align="left" valign="top" class="footer_upper"><table width="100%%" border="0" cellspacing="1" cellpadding="0"><tr><td align="center" valign="top" class="main_footer_upper">Home | Ministry of Railways | Trains between Stations | Booking Locations | CRIS | CONCERT | Advertise with CRIS | Railway Map | FAQ | Sitemap | Feedback</td></tr><tr><td align="center"valign="top" class="copy_footer" style="padding-top:3px;"><span class="main_footer_copy">Copyright</span> © 2010, Centre For Railway Information Systems, Designed and Hosted by CRIS | <span class="main_footer_copy">Disclaimer</span><br />Best viewed at 1024 x 768 resolution with Internet Explorer 5.0 or Mozila Firefox 3.5 and higher</td></tr> </table></td><td width="9" align="right" valign="top"><img src="http://www.indianrail.gov.in/images/footer_upper_rgt.gif" alt="" width="9" height="49" /></td></tr></table></td></tr></table></td></tr></table><script type="text/javascript">anylinkmenu.init("menuanchorclass")</script>
</BODY>
</HTML>
I want to write an xpath query to read the string
SORRY !!! No Matching buses Found
There's no unique class that identifies the class with the string. I tried the xpath query
#"//td[#class='inside_heading_text']/tr"
but it doesnt seem to work.
Can someone point me in the right direction? I'm using the ONO library in Objective-C to parse the html.

Well, this would get you the container of the "SORRY" text
//*[contains(text(),'SORRY')]
I recommend firefinder extension for firebug (on firefox) for an easy way to try xpaths.

That's some ugly HTML you got there.
There are unclosed elements, repeated td/#align attributes, etc. You're going to have to clean it up first if you want to use XPath.
If you can manually or automatically clean it up at least to this point:
<?xml version="1.0" encoding="utf-8"?>
<HTML>
<BODY>
<TABLE width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="400" align="right" valign="top" class="text_rail_left">
</td>
<td width="100%" align="left" valign="top" class="text_back_color">
<table border="0" cellPadding="0" cellSpacing="0" width="100%">
<tr>
</tr>
<tr>
<td width="100%" align="left">
<table width="100%" border="0" cellspacing="2" cellpadding="0">
<tr>
<td align="center" valign="top" class="inside_heading_text">Train Names with Details</td>
</tr>
<tr>
<td>
<b>
<BR/>
<BR/> SORRY !!! No Matching buses Found</b>
</td>
</tr>
<tr>
<td>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
<td align="left" valign="top" class="text_rail_right"></td>
</tr>
</TABLE>
</BODY>
</HTML>
Then this XPath will select the "SORRY..." text given the inside_heading_text point of reference that you mention:
//td[#class='inside_heading_text']/../following-sibling::tr[1]/td[1]/b

Related

Why table boxes are not rendering in a row in Outlook?

I am creating a responsive email template for that I need 6 Books in a row.
The width of main table is 600px, books table width is 15% and red highlighted table (for space between tables) width is 2%. All tables are left aligned.
Email is working fine in browser but not rendering in properly in Outlook here is screenshot below.
There is 1px space around the red table, please suggest a fix so it renders in a row & works fine in outlook 2016 and also in other version.
Outlook 2016 Example
Note: I tried using single table with 6 <td> but it wasn't working in Andorid 4.4, so that is why I am using this table structure.
/* MOBILE STYLES */
#media screen and (max-width: 520px) {
/* FULL-WIDTH TABLES */
table[class="responsive-table"] {
width: 100%!important;
}
}
<table border="0" cellpadding="0" cellspacing="0" width="600" class="responsive-table" align="center" bgcolor="yellow">
<tr>
<td>
<!-- TWO COLUMNS -->
<table cellspacing="0" cellpadding="0" border="0" width="100%">
<tr>
<td valign="top" style="padding: 0;">
<table cellpadding="0" cellspacing="0" border="0" width="15%" align="left" class="responsive-table">
<tr>
<td align="center"><img src="http://placehold.jp/85x120.png" alt="" width="85" border="0"></td>
</tr>
</table>
<table width="2%" height="10" border="0" align="left" cellpadding="0" cellspacing="0" bgcolor="red" class="responsive-table">
<tr>
<td> </td>
</tr>
</table>
<table cellpadding="0" cellspacing="0" border="0" width="15%" align="left" class="responsive-table">
<tr>
<td align="center"><img src="http://placehold.jp/85x120.png" alt="" width="85" border="0"></td>
</tr>
</table>
<table width="2%" height="10" border="0" align="left" cellpadding="0" cellspacing="0" bgcolor="red" class="responsive-table">
<tr>
<td> </td>
</tr>
</table>
<table cellpadding="0" cellspacing="0" border="0" width="15%" align="left" class="responsive-table">
<tr>
<td align="center"><img src="http://placehold.jp/85x120.png" alt="" width="85" border="0"></td>
</tr>
</table>
<table width="2%" height="10" border="0" align="left" cellpadding="0" cellspacing="0" bgcolor="red" class="responsive-table">
<tr>
<td> </td>
</tr>
</table>
<table cellpadding="0" cellspacing="0" border="0" width="15%" align="left" class="responsive-table">
<tr>
<td align="center"><img src="http://placehold.jp/85x120.png" alt="" width="85" border="0"></td>
</tr>
</table>
<table width="2%" height="10" border="0" align="left" cellpadding="0" cellspacing="0" bgcolor="red" class="responsive-table">
<tr>
<td> </td>
</tr>
</table>
<table cellpadding="0" cellspacing="0" border="0" width="15%" align="left" class="responsive-table">
<tr>
<td align="center"><img src="http://placehold.jp/85x120.png" alt="" width="85" border="0"></td>
</tr>
</table>
<table width="2%" height="10" border="0" align="left" cellpadding="0" cellspacing="0" bgcolor="red" class="responsive-table">
<tr>
<td> </td>
</tr>
</table>
<table cellpadding="0" cellspacing="0" border="0" width="15%" align="left" class="responsive-table">
<tr>
<td align="center"><img src="http://placehold.jp/85x120.png" alt="" width="85" border="0"></td>
</tr>
</table>
<!-- RIGHT COLUMN -->
</td>
</tr>
</table>
</td>
</tr>
</table>
You can try the following code for table, I suggest you, not to use multiple tables inside a table, instead use TD.
It may resolve your issue.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
#media screen and (max-width: 520px) {
/* FULL-WIDTH TABLES */
table[class="responsive-table"] {
width: 100%!important;
}
}
</style>
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="600" class="responsive-table" align="center" bgcolor="yellow">
<tr>
<td>
<!-- TWO COLUMNS -->
<table cellspacing="0" cellpadding="0" border="0" width="100%">
<tr>
<td width="15%">
<img src="http://placehold.jp/85x120.png" alt="" width="100%" border="0">
</td>
<td width="2%" bgcolor="red"></td>
<td width="15%">
<img src="http://placehold.jp/85x120.png" alt="" width="100%" border="0">
</td>
<td width="2%" bgcolor="red"></td>
<td width="15%">
<img src="http://placehold.jp/85x120.png" alt="" width="100%" border="0">
</td>
<td width="2%" bgcolor="red"></td>
<td width="15%">
<img src="http://placehold.jp/85x120.png" alt="" width="100%" border="0">
</td>
<td width="2%" bgcolor="red"></td>
<td width="15%">
<img src="http://placehold.jp/85x120.png" alt="" width="100%" border="0">
</td>
<td width="2%" bgcolor="red"></td>
<td width="15%">
<img src="http://placehold.jp/85x120.png" alt="" width="100%" border="0">
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
Snapshot 1
Snapshot 2
Snapshot 3

Block of code with no spacing or indentation

I have received a html block of code (email template so lots of tables) that I have to work with that has no spacing or indentation aand is essentially all on one line. It's a nightmare to try and edit it.
Does anyone know of any online tools or applications that you can copy and paste code into where it organises it for you?
olor="#e5e5e5" alink="#000000" class="yfix" leftmargin="0" rightmargin="0" topmargin="0"> <!--//--> <table width="100%" cellspacing="0" cellpadding="0" border="0"> <tr> <td width="100%" valign="top" bgcolor="#e5e5e5" align="center"> <table width="698" cellspacing="0" cellpadding="0" border="0"> <tr> <td width="5"><img hspace="0" height="1" width="5" src="http://info.page7media.ie/img/trans.gif" /></td> <td align="left"> <table width="688" cellspacing="0" cellpadding="0" border="0"> <tr> <td height="10"><a name="top_of_mail"></a></td> </tr> <tr> <td align="center"><font face="Arial, Helvetica, sans-serif" size="2" color="red" style="font-size: 12px; line-height: 17px;">If you are unable to see this message, click <a target="_blank" href="http://info.page7media.ie/u/gm.php?UID=JJ20yz3nz2&ID=279438389_478447_36061" style="text-decoration: underline;"><font face="Arial, Helvetica, sans-seri
Try Dirty Markup, it cleaned this markup up nicely
http://www.dirtymarkup.com/
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
olor="#e5e5e5" alink="#000000" class="yfix" leftmargin="0" rightmargin="0"
topmargin="0"> <!--//-->
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="center" style="background-color: #E5E5E5" valign="top"
width="100%">
<table border="0" cellpadding="0" cellspacing="0" width="698">
<tr>
<td width="5"><img height="1" hspace="0" src=
"http://info.page7media.ie/img/trans.gif" width=
"5"></td>
<td align="left">
<table border="0" cellpadding="0" cellspacing="0"
width="688">
<tr>
<td height="10">
<a id="top_of_mail" name=
"top_of_mail"></a>
</td>
</tr>
<tr>
<td align="center">
If you are unable to see this message,
click <a href=
"http://info.page7media.ie/u/gm.php?UID=JJ20yz3nz2&ID=279438389_478447_36061"
style="text-decoration: underline;"
target="_blank"></a>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
You're looking for something called a "beautifier".
Here's an online beautifier that supports HTML: http://ctrlq.org/beautifier/
I beautified it for you but noticed the beginning of your code sample is missing.
olor="#e5e5e5" alink="#000000" class="yfix" leftmargin="0" rightmargin="0" topmargin="0">
<!--//-->
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
<td width="100%" valign="top" bgcolor="#e5e5e5" align="center">
<table width="698" cellspacing="0" cellpadding="0" border="0">
<tr>
<td width="5">
<img hspace="0" height="1" width="5" src="http://info.page7media.ie/img/trans.gif" />
</td>
<td align="left">
<table width="688" cellspacing="0" cellpadding="0" border="0">
<tr>
<td height="10">
<a name="top_of_mail">
</a>
</td>
</tr>
<tr>
<td align="center">
<font face="Arial, Helvetica, sans-serif" size="2" color="red" style="font-size: 12px; line-height: 17px;">
If you are unable to see this message, click
<a target="_blank" href="http://info.page7media.ie/u/gm.php?UID=JJ20yz3nz2&ID=279438389_478447_36061" style="text-decoration: underline;">
<font face="Arial, Helvetica, sans-seri
Use an online code formatter.
http://ctrlq.org/beautifier/
I grabbed the first one that looked interesting. There are others out there.
http://bit.ly/1Eqgeqr

Lotus Notes HTML and Tables: How can I make this work

I am trying to create a newsletter style HTML email for users who are using IBM Lotus Notes 9.0.1.
I get closed, but can't exactly get it right.
Here is my code:
<html>
<head>
<title>Scoular Weekly Technology Newsletter</title>
</head>
<script>
</script>
<body bgcolor="#E0DED8" style="padding-top:30px;" height="1000px">
<table bgcolor="#FFFFFF" align="center" width="800px" cellspacing="0" border="0" cellpadding="0">
<tr>
<td>
<table cellspacing="20" cellpadding="20" border="0" width="640" align="center">
<tr width="650px">
<td bgcolor="#D7D3C7" style="padding:10px" align="center"><img alt="Scoular_HTML2" height="93" width="400px" src="" style="padding:20px"></td>
</tr>
</table>
<table cellspacing="20" cellpadding="20" border="0" width="640" align="center">
<tr width="650px">
<td bgcolor="#D7D3C7" style="padding:10px" align="left">
<span> Weekly Technology Tips</span>
<td bgcolor="#D7D3C7" style="padding:10px" align="right">
<span>IT Help Desk</span</td>
</td>
</tr>
</table>
<table cellspacing="20" cellpadding="20" border="0" width="640" align="center">
<tr width="650px">
<td bgcolor="#D7D3C7" style="padding:10px" align="center">TIP</td>
</tr>
</table>
<table cellspacing="20" cellpadding="20" border="0" width="640" align="center">
<tr width="650px">
<td bgcolor="#D7D3C7" style="padding:10px" align="center">TIP</td> </tr>
</table>
<table cellspacing="20" cellpadding="20" border="0" width="640" align="center">
<tr width="650px">
<td bgcolor="#D7D3C7" style="padding:10px" align="center">TIP</td>
</tr>
</table>
<table cellspacing="20" cellpadding="20" border="0" width="640" align="center">
<tr width="650px">
<td bgcolor="#D7D3C7" style="padding:10px" align="center">FOOTER</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
In any web tool it looks like this, which is generally how I want to it to look.:
However when I send it to Lotus Notes (I am using the testing tool PutsMail to send jt to my Lotus Notes email account, here is what I get. I know it looks almost the same, but it is not.There is extra space on the left.
I have struggled for hours trying to figure out what is wrong.
Can anyone see something that I am missing.

Creating cross-client email logo using tables and no images

I am trying to create a "cool" email signature for my company using only text and html with NO images whatsoever. I am trying to recreate our company's logo using only tables since it is basically a four cell table with different bg colors. What seemed easy at first has become quite a nuisance. It obviously looks good in browsers but once I paste it into Outlook 2013 the cells don't retain their height and width values. Any suggestions on how to make this work across most current email clients??
http://codepen.io/anon/pen/wqaLm
Firstly, a good technique is to style your cells inline like:
<td style="width:10px; height:10px;">
Secondly: have a look at this article: "A complete breakdown of the CSS support for every popular mobile, web and desktop email client"
Here is a basic example. Not sure exactly what the logo looks like, so here are a few versions. If you want to have the gap between the cells smaller than 20px, you need to use the 3rd technique. This is because Outlook has a min-height on cells of around 19px which will create a larger gap between the rows.
<table width="100" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="50" height="50" bgcolor="#333333">
</td>
<td width="50" height="50" bgcolor="#555555">
</td>
</tr>
<tr>
<td width="50" height="50" bgcolor="#444444">
</td>
<td width="50" height="50" bgcolor="#666666">
</td>
</tr>
</table>
<br><br>
<table width="100" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="40" height="40" bgcolor="#333333">
</td>
<td width="20" height="40">
</td>
<td width="40" height="40" bgcolor="#555555">
</td>
</tr>
<tr>
<td width="40" height="20">
</td>
<td width="20" height="20">
</td>
<td width="40" height="20">
</td>
</tr>
<tr>
<td width="40" height="40" bgcolor="#444444">
</td>
<td width="20" height="40">
</td>
<td width="40" height="40" bgcolor="#666666">
</td>
</tr>
</table>
<br><br>
<table width="60" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="30" height="30" align="left" valign="top">
<table width="25" height="25" border="0" cellpadding="0" cellspacing="0">
<tr>
<td bgcolor="#333333">
</td>
</tr>
</table>
</td>
<td width="30" height="30" align="right" valign="top">
<table width="25" height="25" border="0" cellpadding="0" cellspacing="0">
<tr>
<td bgcolor="#555555">
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="30" height="30" align="left" valign="bottom">
<table width="25" height="25" border="0" cellpadding="0" cellspacing="0">
<tr>
<td bgcolor="#444444">
</td>
</tr>
</table>
</td>
<td width="30" height="30" align="right" valign="bottom">
<table width="25" height="25" border="0" cellpadding="0" cellspacing="0">
<tr>
<td bgcolor="#666666">
</td>
</tr>
</table>
</td>
</tr>
</table>

HTML Email and Lotus Notes - Content is repeating

I have an HTML Email campaign that I have tested with EmailOnAcid.com. The email displays fine in almost all clients except Lotus Notes v6.5, v7, v8 :(
In Lotus Notes 6.5 & 7, at the end of the email, Lotus seems to repeat the email from the start again, so it looks like the same email has been put in twice, but it hasn't.
Is there a mimimum height for HTML emails in Lotus? (height of my email is around 474px).
I have specified height on all image elements and on tags.
In Lotus Notes 8, there is a minor problem; the lower part of the footer image repeats itself?
Does anyone have ideas as to what is causing these problems??
Thanks in advance.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Email</title>
</head>
<body>
<table cellpadding="0" cellspacing="0" border="0" width="650" align="center">
<tr>
<td width="650">
<table cellpadding="0" cellspacing="0" border="0" width="650">
<tr>
<td width="650">
<table cellpadding="0" cellspacing="0" border="0" width="650">
<tr>
<td width="650"><img src="http://www.website.com/images/hdr.jpg" width="650" height="36" border="0" alt="" style="display:block;margin:0;"></td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="650">
<table cellpadding="0" cellspacing="0" border="0" width="650">
<tr>
<td width="137" height="53"><img src="http://www.website.com/images/hdr_left.gif" width="137" height="53" border="0" alt="" style="display:block;margin:0;"></td>
<td width="513" height="53"><img src="http://www.website.com/images/hdr_right.jpg" width="513" height="53" border="0" alt="" style="display:block;margin:0;"></td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="650">
<table cellpadding="0" cellspacing="0" border="0" width="650">
<tr>
<td width="650"><img src="http://www.website.com/images/spacer_top.jpg" width="650" height="28" border="0" alt="" style="display:block;margin:0;"></td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="650">
<table cellpadding="0" cellspacing="0" border="0" width="650">
<tr>
<td width="397" valign="top"><img src="http://www.website.com/images/gold_main.jpg" width="397" height="271" border="0" alt="" style="display:block;margin:0;"></td>
<td width="240" valign="top">
<table cellpadding="0" cellspacing="0" border="0" width="240">
<tr>
<td><img src="http://www.website.com/images/title_text.gif" width="240" height="105" border="0" alt="" style="display:block;margin:0;"></td>
</tr>
<tr>
<td><img src="http://www.website.com/images/spacer_white.gif" width="240" height="12" border="0" alt="" style="display:block;margin:0;"></td>
</tr>
<tr>
<td><font style="font-family:verdana; font-size:10px;" color="#808180"><b>TEXT GOES HERE TEXT GOES HERE TEXT GOES HERE TEXT GOES HERE TEXT GOES HERE TEXT GOES HERE TEXT GOES HERE TEXT GOES HERE TEXT GOES HERE TEXT GOES HERE TEXT GOES HERE TEXT GOES HERE TEXT GOES HERE</b></font></td>
</tr>
<tr>
<td><img src="http://www.website.com/images/spacer_white.gif" width="240" height="12" border="0" alt="" style="display:block;margin:0;"></td>
</tr>
<tr>
<td><font style="font-family:verdana; font-size:10px;" color="#808180"><b>TEXT GOES HERE TEXT GOES HERE TEXT GOES HERE TEXT GOES HERE TEXT GOES HERE TEXT GOES HERE TEXT GOES HERE TEXT GOES HERE</b></font></td>
</tr>
</table>
</td>
<td width="13"><img src="http://www.website.com/images/spacer_white.gif" width="13" height="2" border="0" alt="" style="display:block;margin:0;"></td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="650" height="12"> </td>
</tr>
<tr>
<td width="650">
<table cellpadding="0" cellspacing="0" border="0" width="650" height="85">
<tr>
<td width="397" height="85"><img src="http://www.website.com/images/ftr_left_cmras.jpg" width="397" height="85" border="0" alt="" style="display:block;margin:0;"></td>
<td width="253" height="85"><img src="http://www.website.com/images/ftr_right_lnk.gif" width="253" height="85" border="0" alt="" style="display:block;margin:0;"></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
It appears this might be an issue with the EmailsOnAcid testing system.