Trouble Parsing Single Element XML String Doc


#1

Hi I am having trouble parsing xml.
I want to send xml via an action listener, so I create an xml string and then broadcast it:

XmlElement* note = new XmlElement("note");
note->setAttribute ("type", type);
note->setAttribute ("id", pMidiIndex);
note->setAttribute ("name", message.getMidiNoteName (message.getNoteNumber(), true, true, 3));
note->setAttribute ("number", message.getNoteNumber());
note->setAttribute ("vel", (int) message.getVelocity());
note->setAttribute ("time", (int) (message.getTimeStamp() * 1000));
const String& noteXMLString = note->createDocument (String::empty, false, false);
actionBroadcaster->->sendActionMessage (noteXMLString);

I can send this string to a Flash app and it can parse it, no problem.

However, when my listener tries to parse the text, I get a null pointer:

XmlElement* noteXML = XmlDocument::parse (midiString);

if (noteXML== nullptr)
{
    DBG ("noteXML== nullptr!")
    return;
}
else
{
   int noteNumber = noteXML->getIntAttribute ("number");
   //--etc...
}

What am I doing wrong? How do I access the note attributes?

Thanks for any help.


#2

Well the string is clearly not valid XML, so surely the obvious thing to do would be to look at the string and see what’s wrong with it?


#3

Thanks. Figured it out.