[xml] Migration from MS XML and minimal build questions...

Sorry for the long post....

I have two questions for which I would be grateful if someone could answer....

I am currently using MSXML V6 but I am having difficulty with those systems that do not have this level installed.  Therefore I am looking for an alternative XML library callable from a MFC application.  libxml looks promising.

I am using SAX2 to validate a XML file against a fixed external XSD Schema (ignoring anything specified within the XML file).  Cutting out all the error checking, allocation etc., it looks something like:

 bool m_bValidation = true;
 ISAXXMLReaderPtr pSAXReader = NULL;
 hr = pSAXReader.CreateInstance(__uuidof(SAXXMLReader60));

 // Create ContentHandler object
 mySAXContentHandler* pCH = new mySAXContentHandler();

 // Create ErrorHandler object
 mySAXErrorHandler* pEH = new mySAXErrorHandler();

 // Set Content Handler
 hr = pSAXReader->putContentHandler(pCH);

 // Set Error Handler
 hr = pSAXReader->putErrorHandler(pEH);

 // Get ready for XSD schema validation
 IXMLDOMSchemaCollection2Ptr pSchemaCache = NULL;
 hr = pSchemaCache.CreateInstance(__uuidof(XMLSchemaCache60));

 // Add the XSD file to the Schema cache
 CComVariant cvXSDFileName;
 cvXSDFileName.vt = VT_BSTR;
 cvXSDFileName.bstrVal = strXSDFileName.AllocSysString();
 hr = pSchemaCache->add(L"", cvXSDFileName);

 // Want all errors
 hr = pSAXReader->putFeature(L"exhaustive-errors", VARIANT_TRUE);
 // Want to validate XML file
 hr = pSAXReader->putFeature(L"schema-validation", VARIANT_TRUE);
 // Ignore any schema specified in the XML file
 hr = pSAXReader->putFeature(L"use-schema-location", VARIANT_FALSE);
 // Don't allow user to override validation by using DTDs
 hr = pSAXReader->putFeature(L"prohibit-dtd", VARIANT_TRUE);
 // Ignore any schema embedded in the XML file
 hr = pSAXReader->putFeature(L"use-inline-schema", VARIANT_FALSE);
 // Only use my XSD
 hr = pSAXReader->putProperty(L"schemas", _variant_t( pSchemaCache.GetInterfacePtr()));

 // Parse it
 hr = pSAXReader->parseURL(xmlFileName);

Assuming it validates OK, I then parse again but this time actually process the content by setting "m_bValidation = false;", which is accessible to the content handlers.  If it doesn't parse OK, I pass on to the user all the error messages from MS's library about what was found to be wrong.

So, my first question is:

Q. What would be the equivalent of the above in "libxml2"?

I would like to build a 'minimal' version of libxml2.dll (under VS2005 - VC8) that just has enough in it to do what I require - SAX2, validation using a fixed specified external XSD schema (elements are only one of types: string, integer, date or time), some elements have attributes required or optional, most (but not all) character data is in CDATA blocks and, of course, parsing (startDocument, startElement, characters, endElement and endDocument).  However, the file " configure.js" has so many options that I don't know which ones I need and which ones I can remove for my minimal libray.

So my last question is:

Q. Which options must I have to do what I want to do and which ones don't I need and can set to false?



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