XML as input data, Angular construction in recursion

3,521 views
Skip to first unread message

MisoX X.

unread,
Feb 24, 2012, 6:41:02 PM2/24/12
to AngularJS
Hello,
I am new in Angular.js and I am trying to solve these problems few
days. Maybe sameone more skilled could help me:

1) Angular examples are focused on JSON as model. It's possible to use
i.e. XML document as model? I mean, that I will echo xml "elements"
via repeater, I can echo text inside using $(element).text(). And also
I have to write data to model via $(element).text('new text inside');.

2) It's possible to construct elements in recursion, when model is in
tree structure? I found that repeater works for iterating over one
level, but can't figure out, have to use it in deeper level.
I.e :
|-elem
|-elem
|-elem
|-elem
|-elem

Thank you.

andrew mcelroy

unread,
Feb 24, 2012, 9:32:22 PM2/24/12
to ang...@googlegroups.com
On Fri, Feb 24, 2012 at 5:41 PM, MisoX X. <mis...@gmail.com> wrote:
Hello,
I am new in Angular.js and I am trying to solve these problems few
days. Maybe sameone more skilled could help me:

1) Angular examples are focused on JSON as model. It's possible to use
i.e. XML document as model? I mean, that I will echo xml "elements"
via repeater, I can echo text inside using $(element).text(). And also
I have to write data to model via $(element).text('new text inside');.
I don't see why this couldn't be done. xhr after all stands for XML http request.
However, what is compelling you to do so? 
XML has a far greater network traffic overhead than JSON. 

I'm curious to know more about this usecase

Andrew

2) It's possible to construct elements in recursion, when model is in
tree structure? I found that repeater works for iterating over one
level, but can't figure out, have to use it in deeper level.
I.e :
|-elem
 |-elem
 |-elem
   |-elem
 |-elem

Thank you.

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/angular?hl=en.


MisoX X.

unread,
Feb 25, 2012, 3:06:37 AM2/25/12
to AngularJS
I need to load xml file and edit it. And I think that Angular could be
a great library.
I don't want to use JSON, because I'm trying to avoid converting XML-
>JSON->XML.
Problem is, that I still don't understand everything in Angular. I
read documentation, but
I'm not sure how to create own setter/getter, because model based on
XML need it.

I'm iterating elements via ng:repeater = "element as elements".
I tryed to define functions in controller scope, ie. function
TestController() { ... } :

this.element.$set = function(){}, this.element.$get = function(){}
or
this.set = function(element) {}
...

Charlie

unread,
Feb 25, 2012, 11:36:51 AM2/25/12
to AngularJS
XML is far more verbose in an uncompressed form, however you really
should be gzipping your data streams in which case, for typical
models, there is very little difference in payload size over the
network at least for larger data sets.

Historically large data sets in json suffered from performance
degradation (on the client) when performing complex sorts/filters/
queries, areas where xpath and compiled XSLT on the shined. In
recent years JavaScript engines have experienced stunning improvement
while xPath/XSLT performance/feature completeness has stagnated, at
least in webkit browsers (IE and Mozilla fare a bit better).

For some historical perspective see:
http://www.nczonline.net/blog/2008/01/09/is-json-better-than-xml/

Vojta Jina

unread,
Feb 26, 2012, 1:22:27 AM2/26/12
to ang...@googlegroups.com
Hey,

ad 1/ sure you can use xml, $http has transformRequest, transformResponse - defaults are for json, so you need to configure it to parse xml
See http://docs-next.angularjs.org/api/angular.module.ng.$http (request/response transformations)
Unfortunately I don't understand the rest of this point - not sure what exactly you are trying to achieve.

ad 2/ ng:repeater does not have support for recursion, but you can nest it

V.

MisoX X.

unread,
Feb 26, 2012, 2:15:12 AM2/26/12
to AngularJS
1/ Actually I have received xml document in my controller. Now I need
to define, how it should work with one child of that document. I.e.
function myCntrl() {
var myXML;
this.element ???(set/get)
}

<ul ng:repeat="myXml.find('user') as element">
<input name="element" value="{{ element.text() }}">
</ul>

...that's not right structure or syntax. Could someone give me an
simple example?

Because default setting and getting via Angular works simple because
of JSON:
set: this.element.text = "newtext";
get: this.element.text;

But XML doc, needs:
set: this.element.text('newtext'); <-to set text inside of element
get: this.element.text();

On 26. Feb, 07:22 h., Vojta Jina <vojta.j...@gmail.com> wrote:
> Hey,
>
> ad 1/ sure you can use xml, $http has transformRequest, transformResponse -
> defaults are for json, so you need to configure it to parse xml
> Seehttp://docs-next.angularjs.org/api/angular.module.ng.$http

Vojta Jína

unread,
Feb 26, 2012, 5:34:37 PM2/26/12
to ang...@googlegroups.com
Well, you can use ng:change, to do something like:
<input type="text" ng:model="tempData" ng:change="element.text(tempData)" />

Or you can learn the parser to understand getter/setter and bind to element... :-D

I was trying to make it more general, basically allow binding to any method, which would be called as getter or setter then, but all these jq methods are bound (you need to call them on object), so it would be more complicated...

V.

John George Wright

unread,
May 28, 2013, 10:40:04 AM5/28/13
to ang...@googlegroups.com, mis...@gmail.com
https://github.com/johngeorgewright/angular-xml

Made the above module a while back. It adds an interceptor on HTTP requests and converts the response in to a ng.element object.
Reply all
Reply to author
Forward
0 new messages