We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I am creating a reference application for music theory that will compare frequencies from a piano roll to those on a guitar fretboard. I have two XML file schemas below, the second one modeled after Processing documentation. Is it possible to create a method in which I can pass in a string value and have it return the additional info for that node... I have tried all of the get methods for XML and am about to scrap it, but maybe I am missing something...
<?xml version="1.0"?>
<musicalNotes>
<noteData>
<noteName>C0</noteName>
<noteFreq>16.35</noteFreq>
<noteWave>2100</noteWave>
</noteData>
<noteData>
<noteName>C#0</noteName>
<noteFreq>17.32</noteFreq>
<noteWave>1990</noteWave>
</noteData>
</musicalNotes>
<?xml version="1.0"?>
<musicalNotes>
<noteName id="0" noteFreq="16.35" noteWave="2100">C0</noteName>
<noteName id="1" noteFreq="17.32" noteWave="1990">C#0</noteName>
</musicalNotes>
XML xml;
xml = loadXML("noteFreq.xml");
String matchInfo(String value) {
// match the string value of note clicked to xml data
XML noteInfo = xml.getChild(value);
value = noteInfo.getContent(value);
println(value);
return value;
}
Answers
To retrieve attributes, it should be something like
xml.getInt()
. There are functions for retrieving each of the basic types. Of course, you can always get every value as aString
and parse it later.You can only return one of these values unless you create a wrapper class for the XML data (in some cases, XML itself is enough).