Will support be provided for XML file reads/writes? If I read the Aurelia docs correctly, Aurelia-fetch-client and aurelia-http-client, are configured for/expecting JSON response types (HTTP Services in Aurelia docs). I have a very large SPA conversion project and want to use Aurelia. However, all the page content and pointers are output in an XML document and mapped via GUIDs. Do I need to build a custom routine for XML to JSON for use with Aurelia?
Asked
Active
Viewed 419 times
1 Answers
4
The Fetch API specification currently doesn't have any methods to take/ convert the response stream as XML Document (https://developer.mozilla.org/en-US/docs/Web/API/Response#Methods). (The same fetch API is used by Aurelia if the browser supports it or it uses a polyfill (whatwg fetch) that implements matching logic to the API)
What you can do is get the stream as text and then parse the output with a library that can parse XML.
For example with jQuery's parseXML (https://api.jquery.com/jQuery.parseXML/) method:
import {autoinject} from 'aurelia-framework';
import {HttpClient} from 'aurelia-fetch-client';
import 'fetch';
import * as $ from 'jquery';
@autoinject
export class XMLFetchTest {
constructor(private http: HttpClient) {
http.configure(config => {
config
.useStandardConfiguration()
.withBaseUrl('/src/');
});
}
public activate() {
return this.http.fetch('test.xml')
.then(response => response.text())
.then(text => {
let doc = $.parseXML(text);
}));
}
}

Erik Lieben
- 1,249
- 6
- 12
-
Thanks for the reply. I figured it was going to be something like this. I was really hoping to avoid Angular - seems like this is the solution. I just wish there was something in the framework. – RT1138 Nov 20 '16 at 00:34