Using angular template engine to generate xml

3,077 views
Skip to first unread message

Miguel Ping

unread,
Feb 1, 2013, 7:22:47 AM2/1/13
to ang...@googlegroups.com
I'd like to use angular's template engine to generate some xml documents.
Is it possible to use the template engine "standalone" to generate a string? Something along these lines:

  1. <script type="text/ng-template" id="/xml.html">
    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <node1 ..>
      1. <Row ng-repeat="data in items">
        1. <Item>{{data}}</Item>
      2. </Row>
    3. </node1>
  2. </script>

Then, I would just need to invoke it within a service:

...['$some_unknown_dep', function(templateEngine)(){
var str = templateEngine.render('/xml.html', {items: [1,2,3]});
$http.post(..., str, ...)
}]);

Yeah, POSTing JSON would be easier, but it's not my service :\

Thanks!

Miguel Ping

unread,
Feb 1, 2013, 8:50:54 AM2/1/13
to ang...@googlegroups.com
Here's a fiddle of what I am trying to achieve: http://jsfiddle.net/r3Ykr/

Miguel Ping

unread,
Feb 1, 2013, 9:10:06 AM2/1/13
to ang...@googlegroups.com
I got a version working, although I still can't use $templateCache: http://jsfiddle.net/r3Ykr/2/

Pawel Kozlowski

unread,
Feb 1, 2013, 9:12:35 AM2/1/13
to ang...@googlegroups.com
Miguel,

AngularJS is _not_ a templating engine so using it to generate XML has
limited benefit, IMO.
What is your use case?

Cheers,
Pawel
> --
> You received this message because you are subscribed to the Google Groups
> "AngularJS" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to angular+u...@googlegroups.com.
> To post to this group, send email to ang...@googlegroups.com.
> Visit this group at http://groups.google.com/group/angular?hl=en-US.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>



--
Question? Send a fiddle
(http://jsfiddle.net/pkozlowski_opensource/Q2NpJ/) or a plunk
(http://plnkr.co/)
Need help with jsFiddle? Check this:
http://pkozlowskios.wordpress.com/2012/08/12/using-jsfiddle-with-angularjs/

Looking for UI widget library for AngularJS? Here you go:
http://angular-ui.github.com/

Miguel Ping

unread,
Feb 1, 2013, 9:28:44 AM2/1/13
to ang...@googlegroups.com
Hi Pawel,

I know angular is not a templating engine and that I would be better off with mustache, underscore, handlebars or whatever.
I just want to use the ng-repeats and data-binding to generate a xml document. The xml is simple enough to use just ng-repeats, ng-switchs and so on.

My use case is the following: I need to POST a url with some xml data (I do not own this service); the xml will be fed with data from a $scope.
In order to construct the xml, I am evaluating the unorthodox way of using angular's services to build it, just for the sake of it.

Anyway I learn a little more of angular's internals by doing these kinds of 'exercises'.
Thanks.

NV

unread,
Oct 23, 2013, 10:40:56 AM10/23/13
to ang...@googlegroups.com
Hi Miguel,

Have you had any luck with this or abandoned it?

Olga Szklarska

unread,
Feb 1, 2015, 2:36:42 PM2/1/15
to ang...@googlegroups.com, ni...@kodamediagroup.com
Hi,

just by pure concidence I found Your posts. For the purpose of my project, I have created this simple stuff:


Greetingz.
Reply all
Reply to author
Forward
0 new messages