Creating an XML string in Flex (AS3) by using DOM functions

177

Solution 1

Stay away from XMLNode if you're using as3, it's a legacy class, the new XML and XMLList classes are the ones that support the excellent E4X. Using those it's as easy as this:

var myXML:XML = <slide />;
myXML.@thumb="http://www.thumbs.com/thumb.jpg";
myXML.@type="static";
myXML.@blah="bleh";
trace("myXML", myXML.toXMLString());

The @ means it's an attribute, not using that would add child nodes instead.

Solution 2

This would probably be easier:

var thumb:String = "http://www.thumbs.com/thumb.jpg";

var type:String = "static";

var blah:String = "bleh";

var xml:XML =        

          <Relyon>
             <slide thumb={thumb} type={type} blah={blah} />
          </Relyon>;


trace( xml.toXMLString() );

//traces out

 <Relyon>
     <slide thumb="http://www.thumbs.com/thumb.jpg" type="static" blah="bleh"/>
 </Relyon>
Share:
177
Abhishek Yadav
Author by

Abhishek Yadav

Updated on June 04, 2022

Comments

  • Abhishek Yadav
    Abhishek Yadav about 2 years

    I'm new to rails programming and i'm trying to use rails status code when raising a grape exception but my tests are failing. I couldn't find any example on grape documentation so this may be impossible.

    I want to know if it is possible and if not, why so?

    This works:

    rescue_from Example::IsExampleWorking do |_e|
        error!({ messages: ["Example is not working because it was not found"] }, 404)
    end
    

    But this does not:

    rescue_from Example::IsExampleWorking do |_e|
        error!({ messages: ["Example is not working because it was not found"] }, :not_found)
    end
    

    My test is:

    it "return a 404 Not Found status" do
      expect(response).to have_http_status(:not_found)
    end
    

    edit: guys, I forgot to mention that the error message from he test is

    undefined method `to_i' for :not_acceptable:Symbol
    Did you mean?  to_s
    

    But I didn't find any documentation on grape's docs to make sure they accept only integer as second param.

    Thank you :)

    • theUtherSide
      theUtherSide about 5 years
      Hi, welcome to SO. Can you please also post the code you are testing.
    • Martin Zinovsky
      Martin Zinovsky about 5 years
      Yeah. You might create an issue in grape repo with this question. One of the solutions would be to use Rack::Utils::SYMBOL_TO_STATUS_CODE[:not_found]. I would prefer just a number in that case :)