0

I need to use a string to access nodes and attributes in XML using E4X. It would be ideal to have this scenario (with XML already loaded):

var myXML:XML = e.target.data;

var myStr:String = "appContent.bodyText.(@name == 'My Text')";

myXML.myStr = "New Value for bodyText node where attribute('name') is equal to 'My Text'";

I ultimately need to set new values to an XML document using strings as E4X expressions.

Zombo
  • 1
  • 62
  • 391
  • 407
  • Anyone got this working? – Shawn Aug 06 '09 at 21:29
  • I haven't gotten it working, BUT... I figured out a workaround. take the string of the E4X path you want to target. while parsing the XML, pull the E4X path and compare it to your target path. if the two are equal, do what you will with that node/attribute. It's a hack, but it works. You could even parse the XML and populate an array with the target string and the target node, then you could just access it through an item in the array. This is expandable in many ways. As long as everything is set up for proper garbage collection, you'll be okay. I'm just using it in a development tool. :-) –  Aug 07 '09 at 16:52

1 Answers1

0

As noted above:

I figured out a workaround

  • Take the string of the E4X path you want to target

  • Pull the E4X path and compare it to your target path

  • If the two are equal, do what you will with that node/attribute

It's a hack, but it works. You could even parse the XML and populate an array with the target string and the target node, then you could just access it through an item in the array. This is expandable in many ways. As long as everything is set up for proper garbage collection, you'll be okay.

Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265