Loading KML from raw text

I am work on a project where I need to load kml files from the client computer. They select the file and its read into a buffer on the browser. The documentation said I could load the kml into the scene directly from a raw kml string, but when I try to do it, it errors saying

"Cesium.js:1 Uncaught TypeError: Cannot read property '1' of null
    at new URI (Cesium.js:1)
    at new Resource (Cesium.js:1)
    at Function.Resource.createIfNeeded (Cesium.js:1)
    at load$2 (Cesium.js:1)
    at KmlDataSource.load (Cesium.js:1)
    at Function.KmlDataSource.load (Cesium.js:1)
    at AppState.addKMLFromText (app.js:95)
    at addKMLToScene (object-loader.js:47)
    at parseClientLoadedObject (object-loader.js:32)
    at FileReader.reader.onload (client-files.js:27)

The KML file loads correctly when its loaded from the server using a url. I have also verified that the file text has been loaded correctly.

	addKMLFromText(fileText) {
		var kmlOptions = {
			camera : appState.getViewer().scene.camera,
			canvas : appState.getViewer().scene.canvas,
			clampToGround : true
		appState.viewer.dataSources.add(Cesium.KmlDataSource.load(fileText, kmlOptions));

I would appreciate any and all help with this issue.

This will not work because the KMLDataSource.load function does not accept a KML string. That argument you pass in must be:

A url, parsed KML document, or Blob containing binary KMZ data or a parsed KML document.

If you’ve already fetched the text and want to load it, you’ll need to pass it to DOMParser first:

var parser = new DOMParser();
var kmlDoc = parser.parseFromString(kmlContent, "text/xml");
viewer.zoomTo(viewer.dataSources.add(Cesium.KmlDataSource.load(kmlDoc, options)))

Here’s a full Sandcastle example you can run.