Thanks Paul, let me know what you think

I was talking to Chris Allen about the new recursion method and he came up with the thought to check for escape characters - if found, add the CDATA tag.

Now, the interesting thing about this is, if I do this, and you convert a string to XML, the characters will be escaped for you.  What's more, if I don't look for characters like "<" or ">" and they're in your property without CDATA tags, it breaks the result.  So, I'll be adding that this morning.

The thing about when you pass in CDATA to Flash, it escapes the <> characters (and others) anyway - so, no matter what, you still have to deal with decoding the HTML encoding.  Make sense?

IE:  these 2 samples show up identical when loaded into Flash:
<root><someNode><![CDATA[Some text > <that needs to be escaped & what not...]]></someNode></root>
<root><someNode>Some text &gt; &lt;that needs to be escaped &amp; what not...</someNode></root>

One other thing Chris suggested was a mapToObject() method

XMLObject.mapToObject(xmlToConvert, targetObject);

On 3/3/06, paul | WE.BYTE! <[EMAIL PROTECTED]> wrote:
thanks john!

i will check it out .


Am 02.03.2006 um 22:12 schrieb John Grden:

sorry, 105 is old, get version 106:

http://mirror1.cvsdude.com/trac/osflash/xray/browser/downloads/FLASC/XMLObject.as

On 3/2/06, John Grden <[EMAIL PROTECTED] > wrote:
ok, I've written a completely new recursion method to build an xml object and posted it:

http://mirror1.cvsdude.com/trac/osflash/xray/browser/downloads/FLASC/XMLObject.as?rev=105

To convert from an object to XML, use the new getXML(object, ["root name"]) method;
To convert from an XML to Object, use the new getObject(XML) method:

Use this code in a new FLA along with xray to test. 

import it.sephiroth.XMLObject;
var x2o:XMLObject = new XMLObject();

var returnXML:XML;
var convertedObj:Object;

var obj:Object = new Object();
obj.prop_0 = "Test String";
obj["child_0"] = {};
obj["child_0"].prop_0 = new Array("xray", "red5", "flasc");
obj["child_0"].prop_1 = true;
obj["child_0"].prop_2 = 12;

tt("obj before", obj)

function convertObjectToXML(p_obj:Object):XML
{
    var x2o:XMLObject = new XMLObject();
    var xmlDoc:XML = x2o.getXML(p_obj, "EXPORT");

    return xmlDoc;
}

function convertXMLToObject(p_xml:XML):Object
{
    var x2o:XMLObject = new XMLObject();
    var obj:Object = x2o.getObject(p_xml);

    return obj;
}

tt('========');
returnXML = convertObjectToXML(obj);
tt(parseXML(returnXML));

tt('========');
convertedObj = convertXMLToObject(returnXML)
tt("convert back to obj", convertedObj);



function parseXML(p_xml:XML):String
{
    str = p_xml.toString();
    str = str.split("><").join(">\n<");
    return str;
}

from here, i put it in with Flasc's export/import and it worked great right out of the box.  I didn't have to change a thing. 

I'm sure that the new recursion method for object -> xml can be extended/added to, but in it's basic form, it works well.

Thoughts?


On 3/2/06, John Grden < [EMAIL PROTECTED]> wrote:
Yep, that's right ;)

In running an initial test with the class on it's own however, I see that the object conversion was having problems, and i think I see why.  I'm reworking the recursion methods right now.


On 3/2/06, Aaron Smith <[EMAIL PROTECTED] > wrote:
when you parse back to xml. pass the first node of the object.. (   xml
= new XMLObject().parseObject(obj.firstnode, 'firstnode');    )

John Grden wrote:

> yeah, someone mentioned that issue, let me mess with it for a few
> minutes and get back to you ;)
>
> On 3/2/06, *paul | WE.BYTE!* < [EMAIL PROTECTED]
> <mailto: [EMAIL PROTECTED]>> wrote:
>
>     hi john,
>     forget about the shift/pop thing. everything works well as it is -
>     concerning node-ordering.
>     anyway there seems to be a problem with parsing from object to XML.
>
>     when you parse xml->object and then back to XML. the first node of
>     the resulting XML appears twice.
>     any ideas?
>
>     ahoi, paul
>
>
>
>     Am 01.03.2006 um 14:49 schrieb John Grden:
>
>>     Good question Paul, I'd have to look through the code to see why
>>     it extends XML.  Sepy is the original writer ;)
>>
>>     As for the shift/pop - i'll take a look - does it work better for
>>     you?  I can see what you're talking about.
>>
>>     On 3/1/06, *paul | WE.BYTE!* < [EMAIL PROTECTED]
>>     <mailto: [EMAIL PROTECTED]>> wrote:
>>
>>         hi john,
>>         first of all: thanks for sharing your code. great!
>>         i just tried your XMLObject and it works realy good for me.
>>         but i noticed, that the order of the xml-tags gets inverted,
>>         when parsing xml<->object.
>>         i think, changing
>>         node = nodes.shift();
>>         to
>>         node = nodes.pop();
>>         in line 125 would be better
>>
>>         and i have a question: why does XMLObject extend XML? i
>>         dont't understand the reason for that?
>>
>>         ahoi,
>>         paul
>>
>>
>>
>>         Am 28.02.2006 um 06:02 schrieb John Grden:
>>
>>>         http://mirror1.cvsdude.com/trac/osflash/xray/browser/downloads/FLASC/XMLObject.as?rev=104
>>>         < http://mirror1.cvsdude.com/trac/osflash/xray/browser/downloads/FLASC/XMLObject.as?rev=104>
>>>
>>>         Sorry, already made a revision ;)
>>>
>>>         On 2/27/06, *John Grden * < [EMAIL PROTECTED]
>>>         <mailto: [EMAIL PROTECTED]>> wrote:
>>>
>>>             Well, thanks to Ben Jackson and everyone else including
>>>             Alessandro himself, I was able to finally get the
>>>             XMLObject class working back and forth cleanly.
>>>
>>>             In creating and import/export for FLASC, it was critical
>>>             to make sure it was brought back in exactly the way I
>>>             stored the projects.  After a while, there were a few
>>>             items to add/fix with the latest version, but I think
>>>             we're there!
>>>
>>>             1.  Instead of using split(), i added a counter to go
>>>             through the array object.  Split was hacking my original
>>>             array objects ;)
>>>
>>>             2.  Line 59, instead of doing a for..in loop, I changed
>>>             it to a regular for loop for index based looping of an
>>>             array.
>>>
>>>             3.  Line 131, added boolean casts to make the conversion
>>>             complete from XML to Object ;)
>>>
>>>             and of course, with the changes that Ben made for
>>>             getting rid of "data" properties, it's looking pretty
>>>             close to being complete.
>>>
>>>             I now have a complete class that does conversion back
>>>             and forth between XML and Objects - and so far, it works
>>>             really well.
>>>
>>>             You can check it out here:
>>>             http://mirror1.cvsdude.com/trac/osflash/xray/browser/downloads/FLASC/XMLObject.as?rev=102#L131
>>>
>>>             --
>>>             John Grden - Blitz
>>>
>>>
>>>
>>>
>>>         --
>>>         John Grden - Blitz
>>>         _______________________________________________
>>>         osflash mailing list
>>>         [email protected] <mailto: [email protected]>
>>>         http://osflash.org/mailman/listinfo/osflash_osflash.org
>>>         < http://osflash.org/mailman/listinfo/osflash_osflash.org >
>>
>>
>>
>>         _______________________________________________
>>         osflash mailing list
>>         [email protected] <mailto: [email protected]>
>>         http://osflash.org/mailman/listinfo/osflash_osflash.org
>>
>>
>>
>>
>>
>>     --
>>     John Grden - Blitz
>>     _______________________________________________
>>     osflash mailing list
>>     [email protected] <mailto: [email protected]>
>>     http://osflash.org/mailman/listinfo/osflash_osflash.org
>
>
>
>     _______________________________________________
>     osflash mailing list
>     [email protected] <mailto:[email protected]>
>     http://osflash.org/mailman/listinfo/osflash_osflash.org
>
>
>
>
>
> --
> John Grden - Blitz
>
>------------------------------------------------------------------------
>
>_______________________________________________
>osflash mailing list
>[email protected]
> http://osflash.org/mailman/listinfo/osflash_osflash.org
>
>

_______________________________________________
osflash mailing list
[email protected]
http://osflash.org/mailman/listinfo/osflash_osflash.org



--
John Grden - Blitz



--
John Grden - Blitz



--
John Grden - Blitz
_______________________________________________


_______________________________________________
osflash mailing list
[email protected]
http://osflash.org/mailman/listinfo/osflash_osflash.org





--
John Grden - Blitz
_______________________________________________
osflash mailing list
[email protected]
http://osflash.org/mailman/listinfo/osflash_osflash.org

Reply via email to