2

I plan to generate an Atom feed inside my AngularJS controller. A want to generate a view, but not on the server-side, because I want to replace the URI with a new AngularJS route.

Now I know how to write XML with JavaScript, but I have no idea about how to returning a XML content without a view.

My route setting is quite normal like below. It uses templateUrl to render a partial view.

.when('/posts', {
            templateUrl: 'theme/post_list.html',
            controller: PostsController
        })

Is it possible to serve XML content without a view using AngularJS? Like so:

.when('/posts.atom', {
            controller: PostsController
        })

Generating the angular.js routed Atom feed on the server-side is possible, but I don't want it.

Dan Lowe
  • 51,713
  • 20
  • 123
  • 112
ccoroom
  • 699
  • 9
  • 23

1 Answers1

0

Use the following process:

  • Append an <object> or <iframe> to the DOM with the XML within the tag

OR:

  • Return Atom from the service

  • Store in a documentFragment

  • Use transformToFragment or DOMParser to create a view

  • Use XMLSerializer to convert the view to a string

  • Insert an XML stylesheet into the string:

      <?xml-stylesheet href="feed.css"?>
    
  • Use the string as the value of the srcdoc attribute:

      <iframe srcdoc="{{atomfeed}}" height="95%" width="100%">
    

For example:

$scope.atomstyle='<?xml-stylesheet href="feed.css"?>'
$scope.atomboilerplate='<feed xmlns="http://www.w3.org/2005/Atom">'
$scope.atomhead='<title></title><link></link>'
$scope.atomcontent='<entry><title></title><link></link></entry>';
$scope.atomtail='</feed>'

$scope.atomfeed=String().concat
 (
 $scope.atomstyle, 
 $scope.atomboilerplate,
 $scope.atomhead,
 $scope.atomcontent,
 $scope.atomtail
 )

References

Community
  • 1
  • 1
Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265