Using asx3m and XStream to solve the problem of XML data transfer between Flex and Java using Httpservice _flex

Source: Internet
Author: User
The back end also has a Java user object class that serializes the user object in the list into XML data using the XStream component. obtained using the E4X format format on the flex side via Httpservice.
Just started to parse XML by E4X technology, and construct flex user object, similar to the way it was handled:
Copy Code code as follows:

Public Function FromXml (currentnode:xml): void{
UserID = new number (Currentnode.userid);
UserName = Currentnode.username;
......
}

But this way is too cumbersome. So I wanted to use flex reflect to implement a generic convert or a component like XStream.
Of course, the first is to Google one, and really found two, one is Xmlconverter (http://www.customware.net/repository/display/FLEX/Integrating+Flex+with +xml+using+xmlconverter), one is fully compatible with Xtream asx3m (http://code.google.com/p/asx3m/).
Xmlconverter simple, but not open source, for parsing a single object's XML format, or enough, but for parsing complex inclusion list structure, can not help. Finally, the use of asx3m, very convenient. The only thing that bothers me is that asx3m needs to rely on the Vegas (http://vegas.googlecode.com/svn/AS3/trunk/src/vegas/) behemoth (in fact, it only needs hashmap, List and several auxiliary classes)
Using asx3m is really handy, and the code at both ends is simple, as follows:
Server-side Java code:
list<workitem> users = um.queryusers (1);
XStream XStream = new XStream ();
Xstream.alias ("User", User.class);
String XML = xstream.toxml (users);
list<workitem> users = um.queryusers (1);
XStream XStream = new XStream ();
Xstream.alias ("User", User.class);
String XML = xstream.toxml (users);
Flex End as code:
Import hr.binaria.asx3m.Asx3m;
Import Hr.binaria.asx3m.Asx3mer;
var xmlc:asx3mer = asx3mer.instance;
Xmlc.xstream.alias ("user", user);
This array is the list of user objects
var array:arraycollection = Xmlc.fromxml (compxml) as arraycollection;
Import hr.binaria.asx3m.Asx3m;
Import Hr.binaria.asx3m.Asx3mer;
var xmlc:asx3mer = asx3mer.instance;
Xmlc.xstream.alias ("user", user);
This array is the list of user objects
var array:arraycollection = Xmlc.fromxml (compxml) as arraycollection;
It's as simple as that. -Of course, in this way, you need to maintain two sets of object structures (Java object) and (as Object) at both ends, but they are much more scalable and flexible than the remoteobject of the AMF.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.