ASP.NET 2.0 generated HTML not XHTML/XML compliant

Discussion in 'ASP .Net Web Controls' started by yoga weazel, May 4, 2006.

  1. yoga weazel

    yoga weazel Guest

    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.
     
    yoga weazel, May 4, 2006
    #1
    1. Advertising

  2. yoga weazel

    yoga weazel Guest

    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.
     
    yoga weazel, May 4, 2006
    #2
    1. Advertising

  3. yoga weazel

    yoga weazel Guest

    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.
     
    yoga weazel, May 4, 2006
    #3
  4. yoga weazel

    yoga weazel Guest

    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.
     
    yoga weazel, May 5, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kevin Lawrence

    nowrap not XHTML 1.0 compliant

    Kevin Lawrence, Jan 23, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    10,072
    Rob Roberts
    Jan 24, 2006
  2. =?Utf-8?B?RGlmZmlkZW50?=

    Looking for XHTML compliant text editor

    =?Utf-8?B?RGlmZmlkZW50?=, Jan 31, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    865
    Smithers
    Feb 1, 2006
  3. Amil Hanish
    Replies:
    0
    Views:
    376
    Amil Hanish
    Mar 12, 2007
  4. Amil Hanish

    autocomplete=off is not XHTML compliant

    Amil Hanish, Sep 4, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    6,013
    Jesse Houwing
    Sep 4, 2007
  5. Andrew Poulos

    SWF methods and standard compliant XHTML

    Andrew Poulos, Dec 19, 2005, in forum: Javascript
    Replies:
    0
    Views:
    77
    Andrew Poulos
    Dec 19, 2005
Loading...

Share This Page