# Convert XML to Array of objects

**URL:** <https://forum.kirupa.com/t/convert-xml-to-array-of-objects/313674>\
**Category:** flash\
**Created:** [September 7, 2010, 4:15am UTC](https://forum.kirupa.com/t/convert-xml-to-array-of-objects/313674 "2010-09-07T04:15:58Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![nitinmukesh](https://avatars.discourse-cdn.com/v4/letter/n/7feea3/32.png) [@nitinmukesh](https://forum.kirupa.com/u/nitinmukesh)\
**Post date:** [September 7, 2010, 4:15am UTC](https://forum.kirupa.com/t/convert-xml-to-array-of-objects/313674/1 "2010-09-07T04:15:58Z")

</div>

Hi,

I found a good class to convert XML to Array of Objects just like SimpleXMLSecoder do in flex.

The problem is the class does not convert it to array if there is only 1 node. I tried to modify it without success.

Please can someone help me with this.

Attached are the source files.

e.g.

```php

import eu.rotundu.xml.*;

var s:SimpleXMLDecoder = new SimpleXMLDecoder(true);

/*
var list:XML = <books>
        <book publisher="Addison-Wesley" name="Design Patterns" />
        <book publisher="Addison-Wesley" name="The Pragmatic Programmer" />
        <book publisher="Addison-Wesley" name="Test Driven Development" />
        <book publisher="Addison-Wesley" name="Refactoring to Patterns" />
        <book publisher="O'Reilly Media" name="The Cathedral & the Bazaar" />
        <book publisher="O'Reilly Media" name="Unit Test Frameworks" />
</books>;
*/

var list:XML = <books>
        <book publisher="Addison-Wesley" name="Design Patterns" />
</books>;

var result:XMLDocument = new XMLDocument();
result.ignoreWhite = true;
result.parseXML(list.toString());

var o:Object = s.decodeXML(result.firstChild);

trace(o.book.length)

```

The above code returns length if I use the commented **list**. I want to create 0 index Array if there is one element only.
