[xiph-commits] r8319 - in trunk/oggdsf/src: lib/codecs/cmml/libCMMLTags lib/codecs/cmml/libWinCMMLParse tests/testCMMLParser

illiminable at motherfish-iii.xiph.org illiminable at motherfish-iii.xiph.org
Tue Nov 30 10:30:29 PST 2004


Author: illiminable
Date: 2004-11-30 10:30:28 -0800 (Tue, 30 Nov 2004)
New Revision: 8319

Modified:
   trunk/oggdsf/src/lib/codecs/cmml/libCMMLTags/C_CMMLDoc.cpp
   trunk/oggdsf/src/lib/codecs/cmml/libWinCMMLParse/CMMLParser.cpp
   trunk/oggdsf/src/lib/codecs/cmml/libWinCMMLParse/CMMLParser.h
   trunk/oggdsf/src/tests/testCMMLParser/testCMMLParser.cpp
Log:
* CMML Parser now parses from file, and performs structural validation.

Modified: trunk/oggdsf/src/lib/codecs/cmml/libCMMLTags/C_CMMLDoc.cpp
===================================================================
--- trunk/oggdsf/src/lib/codecs/cmml/libCMMLTags/C_CMMLDoc.cpp	2004-11-30 17:03:10 UTC (rev 8318)
+++ trunk/oggdsf/src/lib/codecs/cmml/libCMMLTags/C_CMMLDoc.cpp	2004-11-30 18:30:28 UTC (rev 8319)
@@ -37,12 +37,14 @@
 C_CMMLDoc::C_CMMLDoc(void)
 {
 	mPreamble = new C_CMMLPreamble;
+	mRoot = new C_CMMLRootTag;
 
 }
 
 C_CMMLDoc::~C_CMMLDoc(void)
 {
 	delete mPreamble;
+	delete mRoot;
 }
 
 C_CMMLPreamble* C_CMMLDoc::preamble() {

Modified: trunk/oggdsf/src/lib/codecs/cmml/libWinCMMLParse/CMMLParser.cpp
===================================================================
--- trunk/oggdsf/src/lib/codecs/cmml/libWinCMMLParse/CMMLParser.cpp	2004-11-30 17:03:10 UTC (rev 8318)
+++ trunk/oggdsf/src/lib/codecs/cmml/libWinCMMLParse/CMMLParser.cpp	2004-11-30 18:30:28 UTC (rev 8319)
@@ -70,8 +70,71 @@
 	}
 }
 
+bool CMMLParser::parseDocFromFile(wstring inFilename, C_CMMLDoc* outCMMLDoc) {
 
+	MSXML2::IXMLDOMDocument* locDoc		=	NULL;
+	MSXML2::IXMLDOMNode*		locNode =	NULL;
+	BSTR locQuery	= SysAllocString(L"cmml");;
+	VARIANT locFilename;
 
+	VariantInit(&locFilename);
+	V_BSTR(&locFilename) = SysAllocString(inFilename.c_str());
+	V_VT(&locFilename) = VT_BSTR;
+	//locFilename.vt = VT_BSTR;
+	//locFilename.bstrVal = SysAllocString(inFilename.c_str());
+
+
+	bool retVal = true;
+	HRESULT locHR = S_FALSE;
+
+	
+	locHR = CoCreateInstance(__uuidof(DOMDocument30), NULL, CLSCTX_INPROC_SERVER, IID_IXMLDOMDocument, (void**)&locDoc);
+	if (locHR != S_OK) {
+		retVal = false;
+	} else {
+	
+		
+		VARIANT_BOOL locBool = VARIANT_FALSE;
+		locDoc->put_validateOnParse(locBool);
+		
+		locHR = locDoc->load(locFilename, &locBool);
+		MSXML2::IXMLDOMParseError *locParseError = NULL;
+		locHR = locDoc->get_parseError(&locParseError);
+		long locEC = 0;
+		locParseError->get_errorCode(&locEC);
+		BSTR locStr;
+		locParseError->get_reason(&locStr);
+
+		
+
+		//--------------Child Nodes-----------------
+		locHR = locDoc->selectSingleNode(locQuery, &locNode);
+		if (locHR != S_OK) {
+			retVal = false;
+		} else {
+
+			C_CMMLRootTag* locRootTag = new C_CMMLRootTag;
+
+			retVal = parseCMMLRootTag(locNode, locRootTag);
+			if (retVal) {
+				outCMMLDoc->setRoot(locRootTag);	
+			} else {
+				delete locRootTag;
+			}
+		}
+	}
+
+	//SysFreeString(locFilename.bstrVal);
+	SysFreeString(locQuery);
+	if (&locFilename) VariantClear(&locFilename);
+	if (locDoc != NULL)			locDoc->Release();
+	if (locNode != NULL)		locNode->Release();
+
+	return retVal;
+}
+
+
+
 MSXML2::IXMLDOMNode* CMMLParser::getNamedNode(wstring inXPath, MSXML2::IXMLDOMDocument* inDoc) {
 	BSTR locQuery = SysAllocString(inXPath.c_str());
 	HRESULT locHR = S_FALSE;

Modified: trunk/oggdsf/src/lib/codecs/cmml/libWinCMMLParse/CMMLParser.h
===================================================================
--- trunk/oggdsf/src/lib/codecs/cmml/libWinCMMLParse/CMMLParser.h	2004-11-30 17:03:10 UTC (rev 8318)
+++ trunk/oggdsf/src/lib/codecs/cmml/libWinCMMLParse/CMMLParser.h	2004-11-30 18:30:28 UTC (rev 8319)
@@ -65,8 +65,11 @@
 	bool parseParamTag(MSXML2::IXMLDOMNode* inParamNode, C_ParamTag* outParam);
 	bool parseCMMLRootTag(MSXML2::IXMLDOMNode* inCMMLRootNode, C_CMMLRootTag* outCMMLRoot);
 
+	
+	bool CMMLParser::parseDocFromFile(wstring inFilename, C_CMMLDoc* outCMMLDoc);
 
 
+
 protected:
 	wstring getNamedAttribValue(wstring inAttribName, MSXML2::IXMLDOMNamedNodeMap* inAttribMap);
 	MSXML2::IXMLDOMNode* getNamedNode(wstring inXPath, MSXML2::IXMLDOMDocument* inDoc);

Modified: trunk/oggdsf/src/tests/testCMMLParser/testCMMLParser.cpp
===================================================================
--- trunk/oggdsf/src/tests/testCMMLParser/testCMMLParser.cpp	2004-11-30 17:03:10 UTC (rev 8318)
+++ trunk/oggdsf/src/tests/testCMMLParser/testCMMLParser.cpp	2004-11-30 18:30:28 UTC (rev 8319)
@@ -64,6 +64,24 @@
 
 }
 
+bool testCMMLFileParse(wstring inFilename) {
+	CMMLParser locParser;
+
+	C_CMMLDoc locDoc;
+	bool locWasOK = locParser.parseDocFromFile(inFilename, &locDoc);
+
+	wcout<<"Trying to parse "<<inFilename<<endl;
+
+	if (locWasOK) {
+		wcout<<locDoc.toString()<<endl;
+	} else {
+		wcout<<"*** PARSE FAILED ***"<<endl;
+	}
+
+	return locWasOK;
+
+}
+
 int __cdecl _tmain(int argc, _TCHAR* argv[])
 {
 	//Valid minimal
@@ -136,8 +154,15 @@
 	wstring cmml_5 = L"<blue><red>random stuff</red><green>But still valid XML</green></blue>";
 	testCMMLRootParse(cmml_5);
 
+	int x;
+	cin>>x;
 
+	wstring file_1 = L"testcmml.xml";
+	testCMMLFileParse(file_1);
 
+
+
+
 	return 0;
 }
 



More information about the commits mailing list