Use the code below. I did it for my implementation of a flash replacer, and works like a charm.

input: an html node (node = document.getElementById("nodename"))
output: a perfectly valid XML reconstruction of the tree below the node. Works on all browsers.

parseTree = function ($node) {
        if ($node == null) return '';
        if ($node.nodeType == null) return '';

        var $result = '';

        var $chn = $node.childNodes;
        if ($chn != null) {
                var $lchnl = $chn.length;
                if ($lchnl > 0) {
                        var $zchild;
var $ynodeNamesWeIgnore = 'accessKey|coords|noWrap|dataFormatAs|disabled|dataSrc|object|dataFld|language|compact|contentEditable|inherit|tabIndex|align|clear|shape|charset|urn|rel|rev|dir|css';

                        for (var $j = 0; $j < $lchnl; $j++) {
                                $zchild = $chn[$j];
                                switch ($zchild.nodeType) {
                                        case 3:
                                                var $val = 
$zchild.nodeValue.replace(/[\t\n\r\f]*/g, '');
                                                if ($val.replace(/ */g, '') != 
'') {
                                                        $result += 
'<![CDATA['+$val+']]>';
                                                }
                                        break;

                                        case 1:
                                        var $tag_name = 
$zchild.nodeName.toLowerCase();
                                        $result += '<' + $tag_name;
                                        var $wnattr = $zchild.attributes;

                                        if ($wnattr != null) {
                                                var $xnal = $wnattr.length;

                                                if ($xnal) {
                                                        for (var $i = 0; $i < 
$xnal; $i++) {
                                                                var $qnodeName 
= $wnattr.item($i).nodeName;
if (($wnattr.item($i).value != 'null') && ($ynodeNamesWeIgnore.indexOf($qnodeName) == -1)) { $result += ' ' + $wnattr.item($i).nodeName.toLowerCase() + '="' +$wnattr.item($i).value +'"';
                                                                }
                                                        }
                                                }
                                        }

                                        if ($zchild.canHaveChildren || 
$zchild.hasChildNodes()){
                                                $result += '>';
                                                $result += parseTree($zchild);
                                                $result += '</'+$tag_name+'>';

                                        } else {
                                                $result += ' />';
                                        }
                                }
                        }
                }
        }

        return $result;
}



On Thu, 09 Nov 2006 16:45:17 -0300, Geoff Stearns <[EMAIL PROTECTED]> wrote:

I did some research into this a while back:
http://blog.deconcept.com/2006/02/27/using-alternate-content-flash/

end result: too much hassle to get the code you really want... you never know when browsers will update and break it in the future, or when some new obscure browser will come up and screw up your Flash content.

this other method of loading the entire page as xml is an interesting one, I know i've seen talk of things before, but i'm not aware of any big sites that actually do it.

for most 'big' projects, we'll just use a database, and output the page as html for the browser, and have an option to output it as clean xml for flash (or anything else that wants an xml feed of the page content). so then you don't have to worry about forward compatibility or rely on clientside conversion of SGML (or mangled html, etc.)



On Nov 9, 2006, at 2:39 PM, Ryan Potter wrote:

Not sure how complicated your html page is, but I have been playing with
the same idea but going at it a different way.  I just loaded the entire
page in as xml.  As long as the page is valid xhtml it works great.  I
realize it doesn't exactly answer your sgml question, but it should get you the same effect and it doesn't rewrite your code. Then you can either go
directly to the node or use xpath to navigate to it.

Just a thought.


-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Mike Keesey
Sent: Thursday, November 09, 2006 12:24 PM
To: flashcoders@chattyfig.figleaf.com
Subject: [Flashcoders] Grabbing data directly from the HTML page

I was playing around with the idea of passing data from an HTML page
directly into a Flash movie via Javascript/SWFObject. One thing I wanted
to try was sending the text that SWFObject replaces into the Flash
movie.

In Firefox this was pretty simple. E.g., if SWFObject was replacing the
contents of <div id="flash-content">...</div>, then all that was needed
was something in the Javascript code like:

var swfObj = new SWFObject(parameters);
swfObj.addVariable("HTML_flashContent", escape('<div
id="flash-content">' +
document.getElementById("flash-content").innerHTML.toString() +
"</div>"));

Then, in Flash, the root variable HTML_flashContent can be parsed into
an XML object. This has obvious benefits for search engine optimization,
as well as making it so a Flash and non-Flash version of a page can be
the exact same file.

Unfortunately, though, Internet Explorer and Safari return SGML, not
XHTML, for the innerHTML property (e.g., the above div tag gets
converted to <DIV id=flash-content>...</DIV> in IE). I made a
quick-and-dirty SGML to XHTML conversion tool to get around this, and it
seems to work so far.

My question is, has anybody else made an SGML to XHTML conversion tool
in ActionScript, or should I continue to refine mine and offer it for
public use when done?
―
T. Michael Keesey
Director of Technology
Exopolis, Inc.
2894 Rowena Ave. Ste. B
Los Angeles, California 90039


_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com
_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com



--
_____________
Marcelo Volmaro
_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to