how many c:forEach can we have in 1 jsp file - spring

I am having a trouble with my jsp file at the moment, for somehow when i include pagination.jsp, my website goes like this ( but if i don't, everything works well). Can anybody help me with this ?
Here is my original jsp file:
<%# page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>User Management</title>
<jsp:include page="../Common/inlcude.jsp"/>
</head>
<body>
<jsp:include page="../Common/header.jsp"/>
<jsp:include page="../Common/sidebar.jsp"/>
<h1 class="col-md-10" style="margin-bottom:20px"> List Of Member </h1>
<div class="col-md-10">
<form style="margin-left: 20px;padding-left : 20px;" class="table table-hover col-lg-9 col-md-6 col-sm-3 col-xs-3" method="GET" action="#" >
<input type="text" name="search" id="search" placeholder ='Search user'>
<input type="submit" name='submit' value='search'>
</form>
<table style="margin-left: 0px;padding-left : 0px;" class="table table-hover col-lg-9 col-md-6 col-sm-3 col-xs-3">
<thead>
<th>STT</th>
<th>TenTaiKhoan</th>
<th>HoTen</th>
<th>Email</th>
<th>SDT</th>
<th>AnhDaiDien</th>
<th>DiaChi</th>
<th>GioiTinh</th>
<th>NgaySinh</th>
<th>LoaiTaiKhoan</th>
<th>TrangThai</th>
<th>Edit</th>
<th>Delete</th>
</thead>
<tbody>
<c:forEach var="user" items="${users}" varStatus="status">
<tr>
<td>${status.index + 1}</td>
<td>${user[0]}</td>
<td>${user[3]}</td>
<td>${user[4]}</td>
<td>${user[5]}</td>
<td><img src="../Resources/Images/${user[1]}" alt="" id="img1" height="150" width="150"></td>
<td>${user[6]}</td>
<td>${user[7]}</td>
<td>${user[8] == 1?"User":"Admin"}</td>
<td>${user[9]}</td>
<td>${user[10] == 1?"Actived":"Removed"}</td>
<td align="center">
<a href="${user[0]}.htm?ModifyForm">
<img src="../Resources/Images/edit.png">
</a>
</td>
<td align="center"><a onclick="return confirm('Are you sure you want to delete this')"
href="${user[0]}.htm?Delete"><img src="../Resources/Images/delete.png"/></a></td>
<tr>
</c:forEach>
</tbody>
</table>
</div>
<jsp:include page="../Common/pagination.jsp"/>
<jsp:include page="../Common/footer.jsp"/>
</body>
</html>
And here is the pagination.jsp file that i inlcude:
<%--
Created by IntelliJ IDEA.
User: levub
Date: 4/10/2020
Time: 2:40 PM
To change this template use File | Settings | File Templates.
--%>
<%# page contentType="text/html;charset=UTF-8" language="java" %>
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<div class="col-lg-10" style="text-align: center;">
<c:choose>
<c:forEach var="index" begin="1" end="2">
<c:when test="${page > index && page - 1 == index}">
<a class="button" href="UserManagement.htm?page=${page - 1}"></a>
</c:when>
<c:when test="${page <= index && page + 2 >= index}">
<a class="button" href="UserManagement.htm?page=${index}"></a>
</c:when>
<c:when test="${page < 10 && page + 2 == index && 10 - page > 2}">
<a class="button" href="UserManagement.htm?page=${page + 1}"></a>
</c:when>
</c:forEach>
</c:choose>
</div>
And this what i get from my browser when i include it :

Correct way to use Tag. Also, your nesting of tags is incorrect with c:forEach
<c:choose>
<c:when test="${condition1}">
//do something if condition1 is true
</c:when>
<c:when test="${condition2}">
//do something if condition2 is true
</c:when>
<c:otherwise>
//Statements which gets executed when all <c:when> tests are false.
</c:otherwise>

Related

How to compare 2 values using jstl

I have lists in controller
List l=serviceClientServiceImpl.getSavedParents(clientId);
uiModel.addAttribute("savedParents",l);
List<Parent> parentList =
(List<Parent>) serviceClientServiceImpl.getParents("Parent",Long.valueOf(clientId));
uiModel.addAttribute("parentList", parentList);
and I am retrieving it in jsp like the follow
<ul style="max-width: 300px;" class="nav nav-pills nav-stacked" id="menuId">
<c:forEach items="${parentList}" var="test">
<li ><a href="#" value="${test.id}-${test.category}" id="${parent.id}" onclick="return getQuestions(this);" >
<input type="checkbox" value="${test.id}">${test.name }</a></li>
</c:forEach>
</ul>
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
<c:forEach items="${savedParents}" var="test1">
<ul style="max-width: 300px;" class="nav nav-pills nav-stacked">
<li class="active"><a href="#" value="${test1.id}" onclick="return getQuestions(this);">
<input type="checkbox" value="${test1.id}"></a></li>
</ul>
</c:forEach>
Now I want to merge the the both and where ever test.id equals to test1.id then I want to add an html class="active"
I tried the following way
<ul style="max-width: 300px;" class="nav nav-pills nav-stacked" id="menuId">
<c:forEach items="${parentList}" var="test">
<c:forEach items="${savedParents}" var="test1">
<c:when test3="${test.id}==${test1.id }">
<li ><a href="#" class="active" value="${test.id}-${test.category}" id="${parent.id}" onclick="return getQuestions(this);" >
<input type="checkbox" value="${test.id}">${test.name }</a></li>
</c:when>
<c:otherwise>
<li ><a href="#" value="${test.id}-${test.category}" id="${parent.id}" onclick="return getQuestions(this);" >
<input type="checkbox" value="${test.id}">${test.name }</a></li>
</c:otherwise>
</c:forEach>
<%-- <li ><a href="#" value="${test.id}-${test.category}" id="${parent.id}" onclick="return getQuestions(this);" >
<input type="checkbox" value="${test.id}">${test.name }</a></li> --%>
</c:forEach>
</ul>
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
but I am getting error in eclipse
Multiple annotations found at this line:
- Missing required attribute
"test"
- Undefined attribute name
"test3"
- Missing required attribute
"test"
- Undefined attribute name
"test3"
Can any body help me in this?
Try comparing the strings this way
<c:when test="${test.id == test1.id }">
you could also use the eq instead of ==
<c:when test="${test.id eq test1.id }">
It should be <c:when test= instead of <c:when test3=
try with c:if as well
<c:set var="id1" value="2" />
<c:set var="id" value="2" />
<c:if test="${id == id1 }">
Equal
</c:if>
OR
<c:set var="id1" value="2" />
<c:set var="id" value="2" />
<c:choose>
<c:when test="${id == id1 }">
Equal
</c:when>
<c:otherwise>
Not equal
</c:otherwise>
</c:choose>
Read more JSTL Core conditional Tag
Note:
complete conditional expression must be enclosed inside single ${}
c:when tag should be enclosed inside the c:choose tag
The <c:choose> works like a Java switch statement in that it lets you choose between a number of alternatives. Where the switch statement has case statements, the <c:choose> tag has <c:when> tags. A a switch statement has default clause to specify a default action and similar way <c:choose> has <c:otherwise> as default clause.

session with spring and iframe

I work with spring and jsp ( which include iframe)
I have problem with session
I have the login page ( index.jsp) and I have other page ( menu.jsp) which include iframe
I want when the session is expired to redirect from menu.jsp to index.jsp
this is my index.jsp :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!-- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> -->
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%#taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>index</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link rel="stylesheet" type="text/css" href="/Test/theme/login.css">
<!--[if IE 6]>
<link href="default_ie6.css" rel="stylesheet" type="text/css" />
<![endif]-->
</head>
<body>
<div id="wrapper">
<div id="page">
<div id="content">
<div id="content_space">
<form name='f' action="<c:url value='j_spring_security_check' />" method="POST">
<c:if test="${param.error == 1}">
<h3 style="font-size:20; color:#FF1C19;">error.</h3>
</c:if>
<table dir="ltr">
<tbody>
<tr>
<td width="100%">
<table align="left" width="100%" dir="ltr" style="padding-top: 35px;">
<tbody><tr>
<td width="10"></td>
<td><input name="j_username" type="text" value=""></td>
<td width="10"></td>
<td style="color: #000000" align="right">username</td>
</tr>
</tbody></table>
</td>
</tr>
<tr>
<td width="100%">
<span id="_58_passwordCapsLockSpan" style="display: none;">Caps Lock is on.</span><table align="left" dir="ltr" width="100%">
<tbody><tr>
<td width="10"></td>
<td><input name="j_password" type="password" value=""></td>
<td width="10"></td>
<td style="color: #000000" align="right">login</td>
</tr>
</tbody></table>
</td>
</tr>
<tr>
<td>
<table align="left" dir="ltr" style="padding-left: 15px;">
<tbody><tr>
<td><input type="submit" class="signinAR" value=""></td>
<td width="10"></td>
</tr>
</tbody></table>
</td>
</tr>
</tbody></table>
</form>
</div>
</div>
<div id="sidebar">
<p></p>
</div>
</div>
</div>
</body>
</html>
and this is my menu.jsp
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%#taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%#page import="org.springframework.security.core.userdetails.UserDetails"%>
<%#page import="org.springframework.security.core.context.SecurityContextHolder"%>
<%
String contextPath = request.getContextPath();
Boolean enbaleSMenu = false;
if(request.isUserInRole("ADMIN")){
enbaleSMenu=true;
}
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
String username = "";
if (principal instanceof UserDetails) {
username = ((UserDetails)principal).getUsername();
} else {
username = principal.toString();
}
if(username.equals("anonymousUser")){
response.sendRedirect("/Test/index.htm");
parent.reLoadPage();
}
%>
<html>
<head>
<title>menu</title>
<link rel="stylesheet" type="text/css" href="/Test/theme/default.css">
<script type="text/javascript"
src="<c:url value='/extjs/jquery-latest.min.js'/>"></script>
<script type="text/javascript"
src="<c:url value='/extjs/main.js'/>"></script>
<script>
function loadIframe(iframeName, url) {
var $iframe = $('#' + iframeName);
if ( $iframe.length ) {
$iframe.attr('src',url);
return false;
}
return true;
}
function reLoadPage(){
location.replace("/Test/index.htm");
location.reload();
}
// hidding menu
var hiddenSMenu=<%=enbaleSMenu%>;
function showMenu()
{
if(hiddenSMenu)
{
document.getElementById("idSmenu").children[2].style.display="none";
loadIframe('cmpframe', '/Test/administration/Validation.htm');
}
else
{
document.getElementById("idSmenu").children[0].style.display="none";
document.getElementById("idSmenu").children[1].style.display="none";
loadIframe('cmpframe', '/Test/citizen/Request.htm');
}
}
</script>
<style type="text/css">
label.myBold
{
font-weight: bold;
text-decoration: none;
color: red;
}
.my-fieldset {
background: #F1F3FB,
border: 1px solid red
}
.my-fieldset .x-fieldset-header {
color: red
}
</style>
</head>
<body dir="rtl" onload="showMenu()" >
<script>
<%#taglib uri="http://www.springframework.org/tags" prefix="spring"%>
</script>
<a href="<c:url value="../j_spring_security_logout" />" > ????</a>
<div id="wrapper">
<div id="header">
<div id="logo_left">
<p>
<img src="/Test/theme/images/Taif_logo.png">
</p>
</div>
<div id="logo">
<h1><img src="/Test/theme/images/MIS_logo.png"></h1>
</div>
</div>
<div id="page">
<div id='cssmenu'>
<ul>
<li style="display: none;><span>Home</span></li>
<li><span><spring:message code="label.titleProjet"/></span>
<ul id="idSmenu">
<li class="current"><spring:message code="label.consult"/></li>
<li class="current"><spring:message code="label.validate"/></li>
<li class="current"><spring:message code="label.Request"/></li>
</ul>
</li>
</li>
</ul>
</div>
<div id = "divFrame" >
<iframe id="cmpframe" name="myframe" width="84%" height="100%" >
</iframe></div>
</div>
</div>
</body>
</html>
this is the code whcih should redirect from menu.jsp to index.jsp when the session is expired :
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
String username = "";
if (principal instanceof UserDetails) {
username = ((UserDetails)principal).getUsername();
} else {
username = principal.toString();
}
if(username.equals("anonymousUser")){
response.sendRedirect("/Test/index.htm");
parent.reLoadPage();
}
but with this code I have also the same problem
Updated :
this is my error when I test this code :
parent cannot be resolved
39: }
40: if(username.equals("anonymousUser")){
41: response.sendRedirect("/Test/index.htm");
42: parent.reLoadPage();
43: }
44:
45:
I didn't know how can I declare parent

Please create XPATH for the table element

Could you please create complete XPATH for the following web element
Address 1 (PO Box/Rural Route is ok)
it would be great if you give me how to create the XPATH as well for any HTML or XML code.
HTML code:
<!DOCTYPE html>
<html>
<head>
<body id="myProfile">
<div id="header">
<div class="wrapperMenu">
<div class="wrapperBodyCreditCenter">
<div id="bodyAll2">
<div>
<div class="fsmWideHero">
<div style="display: block; margin-bottom: 10px;">
<div class="fsmSubHeader"> Please update any information to maintain a clean and current profile. Once the correct information is entered, simply click on the save changes button to update your profile. </div>
<span class="validateError"> </span>
<script src="https://staging.privacyguard.com/ClientScript.aspx?script=FormControl%2fdisableOnSubmit.js&utc=633470607600000000" type="text/javascript">
<form action="/secure/MyProfile.aspx" autocomplete="OFF" name="PGUpdateProfileFormControl" onsubmit="disableSubmission(this)" method="post">
<input type="hidden" value="pgupdateprofile" name="cf">
<input id="__FLOWEVENT" type="hidden">
<input type="hidden" value="5sXZAFNB4Co/JF70jyZ1HHJdIMso9YP2jGmMsyuLQCKC2J0lOg2XDVX2FcLJBS2WMnYD55d7UNLPVXW0yHa6f4WVjmWwwvT0KiwnAY+6v0xpWJZ9fuKe5F2h25Z+aZZwdoEpJtmnYVyvq+znPaYwyQqTV0d3M6bWeBKMt6woDqdtRzUEooyojAzyaMiYFyqosVe5cGarbQWvFZiUJqH3wGRawchSjnjzh/Amy2F8YHZlJFJVWYAQ4PUx8E9GQeShHsCMs2Fg3ToiUemtIpgXaCGMnCby+sCEnRW4SPA3P9/Et2VO/YXsCYSwkfsNsqSAWMnYoicNwJy9ALYny1uAUxgBrv4dELuz+St9CcUrB0w=" name="__FlowState__">
<input type="hidden" value="364" name="__fspayload">
<div id="profileFormHeader"> Personal Information </div>
<div id="profileFormBody">
If you wish to change your name, contact the FreeScoresAndMore customer service center at 1-877-787-9002.
<p>
<p> </p>
<table cellspacing="0" cellpadding="2" border="0" summary="">
<tbody>
<tr>
<td width="220" align="left">
<label for="mpadr1">Address 1 (PO Box/Rural Route is ok)</label>
<br>
<input id="mpadr1" type="text" value="123 new address" name="UpdateProfile_Address1" maxlength="25" size="28">
</td>
<td align="left" colspan="2">
<td width="200" valign="top" bgcolor="#FFFFFF" align="left" style="background-color:#EFF0F2;" rowspan="3">
</tr>
<tr>
<tr>
</tbody>
</table>
</div>
<div id="profileFormHeader"> Membership Information </div>
<div id="profileFormBody">
<div id="profileFormHeader"> Subscription Preference </div>
<div id="profileFormBody">
<div style="text-align:center;margin-top:10px;">
</form>
</div>
<input type="hidden" value="7iuanXFUppuCMU7T/6LZi09GsdZ2dCYBLeTL/Wfbclc=" name="authToken">
</div>
</div>
<div class="clear" style="padding-bottom:20px;"></div>
<div id="subFooter">
<div id="mainFooter">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js" type="text/javascript">
<script type="text/javascript">
<script type="text/javascript">
</body>
</html>
Thanks In Advance
I don't think there's a magic-ally way of doing things. There's a lot of guides/tutorials out there where you can start learning.
Nonetheless, here's the xpath code that you need //label[#for='mpadr1'] or //label[contains(.,'Address 1')]

Removing the duplicate id in jstl

I am using jstl. In my page there is a loop which creates div's with different ids but i have seen there are some of the div( after loop completion) having the same id which(div) i want to remove or say want to prevent them to be created. I want to achieve it inside the loop itself through jstl. Please help.
Please find the code segment-
<c:forEach var="menuType" items="${menuTypes}" begin="0" varStatus="mCount">
<c:set var="mcnt" value="${mCount.count}"></c:set>
<div class="window" id="window${mcnt}" onmouseout="hideBub('${mcnt}');" style="top:${mcnt*200}px">
<div id="inner-cont${mcnt}" class="inner-cont" align="center" onmouseover="showBubble('${mcnt}');">
${menuType.functionName}(<span id="totRecord"></span>)
<div class="bubble" id="bubble${mcnt}" style="margin-left:50px;" onmouseout="hideBub('${mcnt}');">
<a href="#">
<span>[+] Add New
</span>
</a>
<hr>
<div class="box">
<div class="box-content">
<table width="100%" class="hovertable">
<tbody>
<tr><td></td></tr>
</tbody>
</table>
</div>
</div>
</div>
<div id="dispRec${mcnt}" class="dispRec"></div>
</div>
<div align="center" class="btnContainer" style="width:90px;">
<span class="linkButton">View</span>
<span class="linkButton">Edit</span>
<span class="linkButton">Delete</span>
</div>
<div align="center" class="btnContainer" style="width:47px;float: right">
<span class="linkButton" style="display: inline-block;padding: 1px;margin-right: 2px">
Analysis
</span>
</div>
</div>
</c:forEach>
</div>

Html Agility Pack: make code look neat

Can I use Html Agility Pack to make the output look nicely indented, unnecessary white space stripped?
HAP is not going to give you the results you are after.
Try using a .net wrapper for HtmlTidy such as the one found here
using System;
using System.IO;
using System.Net;
using Mark.Tidy;
namespace CleanupHtml
{
/// <summary>
/// http://markbeaton.com/SoftwareInfo.aspx?ID=81a0ecd0-c41c-48da-8a39-f10c8aa3f931
/// </summary>
internal class Program
{
private static void Main(string[] args)
{
string html =
new WebClient().DownloadString(
"http://stackoverflow.com/questions/2593147/html-agility-pack-make-code-look-neat/2610903#2610903");
using (Document doc = new Document(html))
{
doc.ShowWarnings = false;
doc.Quiet = true;
doc.OutputXhtml = true;
doc.OutputXml = true;
doc.IndentBlockElements = AutoBool.Yes;
doc.IndentAttributes = false;
doc.IndentCdata = true;
doc.AddVerticalSpace = false;
doc.WrapAt = 120;
doc.CleanAndRepair();
string output = doc.Save();
Console.WriteLine(output);
File.WriteAllText("output.htm", output);
}
}
}
}
Results:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="generator" content="HTML Tidy for Windows (vers 14 October 2008), see www.w3.org" />
<title>
Html Agility Pack: make code look neat - Stack Overflow
</title>
<link rel="stylesheet" href="http://sstatic.net/so/all.css?v=6638" type="text/css" />
<link rel="shortcut icon" href="http://sstatic.net/so/favicon.ico" />
<link rel="apple-touch-icon" href="http://sstatic.net/so/apple-touch-icon.png" />
<link rel="search" type="application/opensearchdescription+xml" title="Stack Overflow" href=
"http://sstatic.net/so/opensearch.xml" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js">
</script>
<script type="text/javascript" src="http://sstatic.net/so/js/master.js?v=6523">
</script>
<script type="text/javascript">
//<![CDATA[
var imagePath='http://sstatic.net/so/img/';
//]]>
</script>
<link rel="canonical" href="http://stackoverflow.com/questions/2593147/html-agility-pack-make-code-look-neat" />
<link rel="alternate" type="application/atom+xml" title=
"Feed for question 'Html Agility Pack: make code look neat'" href="/feeds/question/2593147" />
<script src="http://sstatic.net/so/js/question.js?v=6714" type="text/javascript">
</script>
<script type="text/javascript">
//<![CDATA[
var fkey = "b00609a1a5f2966a687eca3f84e4dd64";
$(function() {
vote.init(2593147);
comments.init();
styleCode();
});
//]]>
</script>
</head>
<body>
<noscript>
<div id="noscript-padding"></div></noscript>
<div id="notify-container"></div><script type="text/javascript">
//<![CDATA[
$(function() { notify.showFirstTime(); });
//]]>
</script>
<div class="container">
<div id="header">
<div id="topbar">
<div id="hlinks">
<a href=
"/users/login?returnurl=%2fquestions%2f2593147%2fhtml-agility-pack-make-code-look-neat%2f2610903">login</a>
<span class="lsep">|</span> careers <span class=
"lsep">|</span> about <span class="lsep">|</span> faq
</div>
<div id="hsearch">
<form id="search" action="/search" method="get" name="search">
<div>
<input name="q" class="textbox" tabindex="1" onfocus="if (this.value=='search') this.value = ''" type=
"text" maxlength="80" size="28" value="search" />
</div>
</form>
</div>
</div><br class="cbt" />
<div id="hlogo">
<img src="http://sstatic.net/so/img/logo.png" width="250" height="61" alt="Stack Overflow" />
</div>
<div id="hmenus">
<div class="nav">
<ul>
<li class="youarehere">
Questions
</li>
<li>
Tags
</li>
<li>
Users
</li>
<li>
Badges
</li>
<li>
Unanswered
</li>
</ul>
</div>
<div class="nav" style="float:right">
<ul>
<li style="margin-right:0px">
Ask Question
</li>
</ul>
</div>
</div>
</div>
<div id="content">
<div id="question-header">
<h2>
<a href="/questions/2593147/html-agility-pack-make-code-look-neat" class="question-hyperlink">Html Agility
Pack: make code look neat</a>
</h2>
</div>
<div id="mainbar">
<div id="question" class="">
<div class="everyonelovesstackoverflow">
<script type="text/javascript">
//<![CDATA[
document.write('<s'+'cript lang' + 'uage="jav' + 'ascript" src="http://ads.stackoverflow.com/a.aspx?ZoneID=3&Task=Get&IFR=False&PageID=52405&SiteID=1&Random=' + (+new Date()) + '&Keywords=htmlagilitypack">');
document.write('</'+'scr'+'ipt>');
//]]>
</script> <noscript>
<div>
<a href=
"http://ads.stackoverflow.com/a.aspx?ZoneID=3&Task=Click&Mode=HTML&SiteID=1&PageID=52405">
<img src=
"http://ads.stackoverflow.com/a.aspx?ZoneID=3&Task=Get&Mode=HTML&SiteID=1&PageID=52405"
alt="" /></a>
</div></noscript>
</div>
<table>
<tr>
<td class="votecell">
<div class="vote">
<input type="hidden" value="2593147" /> <img class="vote-up" src=
"http://sstatic.net/so/img/vote-arrow-up.png" width="40" height="25" alt="vote up" title=
"This question is useful and clear (click again to undo)" /> <span class="vote-count-post">1</span>
<img class="vote-down" src="http://sstatic.net/so/img/vote-arrow-down.png" width="40" height="25"
alt="vote down" title="This question is unclear or not useful (click again to undo)" /> <img class=
"vote-favorite" src="http://sstatic.net/so/img/vote-favorite-off.png" width="32" height="31" alt=
"star" title="This is a favorite question (click again to undo)" />
<div class="favoritecount"></div>
</div>
</td>
<td>
<div>
<div class="post-text">
<p>
Can I use Html Agility Pack to make the output look nicely indented, unnecessary white space
stripped?
</p>
</div>
<div class="post-taglist">
<a href="/questions/tagged/htmlagilitypack" class="post-tag" title=
"show questions tagged 'htmlagilitypack'" rel="tag">htmlagilitypack</a>
</div>
<table class="fw">
<tr>
<td class="vt">
<div class="post-menu">
<a id="flag-post-2593147" title="flag this post for serious problems" name=
"flag-post-2593147">flag</a>
</div>
</td>
<td class="post-signature owner">
<div class="user-info">
<div class="user-action-time">
asked <span title="2010-04-07 14:13:47Z" class="relativetime">2 days ago</span>
</div>
<div class="user-gravatar32">
<a href="/users/51795/illdev"><img src=
"http://www.gravatar.com/avatar/52dc0db2cdacc6e9769d074a37466317?s=32&d=identicon&r=PG"
height="32" width="32" alt="" /></a>
</div>
<div class="user-details">
illdev<br />
<span class="reputation-score" title="reputation score">53</span><span title=
"5 bronze badges"><span class="badge3">●</span><span class=
"badgecount">5</span></span>
</div>
</div><br class="cbt" />
<div class="accept-rate cool" title=
"this user has accepted an answer for 2 of 4 eligible questions">
50% accept rate
</div>
</td>
</tr>
</table>
</div>
</td>
</tr>
<tr>
<td class="votecell"></td>
<td>
<div id="comments-2593147" class="comments">
<table>
<tbody>
<tr id="comment-2600849" class="comment">
<td></td>
<td class="comment-text">
<div>
what output? From where? some more details perhaps? – <a href=
"/users/97614/sam-holder" title="1868" class="comment-user">Sam Holder</a> <span class=
"comment-date"><span title="2010-04-07 14:16:41Z">2 days ago</span></span>
</div>
</td>
</tr>
<tr id="comment-2600851" class="comment">
<td></td>
<td class="comment-text">
<div>
<i>(reference)</i> <a href="http://htmlagilitypack.codeplex.com/Wikipage" rel=
"nofollow">htmlagilitypack.codeplex.com/Wikipage</a> – <a href=
"/users/208809/gordon" title="16497" class="comment-user">Gordon</a> <span class=
"comment-date"><span title="2010-04-07 14:16:55Z">2 days ago</span></span>
</div>
</td>
</tr>
<tr id="comment-2624419" class="comment">
<td></td>
<td class="comment-text">
<div>
output = html code output – <a href="/users/51795/illdev" title="53" class=
"comment-user owner">illdev</a> <span class="comment-date"><span title=
"2010-04-10 13:14:42Z">12 secs ago</span></span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
</table>
</div>
<div id="answers">
<a name="tab-top" id="tab-top"></a>
<div id="answers-header">
<div id="subheader">
<h2>
2 Answers
</h2>
<div id="tabs">
<a href="/questions/2593147?tab=oldest#tab-top" title=
"Answers in the order they were given">oldest</a> <a href="/questions/2593147?tab=newest#tab-top"
title="Most recent answers first">newest</a> <a class="youarehere" href=
"/questions/2593147?tab=votes#tab-top" title="Answers with the most votes first">votes</a>
</div>
</div>
</div><a name="2610845"></a>
<div id="answer-2610845" class="answer">
<table>
<tr>
<td class="votecell">
<div class="vote">
<input type="hidden" value="2610845" /> <img class="vote-up" src=
"http://sstatic.net/so/img/vote-arrow-up.png" width="40" height="25" alt="vote up" title=
"This answer is useful (click again to undo)" /> <span class="vote-count-post">0</span>
<img class="vote-down" src="http://sstatic.net/so/img/vote-arrow-down.png" width="40" height="25"
alt="vote down" title="This answer is not useful (click again to undo)" />
</div>
</td>
<td>
<div class="post-text">
<p>
A variation of this question has been answered recently
</p>
<ul>
<li>
<a href=
"http://stackoverflow.com/questions/2490765/which-is-the-best-html-tidy-pack-is-there-any-option-in-html-agility-pack-to-mak/2507673#2507673">
http://stackoverflow.com/questions/2490765/which-is-the-best-html-tidy-pack-is-there-any-option-in-html-agility-pack-to-mak/2507673#2507673</a>
</li>
</ul>
<p>
Basically the outcome of this was that while you <strong>can</strong> use HtmlAgilityPack to
clean it up a bit by using the fix nested tags.
</p>
<p>
The best solution is to use something called Tidy which is an application that was originally
created by some developers at w3c and then made open source. Its the engine that powers the w3c
validator as well.
</p>
<p>
This article covers how to use it but you had to sign up (free) to view it:
</p>
<ul>
<li>
<a href="http://www.devx.com/dotnet/Article/20505/1763/" rel=
"nofollow">http://www.devx.com/dotnet/Article/20505/1763/</a>
</li>
</ul>
<p>
It seems like a legit article but its funny because nobody else seems to have covered this
topic in the last six years...
</p>
</div>
<table class="fw">
<tr>
<td class="vt">
<div class="post-menu">
<a href="/questions/2593147/html-agility-pack-make-code-look-neat/2610845#2610845" title=
"permalink to this answer">link</a><span class="lsep">|</span><a id="flag-post-2610845"
title="flag this post for serious problems" name="flag-post-2610845">flag</a>
</div>
</td>
<td align="right" class="post-signature">
<div class="user-info">
<div class="user-action-time">
answered <span title="2010-04-09 20:55:18Z" class="relativetime">16 hours ago</span>
</div>
<div class="user-gravatar32">
<a href="/users/156388/rtpharry"><img src=
"http://www.gravatar.com/avatar/6811db2b37e824fdf6c5c4fcdddd4146?s=32&d=identicon&r=PG"
height="32" width="32" alt="" /></a>
</div>
<div class="user-details">
rtpHarry<br />
<span class="reputation-score" title="reputation score">88</span><span title=
"6 bronze badges"><span class="badge3">●</span><span class=
"badgecount">6</span></span>
</div>
</div>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="votecell"></td>
<td>
<div id="comments-2610845" class="comments dno">
<table>
<tbody>
<tr>
<td></td>
<td></td>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
</table>
</div>
<div class="everyonelovesstackoverflow">
<script type="text/javascript">
//<![CDATA[
document.write('<s'+'cript lang' + 'uage="jav' + 'ascript" src="http://ads.stackoverflow.com/a.aspx?ZoneID=14&Task=Get&IFR=False&PageID=52405&SiteID=1&Random=' + (+new Date()) + '&Keywords=htmlagilitypack">');
document.write('</'+'scr'+'ipt>');
//]]>
</script> <noscript>
<div>
<a href=
"http://ads.stackoverflow.com/a.aspx?ZoneID=14&Task=Click&Mode=HTML&SiteID=1&PageID=52405">
<img src=
"http://ads.stackoverflow.com/a.aspx?ZoneID=14&Task=Get&Mode=HTML&SiteID=1&PageID=52405"
alt="" /></a>
</div></noscript>
</div><a name="2610903"></a>
<div id="answer-2610903" class="answer">
<table>
<tr>
<td class="votecell">
<div class="vote">
<input type="hidden" value="2610903" /> <img class="vote-up" src=
"http://sstatic.net/so/img/vote-arrow-up.png" width="40" height="25" alt="vote up" title=
"This answer is useful (click again to undo)" /> <span class="vote-count-post">0</span>
<img class="vote-down" src="http://sstatic.net/so/img/vote-arrow-down.png" width="40" height="25"
alt="vote down" title="This answer is not useful (click again to undo)" />
</div>
</td>
<td>
<div class="post-text">
<p>
Output as XHTML and run that through an <a href=
"http://msdn.microsoft.com/en-us/library/system.xml.xmltextwriter.indentation.aspx" rel=
"nofollow">XmlTextWriter</a>
</p>
</div>
<table class="fw">
<tr>
<td class="vt">
<div class="post-menu">
<a href="/questions/2593147/html-agility-pack-make-code-look-neat/2610903#2610903" title=
"permalink to this answer">link</a><span class="lsep">|</span><a id="flag-post-2610903"
title="flag this post for serious problems" name="flag-post-2610903">flag</a>
</div>
</td>
<td align="right" class="post-signature">
<div class="user-info">
<div class="user-action-time">
answered <span title="2010-04-09 21:02:34Z" class="relativetime">16 hours ago</span>
</div>
<div class="user-gravatar32">
<a href="/users/242897/sky-sanders"><img src=
"http://www.gravatar.com/avatar/df4a7fbd8a054fd6193ca0ee62952f1f?s=32&d=identicon&r=PG"
height="32" width="32" alt="" /></a>
</div>
<div class="user-details">
Sky Sanders<br />
<span class="reputation-score" title="reputation score">4,014</span><span title=
"2 silver badges"><span class="badge2">●</span><span class=
"badgecount">2</span></span><span title="14 bronze badges"><span class=
"badge3">●</span><span class="badgecount">14</span></span>
</div>
</div>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="votecell"></td>
<td>
<div id="comments-2610903" class="comments dno">
<table>
<tbody>
<tr>
<td></td>
<td></td>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
</table>
</div>
<form id="post-form" action="/questions/2593147/answer/submit" method="post" name="post-form">
<h2 class="space">
Your Answer
</h2><script src="http://sstatic.net/so/Js/wmd.js?v=6016" type="text/javascript">
</script> <script type="text/javascript">
//<![CDATA[
$(function() {
editorReady(1, heartbeat.answers);
});
//]]>
</script>
<div id="post-editor">
<div id="wmd-container">
<div id="wmd-button-bar"></div>
<textarea id="wmd-input" name="post-text" cols="92" rows="15" tabindex="101">
</textarea>
</div>
<div class="community-option">
<input id="communitymode" name="communitymode" type="checkbox" /> <label for="communitymode" title=
"community owned posts do not generate any reputation for the owner, have a lower reputation barrier for collaborative editing, and show only a revision history instead of a signature block">
community wiki</label>
</div>
<div id="wmd-preview"></div>
<div id="edit-block">
<input id="fkey" name="fkey" type="hidden" value="b00609a1a5f2966a687eca3f84e4dd64" /> <input id=
"author" name="author" type="text" />
</div>
</div>
<div class="form-item">
<table>
<tr>
<td class="vm">
<label for="openid_identifier">OpenID Login</label> <input id="openid_identifier" name=
"openid_identifier" class="openid-identifer" type="text" size="40" maxlength="200" value=""
tabindex="104" />
<div class="form-item-info">
Get an OpenID
</div>
</td>
<td class="orcell">
<div class="orword">
or
</div>
<div class="orline"></div>
</td>
<td class="vm">
<div>
<label for="display-name">Name</label> <input id="display-name" name="display-name" type="text"
size="30" maxlength="30" value="" tabindex="105" />
</div>
<div>
<label for="m-address">Email</label> <input id="m-address" name="m-address" type="text" size=
"40" maxlength="100" value="" tabindex="106" /> <span class="edit-field-overlay" style=
"color:#999; font-weight:normal">never shown</span>
</div>
<div>
<label for="home-page">Home Page</label> <input id="home-page" name="home-page" type="text"
size="40" maxlength="200" value="" tabindex="107" />
</div>
</td>
</tr>
</table>
</div>
<div class="form-submit cbt">
<input id="submit-button" type="submit" value="Post Your Answer" tabindex="110" />
</div>
</form>
<h2 class="space">
Not the answer you're looking for? Browse other questions tagged <a href=
"/questions/tagged/htmlagilitypack" class="post-tag" title="show questions tagged 'htmlagilitypack'" rel=
"tag">htmlagilitypack</a> or ask your own question.
</h2>
</div><img src="/posts/2593147/ivc/1707" class="dno" alt="" />
</div>
A variation of this question has been answered recently
Which is the best HTML tidy pack? Is there any option in HTML agility pack to make HTML webpage tidy?
Basically the outcome of this was that while you can use HtmlAgilityPack to clean it up a bit by using the fix nested tags.
The best solution is to use something called Tidy which is an application that was originally created by some developers at w3c and then made open source. Its the engine that powers the w3c validator as well.
This article covers how to use it but you had to sign up (free) to view it:
http://www.devx.com/dotnet/Article/20505/1763/
It seems like a legit article but its funny because nobody else seems to have covered this topic in the last six years...
See a similar question here: HtmlAgilityPack: how to create indented HTML? and my answer:
No, and it's a "by design" choice.
There is a big difference between XML
(or XHTML, which is XML, not HTML)
where - most of the times -
whitespaces are no specific meaning,
and HTML.
This is not a so minor improvement, as
changing whitespaces can change the
way some browsers render a given HTML
chunk, especially malformed HTML (that
is in general well handled by the
library). And The Html Agility Pack
was designed to minimize the way the
HTML is rendered, not the way the
markup is written.
I'm not saying it's not feasible or
plain impossible. Obviously you can
convert to XML and voilà (and you
could write an extension method to
make this easier) but the rendered
output may be different, in the
general case.

Resources