Fx{r} is trying to start the Fx{r} Community! Please join our group on Adobe Groups following this link: http://groups.adobe.com/groups/ab29539ab9.
Fx{r} is now on Twitter too. Follow us @ twitter.com/fx_r!
« FlashPaper @ The End Of Its Life
» Image Events Dispatch Order

ActionScript, Debug, Errors, MXML, Web Service, xml

HTTPService Requesting XML from FeedBurner Gets Parsed with XSL in IE Browser

Andrei Ionescu | 10.09.08 | 1 Comment

These day I’ve been fighting with this issue: trying to get the Flexer XML feed from FeedBurner into a Flex application. As many of you may know FeedBurner serves the XML with an XSL and browsers that know XSL will parse it and display it in a nicer way that a simple xml.

The problem is that I use IE 7 for development and debugging which is not the best thing to do. So I did a small application to read a feed from an specified URL.

At run-time in IE I always got this error (is displayed after clicking on Get HTTPService button with format=”xml” unchecked - ONLY IN IE) :

Error #1085: The element type “link” must be terminated by the matching end-tag “</link>”.

When I did look in the message.body property of the fault event I was shocked to see that what I get is a HTML page - NOT an XML one. HTML pages do have tags that do not close like “link” tag used to add CSS to the page.

I tried every property of HTTP service, some headers and content types, I also made a URLRequest approach but the same thing.

In the other browser the things were different. Everything was OK. I was requesting for an XML I got an XML. That is great! But I still need to make it work in IE.

It seems that IE is different… It parses everything before sending it to the flash player. I’m not a hundred percent sure if is correct what I am saying but that is how I explained it. Then a “brilliant” colleague of mine found the needed thing - in the request add format = “xml” as request. It seems that when format = “xml” is set FeedBurner sends another header back to IE browser which will tell the browser not to parse the XML with XSL. So, I did it like below (starting with line 11 in the whole code):

testGetUrl.send((useFormat.selected ? {format:'xml'} : {}))

Notice {format:”xml”} object which holds our request parameter.

Here is the whole code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
    layout="absolute" width="370" height="310">
    <mx:HTTPService id="testGetUrl" 
        fault="handleFault(event)"
        result="handleResult(event)"
        resultFormat="e4x"
        url="{geturl.text}">
    </mx:HTTPService>
    <mx:Button x="10" y="40" label="Get HTTPService" 
        click="testGetUrl.send(
            (useFormat.selected ? {format:'xml'} : {})
        )"/>
    <mx:Button x="137" y="40" label="Get URLRequest" 
        click="handleGetUrlRequest(event)"/>
    <mx:CheckBox id="useFormat" x="10" y="70" 
        label="Use format=&quot;xml&quot;"/>
    <mx:TextInput id="geturl" x="10" y="10" 
        width="350" text="http://feeds.feedburner.com/flexer/"/>
    <mx:TextArea id="geturlresp" x="10" y="96" 
        width="350" height="204"/>
    <mx:Script>
        <![CDATA[
            import mx.rpc.events.ResultEvent;
            import mx.rpc.events.FaultEvent;
 
            private function handleFault(e:FaultEvent):void
            {
                var temp:String = e.fault.faultString.toString() + 
                    "\n\n" + e.message.body.toString();
                geturlresp.text = "HTTPSERVICE FAULT!\n\n" + temp;
            }
 
            private function handleResult(e:ResultEvent):void
            {
                var temp:* = e.result;
                geturlresp.text = "HTTPSERVICE RESULT!\n\n" + 
                    e.result.toString();
            }
 
            private function handleGetUrlRequest(e:MouseEvent):void
            {
                var urlReq:URLRequest = new URLRequest(geturl.text + 
                    (useFormat.selected ? "/?format=xml" : ""));
 
 
 
                urlReq.method = URLRequestMethod.GET;
                var urlLoader:URLLoader = new URLLoader(urlReq);
                urlLoader.addEventListener(
                    Event.COMPLETE, handleUrlRequestComplete);
            }
 
            private function handleUrlRequestComplete(e:Event):void
            {
                var tmp:* = e.currentTarget.data;
                geturlresp.text = "URLREQUEST COMPLETE!\n\n" + 
                    tmp.toString();
            }
        ]]>
    </mx:Script>
</mx:Application>

I made also a URLRequest option so you can see that is something that is not happening only when using HTTPService.

Again… I want to specify that the error appears only on IE.

We may write new articles on this as we will found more about it. ;) So keep reading us.

Share and Enjoy:
  • TwitThis
  • Technorati
  • StumbleUpon
  • del.icio.us
  • NewsVine
  • Reddit
  • Digg
  • Furl
  • co.mments
  • blogmarks
  • Slashdot
  • description
  • Taggly
  • YahooMyWeb
  • connotea
  • Webride




Tags: , , ,

This post was written by Andrei Ionescu

Views: 3881

related

1 Comment

have your say

Add your comment below, or trackback from your own site. Subscribe to these comments.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

:

:


« FlashPaper @ The End Of Its Life
» Image Events Dispatch Order