[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

How do we convert flat arraycollection into XMLList ?

Posted on 2010-09-06
16
Medium Priority
?
858 Views
Last Modified: 2013-11-19
Hi,
I have the following ArrayCollection.. (How do we convert flat arraycollection into XMLList?)

            [Bindable]
            private var myData:ArrayCollection = new ArrayCollection([
              {Product:"Product-1", id:"100",label:"Item-11", quantity:"10", price:"50", state:"0"},
              {Product:"Product-1", id:"101",label:"Item-12", quantity:"20", price:"10", state:"0"},
              {Product:"Product-1", id:"102",label:"Item-13", quantity:"20", price:"60", state:"0"},  
 
              {Product:"Product-2", id:"200",label:"Item-21", quantity:"10", price:"30", state:"0"},  
              {Product:"Product-2", id:"201",label:"Item-22", quantity:"10", price:"40", state:"0"},  
              {Product:"Product-2", id:"202",label:"Item-23", quantity:"10", price:"90", state:"0"},
             
              {Product:"Product-3", id:"301",label:"Item-31", quantity:"10", price:"80", state:"0"},
              {Product:"Product-3", id:"302",label:"Item-32", quantity:"10", price:"50", state:"0"},
              {Product:"Product-3", id:"303",label:"Item-33", quantity:"10", price:"75", state:"0"},
              {Product:"Product-3", id:"304",label:"Item-33", quantity:"10", price:"45", state:"0"},

              {Product:"Product-4", id:"",label:"", quantity:"", price:""}

            ]);

How do we convert flat arraycollection into XMLList?


it should be like


[Bindable]	private var myXMLList:XMLList =
&#9;&#9;<>
&#9;      <Product id="Product-1"   state="0">
&#9;&#9;      <Item id="100" state="0"  label="Item-11" quantity="10" price="50"/>
&#9;&#9;      <Item id="101" state="0"  label="Item-12" quantity="10" price="10"/>
&#9;&#9;      <Item id="103" state="0"  label="Item-13" quantity="10" price="60"/>
&#9;      </Product>
&#9;      
&#9;      <Product id="Product-2"   state="0">
&#9;&#9;      <Item id="200" state="0"  label="Item-21" quantity="10" price="30"/>
&#9;&#9;      <Item id="201" state="0"  label="Item-22" quantity="10" price="40"/>
&#9;&#9;      <Item id="202" state="0"  label="Item-22" quantity="10" price="90"/>
&#9;      </Product>

&#9;      <Product id="Product-3"   state="0">
&#9;&#9;      <Item id="300" state="0"  label="Item-31" quantity="10" price="80"/>
&#9;&#9;      <Item id="301" state="0"  label="Item-32" quantity="10" price="50"/>
&#9;&#9;      <Item id="302" state="0"  label="Item-33" quantity="10" price="75"/>
&#9;&#9;      <Item id="304" state="0"  label="Item-34" quantity="10" price="45"/>
&#9;      </Product>&#9;

&#9;      <Product id="Product-4"   state="0">
&#9;      </Product>&#9;
&#9;      </>;


Thanks,
0
Comment
Question by:myBlueSky
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
16 Comments
 
LVL 13

Expert Comment

by:p_nuts
ID: 33616545
hi.

i think this link should show you how to get this done.

http://www.devx.com/getHelpOn/10MinuteSolution/20356

0
 
LVL 1

Author Comment

by:myBlueSky
ID: 33616694
Hi p_nuts,

Thanks for the link. I didn't get that value from the link.

 Do you know how to convert arraycollection into XMLList using actionscript.

0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 33645427
Do you have PHP available?
0
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 
LVL 1

Author Comment

by:myBlueSky
ID: 33656451
Ray_Paseur,

No, I don't have PHP available.
0
 
LVL 4

Expert Comment

by:heppa
ID: 33732994
you might want to look at SimpleXMLEncoder#encodeValue().

Good luck!
0
 
LVL 4

Expert Comment

by:heppa
ID: 33733314
I tested a bit around and came up with this:

 private function arrayCollectionToXML(ac:ArrayCollection):XML{
                var xml:XML = objectToXML(ac);
                return xml;
}
                  
                  private function objectToXML(obj:Object):XML {
                 var qName:QName = new QName("root");
                  var xmlDocument:XMLDocument = new XMLDocument();
                  var simpleXMLEncoder:SimpleXMLEncoder = new SimpleXMLEncoder(xmlDocument);
                  var xmlNode:XMLNode = simpleXMLEncoder.encodeValue(obj, qName, xmlDocument);
                  var xml:XML = new XML(xmlDocument.toString());
                  return xml;
                 }

private function init():void{
                       var xml:XML = arrayCollectionToXML(myData);
// now go ahead with your xml that contains <root><list><source><item><id></id>...</item><item>...</source></list></root>
                 }

Good Luck!
0
 
LVL 1

Author Comment

by:myBlueSky
ID: 33758800
what do you mean by this
>>>>> 
// now go ahead with your xml that contains <root><list><source><item><id></id>...</item><item>...</source></list></root>

Can put the complete solution. please have a look on the input data and output result

Thanks,
0
 
LVL 1

Author Comment

by:myBlueSky
ID: 33758808
INPUT :
            [Bindable]
            private var myData:ArrayCollection = new ArrayCollection([
              {Product:"Product-1", id:"100",label:"Item-11", quantity:"10", price:"50", state:"0"},
              {Product:"Product-1", id:"101",label:"Item-12", quantity:"20", price:"10", state:"0"},
              {Product:"Product-1", id:"102",label:"Item-13", quantity:"20", price:"60", state:"0"},  
 
              {Product:"Product-2", id:"200",label:"Item-21", quantity:"10", price:"30", state:"0"},  
              {Product:"Product-2", id:"201",label:"Item-22", quantity:"10", price:"40", state:"0"},  
              {Product:"Product-2", id:"202",label:"Item-23", quantity:"10", price:"90", state:"0"},
             
              {Product:"Product-3", id:"301",label:"Item-31", quantity:"10", price:"80", state:"0"},
              {Product:"Product-3", id:"302",label:"Item-32", quantity:"10", price:"50", state:"0"},
              {Product:"Product-3", id:"303",label:"Item-33", quantity:"10", price:"75", state:"0"},
              {Product:"Product-3", id:"304",label:"Item-33", quantity:"10", price:"45", state:"0"},

              {Product:"Product-4", id:"",label:"", quantity:"", price:""}

            ]);

OUTPUT:



[Bindable] private var myXMLList:XMLList =
<>
      <Product id="Product-1"   state="0">
      <Item id="100" state="0"  label="Item-11" quantity="10" price="50"/>
      <Item id="101" state="0"  label="Item-12" quantity="10" price="10"/>
      <Item id="103" state="0"  label="Item-13" quantity="10" price="60"/>
     </Product>
     
      <Product id="Product-2"   state="0">
      <Item id="200" state="0"  label="Item-21" quantity="10" price="30"/>
      <Item id="201" state="0"  label="Item-22" quantity="10" price="40"/>
      <Item id="202" state="0"  label="Item-22" quantity="10" price="90"/>
      </Product>

     <Product id="Product-3"   state="0">
      <Item id="300" state="0"  label="Item-31" quantity="10" price="80"/>
      <Item id="301" state="0"  label="Item-32" quantity="10" price="50"/>
      <Item id="302" state="0"  label="Item-33" quantity="10" price="75"/>
      <Item id="304" state="0"  label="Item-34" quantity="10" price="45"/>
      </Product>

      <Product id="Product-4"   state="0">
      </Product>&#9;
      </>;

0
 
LVL 4

Accepted Solution

by:
heppa earned 2000 total points
ID: 33769124
sorry, couldn't get back to you earlier... and sorry for not recognizing your desired output data structure before. But you should be aware, that both are different in terms of normalization? Your ArrayCollection holds "item" objects whereas your XMList holds "Product" objects. It's still feasible with a bit of processing.

http://www.packtpub.com/article/working-with-xml-in-flex3-and-java-1

This link will help you understand XML processing in flex. you could for example use a function

private function processXMLToXMLList(xml:XML):XMLList{

    // walk through xml to find all items with the same product
    var newXML:XML;
    // now put them all together.
    var list:XMLList  = new XMLList(newXML.list.source.item);
}

now, if you really want the data structure like described above, you could walk through the list, and build a new list out of all items with the same Product-Id. If it's not enough for you to give directions, please let me know.
0
 
LVL 4

Expert Comment

by:heppa
ID: 33980763
Are we supposed to give directions or solve the problem with perfect code? I think, I stated clearly, how you could get a working XML out of an ArrayCollection. Obviously, the OP does not want to dig into the programming language at all. Thanks a lot for making me waste another 30minutes of my life!
0
 
LVL 1

Author Comment

by:myBlueSky
ID: 33980845
Thank you for your participation.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Originally, this post was published on Monitis Blog, you can check it here . It goes without saying that technology has transformed society and the very nature of how we live, work, and communicate in ways that would’ve been incomprehensible 5 ye…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question