Ted Patrick > { Events & Community } > Adobe Systems


XML Resolver 1.05 (F7 compatibility)

Bob Roswell reported an error to me regarding XML Resolver. I took a look and sure enough the library wasn't F7 compatible. Here is a new compatible version.&

XML Resolver extends the XML object to support name based editing of XML Nodes. It makes it really easy to edit and read XML documents. Best part is that there is no reparsing of the XML document, ever! Resolver uses __resolve to virtually remap the path resolution of the XML Object. When you request a name based path, the __resolve function kicks in and returns the correct item if it exists. If you are setting the value, it will extend the XML object in place.

Download XML RESOLVER 1.05

Here is an example of its use:

x = new XML("<a>blah<t/><t>Hello World</t><t age='1'/></a>")




//GET REQUESTS
trace(x.a) //return XMLnode
trace(x.a.t[2]) //return XMLNode
trace(x.a.t[2].attribute.age) //return attribute value
trace(x.a._value) //return XMLNode
trace(x.a.t[1]._value) //return TextNode Value
trace(x.a.t[2].attribute) //return Attribute array
trace(x.a._node) //return XMLNode
trace(x.a.t[1]._node) //return XMLNode



//SET REQUESTS
x.a._value = "blah22" //add/edit TextNode Value
x.a.t[1]._value = "Hellllo World" //add/edit TextNode Value
x.a.t[2]._value = "222 World" //add/edit TextNode Value
x.a.t[0]._attr.dog = "fido" //add/edit attribute Value
x.a.t[2]._attr.age = 34 //add/edit Attribute Value
x.a._node = "<superNode/>" //add Node
x.a.t[0]._node = "<subtNode/>" //add Node


(Credit to Arul for AS color!)

The library was written for Flash 5 originally and migrated to Flash 6 in 2003. There were 2 errors in the library that were fixed in this release.

1. Case sensitivity is now correct. XMLNODE is now XMLNode.

2. The AS2 compiler doesn't like you modifying classes at runtime and doesn't allow using 'prototype' or '__proto__' in code compiled for AS2. There is a hack for this that works really well, simply evaluate the keywords as strings and everything works just fine.

XMLNode["prototype"].__resolve = function(){}


XMLNode["prototype"]["__proto__"] = XMLNodeSubClass["prototype"]


If you find any bugs just drop me an email and I will see what I can do. Thank Bob for reporting the error, glad I could help.

Cheers,

Ted ;)

7 Responses to “ XML Resolver 1.05 (F7 compatibility) ”

  1. # Anonymous Anonymous

    Great Stuff. Super usefull !  

  2. # Anonymous Anonymous

    very cool
    and very usefull.
    already use it )  

  3. # Anonymous Anonymous

    Hey Ted, Aral here... Great class! One thing: It appears that you need to access attributes not with "attribute" but _attr when getting them too. I couldn't see support for "attribute" in a cursory glance at the code.  

  4. # Blogger Ted Patrick

    XMLResolver adds items to XMLNode and XML but does not remove anything. You should be able to access any node property/attribute/child identically as before. If you find one that does not work, this is an error in the software.

    Ted ;)  

  5. # Anonymous Anonymous

    How do we treat CDATA using this wonderful thing?  

  6. # Anonymous Anonymous

    Hi Ted, tx. great stuff. But shouldn't the "attribute" in the example be "attributeS"?
    Cheers,

    Ben Smeets  

  7. # Blogger Ted Patrick

    Ben,

    It should be 'attributes' above that is a typo. The code base has this correct, my blog entry is flawed.

    Sorry for the error.

    Ted :)  

Post a Comment



© 2008 Ted On Flash