|
// Filename: TestConsole.cpp
// 2005-07-29 nschan Initial revision.
// Simple console app to test the CWXmlParser wrapper class
// that supports wide-char strings.
#include "stdafx.h"
#include "XmlParser.h"
#include <windows.h>
#include <comdef.h>
class CWXmlTester : public IWXmlElementHandler
{
public:
CWXmlTester()
{
m_xmlParser = new CWXmlParser;
m_xmlParser->AttachElementHandler(this);
}
~CWXmlTester()
{
delete m_xmlParser;
}
void Parse(const std::wstring& xmlPath)
{
m_xmlParser->SetParserFeature(L"schema-validation", true);
m_xmlParser->SetParserFeature(L"use-schema-location", false);
wprintf(L"\nParse 1...\n");
m_xmlParser->AddValidationSchema(L"urn:books", L"..\\TestXmlSupport\\books2.xsd");
m_xmlParser->Parse(xmlPath);
wprintf(L"\nParse 2...\n");
m_xmlParser->RemoveValidationSchema(L"urn:books");
m_xmlParser->Parse(xmlPath);
}
virtual void OnXmlStartElement(const CWXmlElement& xmlElement)
{
wprintf(L"%s\n", xmlElement.ToString().c_str());
}
virtual void OnXmlElementData(const std::wstring& elementData, int depth)
{
for(int i = 0; i < depth; ++i)
wprintf(L" ");
wprintf(L"%s\n", elementData.c_str());
}
virtual void OnXmlEndElement(const CWXmlElement& xmlElement)
{
wprintf(L"%s\n", xmlElement.ToString().c_str());
}
virtual void OnXmlError(int line, int column, const std::wstring& errorText, unsigned long errorCode)
{
wprintf(L"line %d, column %d: %s, errorCode=%d\n",
line, column, errorText.c_str(), errorCode);
}
virtual bool OnXmlAbortParse(const CWXmlElement& xmlElement)
{
// Uncomment this if you want to test abort.
//
// if ( xmlElement.GetAttributeValue(L"id") == L"bk002" )
// return true;
return false;
}
private:
CWXmlParser* m_xmlParser;
};
int main(int argc, char* argv[])
{
printf("Hello World!\n");
CWXmlTester xmlTester;
xmlTester.Parse(L"..\\TestXmlSupport\\books2.xml");
return 0;
}
// END
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.