7 Replies Latest reply on Oct 27, 2010 3:47 PM by aktell2007

    url with special characters

    Vie Bone

      Hello!

       

      I have an xml file with a list of url's.

       

      Some of these urls have special characters.

       

      When I load the xml in my flex project and try to launch the urls with special characters i got wrong urls strings.

       

      The url that I'm trying to launch is: http://www.muypequeño.com/

       

      An the url tha i got is: http://www.muypeque%F1o.com/

       

      This is a fragment of my xml:

       

      <?xml version="1.0" encoding="utf-8"?>

       

      <categories>

       

           <category name="Interactive" id="0">

       

                <project id="0" name="Actualizegroup" url="http://www.actualizegroup.com">

                     <img url="img/actualize/actualize1.jpg" />

                     <img url="img/actualize/actualize2.jpg" />

                     <img url="img/actualize/actualize3.jpg" />

                     <img url="img/actualize/actualize4.jpg" />

                     <img url="img/actualize/actualize5.jpg" />

                     <img url="img/actualize/actualize6.jpg" />

                     <text> asdf asdf asfasdf asdf asdf asdf asdf adsf asdf asf asdf asf sf asf asf asf asf as asdf asf asf asf asdf asdf asf asf asf asf asf asf af af af af asd asdf asdfsas </text>

               </project>

       

       

                <project id="2" name="Pequeño" url="http://www.muypequeño.com/">

                     <img url="img/pequeno/pequeno1.jpg" />

                     <img url="img/pequeno/pequeno2.jpg" />

                     <img url="img/pequeno/pequeno3.jpg" />

                     <img url="img/pequeno/pequeno4.jpg" />

                     <text>

      asdf asdf asfasdf asdf asdf asdf asdf adsf asdf asf asdf asf sf asf asf asf asf as asdf asf asf asf asdf asdf asf asf asf asf asf asf af af af af asd asdf asdfsas

                     </text>

                </project>

       

       

           </category>

       

      </categories>

       

      I take the url property:

       

      _url = xmlData.category[_category].project[_project].@url;

       

      An this function lauch the url:

       

      protected function launchURL():void

      {

           var url:String = String(_url);

           var request:URLRequest = new URLRequest(url);

           try {

                navigateToURL(request, '_blank');

           } catch (e:Error) {

           trace("Error occurred!");

            }

       

      }

       

      Can anyone help me please????

       

      Thanks!!!!!

        • 1. Re: url with special characters
          aktell2007 Level 1

          Hi there,

           

          Special characters requiere in Xml this <url><![CDATA[http://www......com]]></url>

          so I think you have to write the Xml a little different !

          regards aktell2007

          • 2. Re: url with special characters
            rtalton Level 4

            My 1,000th post. Yay!

             

            You need to use the HTML Entity (&#241;) number instead of the hex code (F1).

             

            XML snippet:

                    <project
                        id="2" name="Peque&#241;o"
                        url="http://www.muypequeño.com/">

             

            Code to retrieve/handle the XML:

             

                <mx:HTTPService
                    id="xmlData"
                    result="handleResult(event)"
                    resultFormat="e4x"
                    url="data/myData.xml"/>

             

             

                        private function handleResult(event:ResultEvent):void {
                            myXmlData = event.result as XML;
                            _url = myXmlData.category[0].project[1].@url;
                        }

             

            Code to launch the URL:

                        private function launchURL():void {
                            var url:String = String(_url);
                            var request:URLRequest = new URLRequest(url);
                            navigateToURL(request, '_blank');
                        }

            • 3. Re: url with special characters
              Vie Bone Level 1

              Thanks both for your answers!!!

               

              unfortunately I can't make it work.

               

              If i use CData on my xml file, it doesn't work, it doesn't load any content.

               

              And I can not make it work doing what rtalton said, I don't now why but the xml doesn't load. I am working with FB 4. And I'm writing my code in a s:group component that loads all the works from the xml file.

               

              I'm just trying to manage all the xml with as3, all work fine but when I use the special character ñ, it doesn't work.

               

              there is any other way to load special characters????

               

              Thanks a lot.

              • 4. Re: url with special characters
                rtalton Level 4

                Without seeing how you retrieve the data, it's impossible to troubleshoot what is wrong.

                 

                The following code does work; it opens your web site, complete with the Flash Player run-time error it throws.

                See if you can adapt it to your scenario:

                 

                XML file (adapted from your xml sample):

                 

                <?xml version="1.0" encoding="utf-8"?>

                <categories>

                 

                <category

                id="0" name="Interactive">

                <project

                id="0" name="Actualizegroup"

                url="http://www.actualizegroup.com">

                <img url="img/actualize/actualize1.jpg"/>

                <img url="img/actualize/actualize2.jpg"/>

                <img url="img/actualize/actualize3.jpg"/>

                <img url="img/actualize/actualize4.jpg"/>

                <img url="img/actualize/actualize5.jpg"/>

                <img url="img/actualize/actualize6.jpg"/>

                <text>asdf asdf asfasdf asdf asdf asdf asdf adsf asdf asf asdf asf sf asf asf asf asf as asdf asf asf asf asdf asdf asf asf asf asf asf asf af af af af asd asdf asdfsas </text>

                </project>

                <project

                id="2" name="Peque&#241;o"

                url="http://www.muypequeño.com/">

                <img url="img/pequeno/pequeno1.jpg"/>

                <img url="img/pequeno/pequeno2.jpg"/>

                <img url="img/pequeno/pequeno3.jpg"/>

                <img url="img/pequeno/pequeno4.jpg"/>

                <text>asdf asdf asfasdf asdf asdf asdf asdf adsf asdf asf asdf asf sf asf asf asf asf as asdf asf asf asf asdf asdf asf asf asf asf asf asf af af af af asd asdf asdfsas</text>

                </project>

                </category>

                </categories>

                 

                 

                the application:

                 

                <?xml version="1.0" encoding="utf-8"?>

                <mx:Application

                xmlns:mx=http://www.adobe.com/2006/mxmlabsolute">

                creationComplete="xmlData.send()"

                layout="

                 

                 

                 

                <mx:Script>

                <![CDATA[

                 

                import mx.rpc.events.ResultEvent;

                 

                private var myXmlData:XML;

                 

                private var _url:String;

                 

                 

                private function handleResult(event:ResultEvent):void {

                myXmlData = event.result

                as XML;

                _url = myXmlData.category[0].project[1].@url;

                }

                 

                 

                private function launchURL():void {

                 

                var url:String = String(_url);

                 

                var request:URLRequest = new URLRequest(url);

                navigateToURL(request,

                '_blank');

                }

                ]]>

                 

                </mx:Script>

                 

                 

                 

                <mx:HTTPService

                id="

                xmlData"

                result="handleResult(event)"

                resultFormat="

                e4x"data/myData.xml"/>

                url="

                 

                 

                 

                <mx:Button

                click="launchURL()"

                label="

                launch url"

                y="

                221"

                x="

                82"/>

                </mx:Application>

                • 5. Re: url with special characters
                  aktell2007 Level 1

                  I'm working on a large Test Application at the moment which is using thausands of special characters with NO problems at all !!!

                  I found the way that the other developer discribed did not work for me because as sone as I was using say %amp; it cut of after the semi colon (;).

                  So I use only the CData which I can see in your code will not work as easy as, as it would have to be re writtena little !

                   

                  Say you would have nodes like this:

                   

                  <images urlID="1"> // You cant use the CDATA in the (urlID="") and that is where you have your special characters !

                   

                       <urlId><!CDATA[ Here would go the text with special characters. ]]></urlID>

                       <image><!CDATA[ Here would go the text with special characters. ]]></image>

                   

                  <images

                   

                  regards aktell2007

                  • 6. Re: url with special characters
                    rtalton Level 4

                    @aktell: I think you may have meant " &amp; ", instead of " %amp; "  (an ampersand character) ?

                    This does not work in my example because  &amp;  is an entity name, not an entity number. For instance, the entity number for an ampersand is &#38;

                     

                    The code I posted will work with entity numbers, which is what I believe the OP is aiming at. This eliminates the need for the CDATA tags.

                    • 7. Re: url with special characters
                      aktell2007 Level 1

                      Thanks, my mistake just a typo, but thanks anyway.