Retrieving and loading an XML string

Hi -
I am using an API to get an XML string. I can use another API call to load the XML string but I need help figuring how to do this. I don’t really need to store the XML I just want to “get” it and then load it in the next HYPE scene immediately.

I’ve read through the older posts about storing JSON with PHP on a server but as they are old posts and I’m not entirely sure how it works I’d love to know if someone could say how I might do this.

I’ve attached a file to peruse.

And here is the API I’m using:

Thank you!
MattNoteflight XML (22.7 KB)

I think what I need is just help simply saving the XML data as a variable and then calling it on the next scene.

Your demo does not include all your dependencies .i.e the script files like

  <script type="text/javascript" src="${resourcesFolderName}/jquery-3.1.1.min.js"></script>
  <script type="text/javascript" src="${resourcesFolderName}/jsonQ.min.js"></script>
   <script type="text/javascript" src="${resourcesFolderName}/js.cookie.js"></script>

So all it does is throw errors.

Hopefully you can post a version that has all that is being used or called but also it would be a good idea to explain what is meant to happen in the demo?

Which is what I would do…

I fixed the header issues.

Notice how in this example I can log the XML data.

Trying to figure out how to make it a variable and then call it on the next scene.

Is it as simple as declaring…

var scoreData

… then using this on the next scene’s loadXML function?Noteflight XML (84.0 KB)

Tthe API has restrictions on XML loads which looks like we ( probably not you) get no permission error.
If I remember correctly I set up a score before to help figure some noteflight stuff for you before to get around some restrictions but I think in this case I would have to contact noteflight directly…



Which makes it global rather than locally scoped to it’s containing function.

But I assume scoreData is the Get returned result var. So I would do something like

window.theScoreData = scoreData

inside the .done promise function

if (typeof window.theScoreData == "undefined") {window.theScoreData= {} };

    window.scoreView.getMusicXML().done(function(scoreData) {
   window.theScoreData = scoreData
    // do something with the returned score data
1 Like

I fixed the permissions on the score to allow copying so that should be ok now.

I’ll now go through your answer…

1 Like

Thank you!
So I created a button to get the XML using your function.

Now, on the second scene I’m getting an error when the XML tries to load.

TypeError: Cannot read property ‘toString’ of undefined

This the function I’m using to load the XML:

window.scoreView.loadMusicXML().done(function(scoreData) {
    // do something with the returned score data


Noteflight XML (85.3 KB)

I think I figured it out.

I need to simply call:


… in the 2nd scene and it worked!

Does this sound correct to you?

1 Like

I would think that would be ok.

One more twist on this that I cannot figure out.
I’m trying to load XML data from a file that I have in my resource folder (NFExample.xml)

The Noteflight API has a function that will load an XML String ( loadMusicXML( xmlString ) )so I thought I might need to make the entire document a string by serializing the root node with this:

new XMLSerializer().serializeToString(xmlObject.documentElement);

But I’m not able to get it to work.

This demo file has a basic function set up in the first scene but no real code.
@MarkHunte do you have any thoughts on this?

Noteflight XML (97.2 KB)

The are few ways to do this but the main issues is I cannot see where you are actually reading the file??.

jQuery.get("${resourcesFolderName}/NFExample.xml", function(data) {
  xmlString = (new XMLSerializer()).serializeToString(data);
1 Like

That works great! Thanks @MarkHunte