FYI I've heard that about XML too; that it's slower or much slower than
accessing it's object representation. But that doesn't mean it's too slow.
In my tests delays have been unnoticeable to the user. I don't think it
should be avoided.
For example, in my tests of creating a new XML instance with 100 rows it
takes less than a millisecond in the debugger using the following case:
var xml:XML = new XML(hundredRowsOfXML);
at a 1000 rows it took 7 milliseconds in the debugger or about 2-3 ms at
runtime.
it may take longer when trying to access or manipulate that data but again,
in my tests, it was much less than a normal human would notice. other
things have much more of an impact than XML.
on the Flex JS XML project the compiler will be converting XML syntax into
AS3 calls and then that is cross compiled into JS.
so for FlexJS this:
var myXML:XML = new XML(contents);
var rows:XMLList = myXML.row;
gets converted into:
var xml:XMLProxy = new XMLProxy(contents); // or XMLFacade
var rows:* = myXML.descendants("row");
where descendants() is a method of the XMLProxy class:
// pseudo code
public var contents:XMLObject;
public function descendants(localName:String):XMLArray {
var items:XMLArray = [];
var numOfItems:int = contents.getDescendants();
for (var i:int; i < numOfItems; i++) {
if (content[i].localName==localName) {
items.push(content[i]);
}
}
return items;
}
The FlexJS XML class would be using AS3 objects and methods as a facade or
proxy to the actual data. The conversion from a string to
XMLProxy/XMLFacade object may be the heaviest part about it but after that
those calls would be the same as using JS converted AS3. FYI This is as I
understand it.
Of course a LazyCollection in any case would be best solution.
On Tue, Mar 1, 2016 at 8:23 AM, Alex Harui <[email protected]> wrote:
> Hi,
>
> FlexJS doesn't have XML support yet. One committer is working on it.
>
> Even when we get it to work, it isn't clear how fast it will be. In
> general XML apis aren't even fast in the Flash/AIR runtime. So of those
> reasons, the current FlexJS APIs support inputParsers and itemConverters
> because I've used these patterns in the past to performance tune some big
> apps and wanted to make sure such a feature would work when cross-compiled.
>
> A LazyCollection converts raw data into ValueObjects on-demand. If you
> think about how Flex works today, suppose you get 1000 rows in XML from
> your server. The Player is currently going to lock up the UI while it
> converts the huge String to XML and then, if you are using an XMLDecoder,
> run a loop from 1 to 1000 to convert each item to a ValueObject. If you
> don't use an XMLDecoder, then you are using XML and XMLList directly in
> your app and paying the price for every property fetch on the XML data.
> XML property fetches can be an order of magnitude (or more) slower than
> ValueObject fetches so if you are having performance issues as folks
> scroll a DataGrid with a lot of columns and rows, you might get better
> performance using ValueObjects, but then you have to freeze the UI while
> you convert the ValueObjects when the server payload is received. Yes, we
> can now use Workers to try to move this to the background, but I don't
> want to require every FlexJS runtime to support Workers.
>
> So, a LazyCollection actually only converts the raw data to a ValueObject
> on the first time it is fetched via getItemAt(). This is slightly less
> efficient if you absolutely need to visit every row in the data to compute
> a sum or group, but otherwise, if 1000 rows come in, and only 30 rows are
> being shown, only 30 rows get converted and the time the UI is locked up
> is much smaller.
>
> So, if you think you will need to take advantage of lazy conversion of
> data to ValueObjects, I would recommend that you not wait for the XML
> support and try to write your own converters and parsers. I haven't tried
> to write them for XML, we only have them for JSON, but maybe you or some
> other volunteer can do it.
>
> HTH,
> -Alex
>
> On 3/1/16, 1:16 AM, "santanu4ver" <[email protected]> wrote:
>
> >
> >Therefore I dig more with FlexJS 0.5.0 provided examples and in
> >'FlexWebsiteStatsViewer' example I noticed these following codes where
> >HTTPService calls in MXML tag:
> >
> ><js:HTTPService id="service" method="POST">
> > <js:LazyCollection id="collection">
> > <js:inputParser>
> > <controllers:GAJSONInputParser />
> > </js:inputParser>
> > <js:itemConverter>
> > <controllers:GAStatsDataJSONItemConverter />
> > </js:itemConverter>
> > </js:LazyCollection>
> ></js:HTTPService>
> >
> >After more investigation into the code/data-incoming, I felt:
> >
> >1. GAJSONInputParser is receiving incoming data as String and therefore
> >giving a shape to the String by subStr etc.
> >2. GAStatsDataJSONItemConverter then returned String value by
> >GAJSONInputParser and converted things into object by parsing the String
> >by
> >subStr etc.
> >
> >I tried our URL call with this above way now. I noticed that I received
> >XML
> >as String inside GAJSONInputParser class. So, here are the question I'm
> >now
> >standing in front of:
> >
> >1. Should we need to always use HTTPService in MXML tag - the way I
> >mentioned above?
> >2. If #1 is No, then what is failing in my earlier ActionScript codes
> >(that
> >I've pasted in beginning of this post)
> >3. Why I am having 'variable XML is undefined' - FlexJS provides any API
> >to
> >read XML object?
> >4. Do I need to parse an XML by String.substr way only? (as above example
> >parsing JSON String)
> >5. Why FlexJS Alert is not working when ran as HTML?
> >
> >
> >
> >--
> >View this message in context:
> >
> http://apache-flex-users.2333346.n4.nabble.com/FlexJS-HTTPService-for-XML-
> >parsing-tp12094.html
> >Sent from the Apache Flex Users mailing list archive at Nabble.com.
>
>