You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@flex.apache.org by Harbs <ha...@gmail.com> on 2017/08/28 09:07:12 UTC

FlexJS XML problem

Given the following XML in Flash:
var xml:XML = <root/>;
xml.bar.foo.baz = "baz";

You get an XML structure like so:
<root>
  <bar>
    <foo>
      <baz>
        baz
      </baz>
    </foo>
  </bar>
</root>

In JS, this compiles to the following:

  var /** @type {XML} */ xml = new XML( '<root/>');
  xml.child('bar').child('foo').setChild('baz', "baz");

.child() returns an empty XMLList
.setChild() tries to add a child to that empty list and does not create the structure.

I’m not sure how to best solve this problem.

One idea would be to add a new function called getChild() which would return an existing element if it exists and create a new one if not. Then we could have the compiler rewrite the output to:

  xml.getChild('bar').getChild('foo').setChild('baz', "baz");

I’d prefer to try and figure out how to have setChild walk up the reference tree and create the correct elements automatically. I’m having trouble figuring out how to do that though.

Harbs

Re: FlexJS XML problem

Posted by Harbs <ha...@gmail.com>.
I figured it out and committed a fix.

> On Aug 28, 2017, at 12:07 PM, Harbs <ha...@gmail.com> wrote:
> 
> Given the following XML in Flash:
> var xml:XML = <root/>;
> xml.bar.foo.baz = "baz";
> 
> You get an XML structure like so:
> <root>
>  <bar>
>    <foo>
>      <baz>
>        baz
>      </baz>
>    </foo>
>  </bar>
> </root>
> 
> In JS, this compiles to the following:
> 
>  var /** @type {XML} */ xml = new XML( '<root/>');
>  xml.child('bar').child('foo').setChild('baz', "baz");
> 
> .child() returns an empty XMLList
> .setChild() tries to add a child to that empty list and does not create the structure.
> 
> I’m not sure how to best solve this problem.
> 
> One idea would be to add a new function called getChild() which would return an existing element if it exists and create a new one if not. Then we could have the compiler rewrite the output to:
> 
>  xml.getChild('bar').getChild('foo').setChild('baz', "baz");
> 
> I’d prefer to try and figure out how to have setChild walk up the reference tree and create the correct elements automatically. I’m having trouble figuring out how to do that though.
> 
> Harbs