2

I am using E4X to bind some values from xml in flex 3.

There is a problem when xml tag's (or attribute's) name has special character in it: having xml content

var xml:XML = <tag>
    <special-name att="val" />
</tag>

special-name could not be accessed using xml.special-name.@att because it is interpreted as subtraction, on the other hand using square bracket notation xml['special-name'].@att breaks binding chain.

Is there an elegant way to solve this (like special language syntax) without writing custom binding setters and listeners?

Jonas
  • 2,910
  • 2
  • 26
  • 36

1 Answers1

1

Would the child() function of the XML class work for you in that situation? I can't check it right now, but child() returns an XMLList and that should work for binding.

Alternatively, couldn't you just replace all "problematic" node names (storing the original names in a Dictionary with the replacement names being the keys) and then do the binding, simply avoiding the issue altogether?

Baelnorn
  • 940
  • 8
  • 17
  • Actually, calling child() will break binding, because binding only works with properties (as opposed to method calls). However, using child() will make compiler happy (removes warnings) for not using bracket notation. I don't fully understand how are you suggesting to replace names? – Jonas Apr 21 '10 at 07:07
  • If the XML wasn't too large, you could use String manipulation to replace the problematic names with ones that do work. I know that you generally should not be doing String manipulation on XML (don't beat me please ^^), but that could help you out. I suggested storing the replaced names so that you could switch them back in case you'd need to store/send the XML to a server after using it. – Baelnorn Apr 21 '10 at 21:36
  • I guess I'm not that desperate about this to even perform string replacing.. because it's not trivial to replace tag names excluding any accidental occurrence in the content. – Jonas Apr 23 '10 at 18:10