Skip to content
This repository has been archived by the owner on May 14, 2020. It is now read-only.

nx3 • 1b. XML serialization

Jonas Nyström edited this page Jan 12, 2014 · 2 revisions

XML Serialisation

The N* tree can be saved to and rebuilt from XML. As an example, the bar created above can be serialized to an xml string like this:

var barXmlStr = nx3.io.BarXML.toXml(bar);

Here's the result:

<bar time="3/4">
	<part key="-1">
		<voice direction="Up">
			<note value="9072">
				<head level="-1" />
			</note>
		</voice>
		<voice direction="Down">
			<note value="4536">
				<head level="1" />
			</note>
			<note value="1512">
				<head level="2" />
			</note>
			<note>
				<head level="3" sign="Sharp" />
			</note>
		</voice>
	</part>
	<part clef="ClefF" key="-1">
		<voice>
			<note value="6048">
				<head level="-2" />
				<head level="5" />
			</note>
			<note>
				<head level="0" />
			</note>
		</voice>
	</part>
</bar>

Recreating a bar tree is just as simple:

var recreatedBar = nx3.io.BarXML.fromXmlStr(barXmlStr);