Parsing BinaryData XML documents


Apologies if this is a really stupid question… I’m trying to find the best way to embed an XML file into an executable build and then parse the contents. Previously I had been doing this with relatively small files and just a straight conversion to String and then using static XmlElement* XmlDocument::parse ( const String & xmlData ) to parse was working fine.

However, now I have a couple of larger files, which the Projucer converts to binary representations due to the MS compiler string literal limitation. My first attempt was to use the String::fromUTF8() static method to create a String, but the contents are being truncated. When the XML file is outside the executable I just parse it using the static XmlElement* XmlDocument::parse ( const File & file ) method.

I couldn’t find an obvious way to get the contents of a BinaryData element into a File without writing out to disk first. Am I missing something, or is there a better way to think about this?


pass your binary data to:

MemoryBlock (const void *dataToInitialiseFrom, size_t sizeInBytes)

and then use

String MemoryBlock::toString	(		)	const

to feed

static XmlElement* XmlDocument::parse	(	const String & 	xmlData	)	

auto s = String::createStringFromData (data, size);
std::unique_ptr<XmlElement> xml (XmlDocument::parse (s));


oh, but I just noticed you said it was in BinaryData. That’s even easier:

std::unique_ptr<XmlElement> xml (XmlDocument::parse (BinaryData::foobar_xml));


what happens internally with that last one? is the BinaryData:: converted to a File or String behind the scenes?


A string. It’s a const char*, there’s no implicit conversion from that to a File.


Awesome, thanks to both of you for the pointers, I’ll try that out tonight


Thanks again for the help. It turned out to be a problem with the XML file in the end. For whatever reason it was encoded as UTF-8 with BOM and I ran into the same problems with the ideas above as I did with my previous attempts. Just re-saved the file with UTF-8 encoding and all is now well!