musicXML to JSON in Javascript

I’m trying to convert a musicXML file to JSON. The problem is, as you may know, that the XML has sequential information and JSON does not.
In this specific case I came with a solution: I need to add the closest <note> @default-x attribute to all <direction-type> elements.
Do you know a way to search the nearest <note> element arround a <direction-type> one?

An example of the musicXML score:
raw.githubusercontent.com/scoresmexico/musicXMLscores/main/mm26-29.xml

Read more here: Source link