[Date Prev][Date Next][Thread Prev][Thread Next][Thread Index]

[XaraXtreme-dev] XML notes

If you're going to use XML via libxml2 in Camelot are some notes:

* Remember that libxml2 uses UTF-8 encoding in memory no matter what the program's native encoding or the encoding of the original doc. So you have to be careful to do correct conversion to and from UTF-8 when passing strring parameters to it. I used wxString for this because it has useful encoding conversion functions.

* Only where you *KNOW* for certain that a string is UTF-8 (e.g. a bound-in string, such as an attribute name, containing only 7-bit ascii characters) can you cast to (xmlChar*) - but doing so saves a lot of fiddling around!

* libxml2 provides an API called the "tree module" which similar to the w3c DOM does but different - slightly lower-level being based on C structures. Note that there are functions that take namespaces into account and functions that ignore namespaces - so you can choose at build time whether your code will be more tolerant or strict about namespace usage.

* I revived the CXMLUtils class from Camelot on Windows but it doesn't contain all the old functions - doesn't need to so far. CXMLUtils intialises the libxml2 parser at program startup and de-initialises at closedown so that it's always ready to be used while Camelot is running.