int XMLwrapper::loadXMLfile(const char *filename){ if (tree!=NULL) mxmlDelete(tree); tree=NULL; ZERO(&parentstack,(int)sizeof(parentstack)); ZERO(&values,(int)sizeof(values)); stackpos=0; char *xmldata=doloadfile(filename); if (xmldata==NULL) return(-1);//the file could not be loaded or uncompressed printf("%s\n",xmldata); root=tree=mxmlLoadString(NULL,xmldata,MXML_OPAQUE_CALLBACK); delete []xmldata; if (tree==NULL) return(-2);//this is not XML node=root=mxmlFindElement(tree,tree,"paulstretch-data",NULL,NULL,MXML_DESCEND); if (root==NULL) return(-3);//the XML doesnt embbed required data push(root); values.xml_version.major=str2int(mxmlElementGetAttr(root,"version-major")); values.xml_version.minor=str2int(mxmlElementGetAttr(root,"version-minor")); return(0); };
bool XMLwrapper::checkfileinformation(char *filename){ stackpos=0; ZERO(&parentstack,(int)sizeof(parentstack)); if (tree!=NULL) mxmlDelete(tree);tree=NULL; char *xmldata=doloadfile(filename); if (xmldata==NULL) return(-1);//the file could not be loaded or uncompressed char *start=strstr(xmldata,"<INFORMATION>"); char *end=strstr(xmldata,"</INFORMATION>"); if ((start==NULL)||(end==NULL)||(start>end)) { delete []xmldata; return(false); }; end+=strlen("</INFORMATION>"); end[0]='\0'; tree=mxmlNewElement(MXML_NO_PARENT,"?xml"); node=root=mxmlLoadString(tree,xmldata,MXML_OPAQUE_CALLBACK); if (root==NULL) { delete []xmldata; mxmlDelete(tree); node=root=tree=NULL; return(false); }; root=mxmlFindElement(tree,tree,"INFORMATION",NULL,NULL,MXML_DESCEND); push(root); if (root==NULL){ delete []xmldata; mxmlDelete(tree); node=root=tree=NULL; return(false); }; exitbranch(); if (tree!=NULL) mxmlDelete(tree); delete []xmldata; node=root=tree=NULL; return(true); };
int QtXmlWrapper::loadXMLfile(const std::string &filename) { const char *xmldata = doloadfile(filename.c_str()); if(xmldata == NULL) { qDebug() << "QtXmlWrapper::loadXMLfile(): empty data"; return -1; //the file could not be loaded or uncompressed } QByteArray b( xmldata ); while( !b.isEmpty() && b[0] != '<' ) { // remove first blank line b.remove( 0, 1 ); } if( !d->m_doc.setContent( b ) ) { qDebug() << "QtXmlWrapper::loadXMLfile(): could not set document content"; delete[] xmldata; return -2; } delete[] xmldata; d->m_node = d->m_doc.elementsByTagName( "ZynAddSubFX-data" ).at( 0 ).toElement(); if( d->m_node.isNull() || !d->m_node.isElement() ) { qDebug() << "QtXmlWrapper::loadXMLfile(): missing root node"; return -3; //the XML doesnt embbed zynaddsubfx data } QDomElement root = d->m_node.toElement(); //fetch version information version.Major = root.attribute( "version-major").toInt(); version.Minor = root.attribute( "version-minor").toInt(); version.Revision = root.attribute( "version-revision").toInt(); return 0; }