A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: Using the XML object to load HTML

  1. #1
    Senior Member
    Join Date
    Jan 2001
    Posts
    191

    Using the XML object to load HTML

    Ok, I'm doign a little bit of work with AJAX, and thought I might be able to use the ExternalInterface of Flash 8 to pull data from one spot to another as needed.

    The problem is loading content. I can use the XML object to load data, and if it's just text or some halfway written HTML, the status will of course be less than 0, but the success flag will be true.

    Now, when I use the toString() method for XML, it can load some, but not all HTML. for instance, table tags blow it up.

    Is there a better method for loading chunks of text/html to flash? Thanks for your help!

  2. #2
    Flash Gordon McUsher's Avatar
    Join Date
    Mar 2001
    Location
    Krautland
    Posts
    1,560
    What exactly do you mean by "blow it up"...
    As i use the method myself and it works fine for me.

    You just have to make sure that your html comes as well formed xml
    a <br> with no closing tag would make the flash internal xml parser to
    stop parsing...
    so you would have to use <br/>
    My letters on the F1 key have faded, how are yours today?

  3. #3
    Senior Member dlowe93's Avatar
    Join Date
    Aug 2001
    Location
    Stumptown
    Posts
    621
    Quote Originally Posted by Nebulus
    Ok, I'm doign a little bit of work with AJAX, and thought I might be able to use the ExternalInterface of Flash 8 to pull data from one spot to another as needed.

    The problem is loading content. I can use the XML object to load data, and if it's just text or some halfway written HTML, the status will of course be less than 0, but the success flag will be true.

    Now, when I use the toString() method for XML, it can load some, but not all HTML. for instance, table tags blow it up.

    Is there a better method for loading chunks of text/html to flash? Thanks for your help!
    You need to wrap in in a CDATA tag. Like this:

    Code:
    <pagedata><![CDATA[My <b>html content</b> goes here!!!]]></pagedata>
    The CDATA tells the xml parser to ignore any formatting within the tags and pass it along without trying to do anything with it.

    Note, you can't (as far as i know) pass html formatting in a attribute, only within a node.

    Hope this helps.

    d.
    dlowe93

  4. #4
    Senior Member
    Join Date
    Jan 2001
    Posts
    191
    Thanks for the tips guys. The issue is that I won't be using a complete HTML page, and I can't guarantee the integrity of the HTML. If you're familiar with AJAX, you're loading up chunks of content from external sources into DIV tags on the base page.

    I also can't wrapper the content in a CDATA tag since we're harvesting data from multiple locations on the server from existing pages.

    As an example, check www.backbase.com and run through some of their demos. Basically what i'm trying to do is use JS to harvest form data in a DIV tag and pass the parameters to Flash. The SWF can then load the "XML" from the server. when it gets the data back, it'll then send it back to the base page so it can be processed.

    Any ideas?

  5. #5
    Senior Member dlowe93's Avatar
    Join Date
    Aug 2001
    Location
    Stumptown
    Posts
    621
    Hmm, that's a tough one. The obvioius answer is to use something on the backend to preformat the xml so it plays nice with Flash. Flash is not overly robust in it's Flash tools. However, it's easy to say "preformat the xml," but i have no idea how to do it.

    Rather than xml, would it work to pass url-enoded strings? Or even url encoded strings within the xml? That sould solve the tags breaking the xml, and you could then unescape the strings once you get them into Flash.

    You could also try XPath:

    http://www.xfactorstudio.com/ActionScript/AS2/XPath/

    I know several developers who swear by this, but i've never used it. Most of our webfront/back-end interface is done through Remoting, so we don't really need to use very robust xml tools.

    Good luck,

    d.
    dlowe93

  6. #6
    Senior Member
    Join Date
    Jan 2001
    Posts
    191
    Pretty sweet, I'll check it out. Well, in addition to passing XMl, I'm trying to pass full content - forms, JS, basically anything that can be in an HTML page through the ExternalInterface.

    What I have found is that if on the back end I add CDATA tags as a header/footer, then I can use the content as a node value. Then I can escape it, send it to JS where it unescapes the data and stuffs it in the DIV tag of choice. Here's my proof of concept: www.nebulus.org/flajax

  7. #7
    Senior Member dlowe93's Avatar
    Join Date
    Aug 2001
    Location
    Stumptown
    Posts
    621
    Yeah, url-encoding has saved me on many an occasion.

    I would love for Flash to become a lot more robust in it's xml-handling, but i also think that MM's plan was to encourage users to move to a more robust data platform (Remoting or what ever else was coming down the line).

    It will be interesting to see what Adobe does, since they aren't really a server/platform company.

    d.
    dlowe93

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center