Results 1 to 3 of 3

Thread: reliable html to string via Javascript

  1. #1
    Join Date
    Mar 2006

    Angry reliable html to string via Javascript

    I have tried to search for a solution to this problem before posting here but anything related to strings kicks back a million reference pages and when I start trying to get any more specific everything I find is about writing to the DOM when I need to just read it out!

    I was using innerHTML and passing it through as well formatted XML to Flash for parsing. This was working great in Firefox and I thought I was nearly finished when I had the bright idea of testing in IE7. FAIL! Malformed XML could not be parsed.
    <DIV id=projects>
    <div id="projects">
    How can I get the equivalent string return for my HTML structure in IE7? innerHTML is not going to work as IE7 is stripping information and reformatting my text.

    This is a sample of what I am using now:

  2. #2
    Join Date
    Apr 2003
    Afaik you will have to reformat the string to XML using regular expressions.
    At least 98% of internet users' DNA is identical to that of chimpanzees

  3. #3
    Join Date
    Mar 2006
    Well I banged on some regex stuff for a while and what follows seems to work fairly well by first breaking the xml and then patching it again. I wish there was an easier way to wrap attributes in quotes but this seems to be working.

    var dataString = document.getElementById("pageContainer").innerHTML;
    if(navigator.appName == "Microsoft Internet Explorer")
    	dataString = dataString.replace(/\bDIV id=+\b/g,"div id=\"");
    	dataString = dataString.replace(/\bDIV class=+\b/g,"div class=\"");
    	dataString = dataString.replace(/\b>/g,'\">');
    	dataString = dataString.replace(/\bDIV\">/g,'div>');
    	dataString = dataString.replace(/.image=/g,"\" image=");
    	dataString = escape(dataString);

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center

Recent Articles