Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > ASP.NET 2.0 generated HTML not XHTML/XML compliant

Reply
Thread Tools

ASP.NET 2.0 generated HTML not XHTML/XML compliant

 
 
yoga weazel
Guest
Posts: n/a
 
      05-04-2006
OK, so let me start with what I'm trying to accomplish.

I have several screens with data displays using various controls (DataList,
DataGrid...). I need to provide functionality so that the user can click a
"Printable Version" button and a clean print formatted version of the data
chosen is displayed in a new window. I'd prefer to do as much of this client
side as possible so data services are not re-hit and not storing extraneous
data in Session or View state.

The approach I have currently is to provide a button which when clicked
calls javascript to open the GenericPrintReport.aspx page with the ID of the
original documents HTML element to print and the name of a XSL stylesheet to
use in a new window. The body of the GenericPrintReport.aspx page contains
the following javascript:

<pre>
<script language="javascript" type="text/javascript">
//get data from parentwindow.ctrl
var ctrl =
window.opener.document.getElementById('<%=Request. Params("CtrlId") %>');
//set DivData content to data
var xml = new ActiveXObject("Microsoft.XMLDOM");
xml.async = false;
// make sure to remove any invalid XML (such as )
var ctrlText = '<?xml version="1.0" encoding="UTF-16"?>' +
ctrl.innerHTML.replace(/\&nbsp\;/gi, "");
xml.loadXML(ctrlText); // Load XML Content

document.write("<br>Error Code: ")
document.write(xml.parseError.errorCode)
document.write("<br>Error Reason: ")
document.write(xml.parseError.reason)
document.write("<br>Error Line: ")
document.write(xml.parseError.line)

// load the requested transformation
var xsl = new ActiveXObject("Microsoft.XMLDOM");
xsl.async = false;
var xslFilename = '<%=Request.Params("Transform") %>';
if (xslFilename.length > 0)
{
xsl.load('<%=Request.Params("Transform") %>'); // Transformation
}
else
{
xsl.load('default.xsl');
}

// write results to output
var transformedXml = xml.transformNode(xsl);
document.write(transformedXml);
</script>
</pre>

OK. So now the problem... When using some of the .NET controls (e.g.
DataGrid) the HTML generated at runtime is not XHTML compliant therefore the
xml.loadXML(ctrlText) call gets a parse error:

Error Code: -1072896766
Error Reason: A string literal was expected, but no opening quote character
was found.
Error Line: 1

Since several of the attributes generated by the controls aren't contained
in quote characters.

Is there a way to change the behavior of the parser used by Microsoft.XMLDOM
or change the way the HTML is generated by the framework WebControls? Or is
there another way around this problem (besides writing my own pre-parser to
clean the HTML)? Thanks.



Yoga Weazel
- Eagles may soar but weasels don't get sucked into jet engines.
 
Reply With Quote
 
 
 
 
yoga weazel
Guest
Posts: n/a
 
      05-04-2006
Additionally, there is a good bit of formatting of the data that is displayed
in the source HTML element trying to be printed therefore do not really want
to reproduce this if at all possible. Thanks again.



"yoga weazel" wrote:

> OK, so let me start with what I'm trying to accomplish.
>
> I have several screens with data displays using various controls (DataList,
> DataGrid...). I need to provide functionality so that the user can click a
> "Printable Version" button and a clean print formatted version of the data
> chosen is displayed in a new window. I'd prefer to do as much of this client
> side as possible so data services are not re-hit and not storing extraneous
> data in Session or View state.
>
> The approach I have currently is to provide a button which when clicked
> calls javascript to open the GenericPrintReport.aspx page with the ID of the
> original documents HTML element to print and the name of a XSL stylesheet to
> use in a new window. The body of the GenericPrintReport.aspx page contains
> the following javascript:
>
> <pre>
> <script language="javascript" type="text/javascript">
> //get data from parentwindow.ctrl
> var ctrl =
> window.opener.document.getElementById('<%=Request. Params("CtrlId") %>');
> //set DivData content to data
> var xml = new ActiveXObject("Microsoft.XMLDOM");
> xml.async = false;
> // make sure to remove any invalid XML (such as )
> var ctrlText = '<?xml version="1.0" encoding="UTF-16"?>' +
> ctrl.innerHTML.replace(/\ \;/gi, "");
> xml.loadXML(ctrlText); // Load XML Content
>
> document.write("<br>Error Code: ")
> document.write(xml.parseError.errorCode)
> document.write("<br>Error Reason: ")
> document.write(xml.parseError.reason)
> document.write("<br>Error Line: ")
> document.write(xml.parseError.line)
>
> // load the requested transformation
> var xsl = new ActiveXObject("Microsoft.XMLDOM");
> xsl.async = false;
> var xslFilename = '<%=Request.Params("Transform") %>';
> if (xslFilename.length > 0)
> {
> xsl.load('<%=Request.Params("Transform") %>'); // Transformation
> }
> else
> {
> xsl.load('default.xsl');
> }
>
> // write results to output
> var transformedXml = xml.transformNode(xsl);
> document.write(transformedXml);
> </script>
> </pre>
>
> OK. So now the problem... When using some of the .NET controls (e.g.
> DataGrid) the HTML generated at runtime is not XHTML compliant therefore the
> xml.loadXML(ctrlText) call gets a parse error:
>
> Error Code: -1072896766
> Error Reason: A string literal was expected, but no opening quote character
> was found.
> Error Line: 1
>
> Since several of the attributes generated by the controls aren't contained
> in quote characters.
>
> Is there a way to change the behavior of the parser used by Microsoft.XMLDOM
> or change the way the HTML is generated by the framework WebControls? Or is
> there another way around this problem (besides writing my own pre-parser to
> clean the HTML)? Thanks.
>
>
>
> Yoga Weazel
> - Eagles may soar but weasels don't get sucked into jet engines.

 
Reply With Quote
 
 
 
 
yoga weazel
Guest
Posts: n/a
 
      05-04-2006
After more research I noticed that the problem isn't actually in the
generated HTML but in the use of the ctrl.innerHTML javascript property on
the HTML element. For some reason innerHTML seems to remove the " marks from
all attributes that do not contain whitespace. Now I need to figure out
why???

"yoga weazel" wrote:

> OK, so let me start with what I'm trying to accomplish.
>
> I have several screens with data displays using various controls (DataList,
> DataGrid...). I need to provide functionality so that the user can click a
> "Printable Version" button and a clean print formatted version of the data
> chosen is displayed in a new window. I'd prefer to do as much of this client
> side as possible so data services are not re-hit and not storing extraneous
> data in Session or View state.
>
> The approach I have currently is to provide a button which when clicked
> calls javascript to open the GenericPrintReport.aspx page with the ID of the
> original documents HTML element to print and the name of a XSL stylesheet to
> use in a new window. The body of the GenericPrintReport.aspx page contains
> the following javascript:
>
> <pre>
> <script language="javascript" type="text/javascript">
> //get data from parentwindow.ctrl
> var ctrl =
> window.opener.document.getElementById('<%=Request. Params("CtrlId") %>');
> //set DivData content to data
> var xml = new ActiveXObject("Microsoft.XMLDOM");
> xml.async = false;
> // make sure to remove any invalid XML (such as )
> var ctrlText = '<?xml version="1.0" encoding="UTF-16"?>' +
> ctrl.innerHTML.replace(/\ \;/gi, "");
> xml.loadXML(ctrlText); // Load XML Content
>
> document.write("<br>Error Code: ")
> document.write(xml.parseError.errorCode)
> document.write("<br>Error Reason: ")
> document.write(xml.parseError.reason)
> document.write("<br>Error Line: ")
> document.write(xml.parseError.line)
>
> // load the requested transformation
> var xsl = new ActiveXObject("Microsoft.XMLDOM");
> xsl.async = false;
> var xslFilename = '<%=Request.Params("Transform") %>';
> if (xslFilename.length > 0)
> {
> xsl.load('<%=Request.Params("Transform") %>'); // Transformation
> }
> else
> {
> xsl.load('default.xsl');
> }
>
> // write results to output
> var transformedXml = xml.transformNode(xsl);
> document.write(transformedXml);
> </script>
> </pre>
>
> OK. So now the problem... When using some of the .NET controls (e.g.
> DataGrid) the HTML generated at runtime is not XHTML compliant therefore the
> xml.loadXML(ctrlText) call gets a parse error:
>
> Error Code: -1072896766
> Error Reason: A string literal was expected, but no opening quote character
> was found.
> Error Line: 1
>
> Since several of the attributes generated by the controls aren't contained
> in quote characters.
>
> Is there a way to change the behavior of the parser used by Microsoft.XMLDOM
> or change the way the HTML is generated by the framework WebControls? Or is
> there another way around this problem (besides writing my own pre-parser to
> clean the HTML)? Thanks.
>
>
>
> Yoga Weazel
> - Eagles may soar but weasels don't get sucked into jet engines.

 
Reply With Quote
 
yoga weazel
Guest
Posts: n/a
 
      05-05-2006
Never figured out why but this is how IE implements the innerHTML property.
Therefore there wasn't really any work around except (for my use case) to
remove all attributes from the elements prior to loading into an XML
document. IMHO, innerHTML should return the exact HTML as it has been
encoded on the page but maybe that's just me ranting .

"yoga weazel" wrote:

> After more research I noticed that the problem isn't actually in the
> generated HTML but in the use of the ctrl.innerHTML javascript property on
> the HTML element. For some reason innerHTML seems to remove the " marks from
> all attributes that do not contain whitespace. Now I need to figure out
> why???
>
> "yoga weazel" wrote:
>
> > OK, so let me start with what I'm trying to accomplish.
> >
> > I have several screens with data displays using various controls (DataList,
> > DataGrid...). I need to provide functionality so that the user can click a
> > "Printable Version" button and a clean print formatted version of the data
> > chosen is displayed in a new window. I'd prefer to do as much of this client
> > side as possible so data services are not re-hit and not storing extraneous
> > data in Session or View state.
> >
> > The approach I have currently is to provide a button which when clicked
> > calls javascript to open the GenericPrintReport.aspx page with the ID of the
> > original documents HTML element to print and the name of a XSL stylesheet to
> > use in a new window. The body of the GenericPrintReport.aspx page contains
> > the following javascript:
> >
> > <pre>
> > <script language="javascript" type="text/javascript">
> > //get data from parentwindow.ctrl
> > var ctrl =
> > window.opener.document.getElementById('<%=Request. Params("CtrlId") %>');
> > //set DivData content to data
> > var xml = new ActiveXObject("Microsoft.XMLDOM");
> > xml.async = false;
> > // make sure to remove any invalid XML (such as )
> > var ctrlText = '<?xml version="1.0" encoding="UTF-16"?>' +
> > ctrl.innerHTML.replace(/\ \;/gi, "");
> > xml.loadXML(ctrlText); // Load XML Content
> >
> > document.write("<br>Error Code: ")
> > document.write(xml.parseError.errorCode)
> > document.write("<br>Error Reason: ")
> > document.write(xml.parseError.reason)
> > document.write("<br>Error Line: ")
> > document.write(xml.parseError.line)
> >
> > // load the requested transformation
> > var xsl = new ActiveXObject("Microsoft.XMLDOM");
> > xsl.async = false;
> > var xslFilename = '<%=Request.Params("Transform") %>';
> > if (xslFilename.length > 0)
> > {
> > xsl.load('<%=Request.Params("Transform") %>'); // Transformation
> > }
> > else
> > {
> > xsl.load('default.xsl');
> > }
> >
> > // write results to output
> > var transformedXml = xml.transformNode(xsl);
> > document.write(transformedXml);
> > </script>
> > </pre>
> >
> > OK. So now the problem... When using some of the .NET controls (e.g.
> > DataGrid) the HTML generated at runtime is not XHTML compliant therefore the
> > xml.loadXML(ctrlText) call gets a parse error:
> >
> > Error Code: -1072896766
> > Error Reason: A string literal was expected, but no opening quote character
> > was found.
> > Error Line: 1
> >
> > Since several of the attributes generated by the controls aren't contained
> > in quote characters.
> >
> > Is there a way to change the behavior of the parser used by Microsoft.XMLDOM
> > or change the way the HTML is generated by the framework WebControls? Or is
> > there another way around this problem (besides writing my own pre-parser to
> > clean the HTML)? Thanks.
> >
> >
> >
> > Yoga Weazel
> > - Eagles may soar but weasels don't get sucked into jet engines.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting Documents Into Clean Compliant HTML Fred HTML 2 05-03-2007 12:02 PM
Visual Studio 2005 html-view does not recognize the generated html-tag of a custom control Rolf Welskes ASP .Net 3 10-06-2006 06:49 PM
straight html or dom generated html objects faster? anagai Javascript 1 01-02-2006 09:27 PM
Is IE HTML 4.01 Compliant? Randy Yates HTML 4 03-20-2005 10:48 PM
html/css compliant derek giroulle HTML 60 06-26-2004 05:56 PM



Advertisments