csPtr<iString> AssetManager::LoadDocument (iObjectRegistry* object_reg, csRef<iDocument>& doc, const char* vfspath, const char* file) { doc.Invalidate (); csRef<iVFS> vfs = csQueryRegistry<iVFS> (object_reg); if (vfspath) vfs->PushDir (vfspath); csRef<iDataBuffer> buf = vfs->ReadFile (file); if (vfspath) vfs->PopDir (); if (!buf) return 0; // No error, just a non-existing file. csRef<iDocumentSystem> docsys; docsys = csQueryRegistry<iDocumentSystem> (object_reg); if (!docsys) docsys.AttachNew (new csTinyDocumentSystem ()); doc = docsys->CreateDocument (); const char* error = doc->Parse (buf->GetData ()); if (error) { scfString* msg = new scfString ();; msg->Format ("Can't parse '%s': %s", file, error); doc.Invalidate (); return msg; } return 0; }
const char* csTinyDocWrapper::Parse (const char* buf, bool collapse) { // Skip any UTF8 BOM if (HasUTF8Bom (buf)) buf += 3; const char* b = buf; while ((*b == ' ') || (*b == '\n') || (*b == '\t') || (*b == '\r')) b++; if (*b == '<') { return tinydoc->Parse (buf, collapse); } else { return "Data does not seem to be XML."; } }