This section explains how to implement the MContentProcessor interface to parse, validate and autocorrect an XML document.
The parsed document can also be validated against a specification and auto-corrected for spelling errors in the validated text. This can be done by writing three applications - a parser, a validator and an autocorrector. These applications must implement the MContentProcessor interface.
Writing a content processor is similar to writing a content handler as explained in Parsing an XML Document. MContentProcessor is an extension of MContentHandler. Each application is writen by implementing the callback functions of MContentHandler. The only difference is that MContentProcessor has a mechanism for directing output, so that the output of the parser is the input to the validator, and the output of the validator is the input to the autocorrector.
Direct output of a content processor by implementing the SetContentSink() function, so that the parser outputs to the validator and the validator outputs to the autocorrector. A sequence of several applications linked in this way is called a Plug-in Chain.
Implement the MContentProcessor interface.
Implement the MContentProcessor::SetContentSink() function.
Perform the actual parsing.
Use a CParser object as explained in Choosing a Parser Plug-in. To ensure that parsing is followed by validation and autocorrection, associate the CParser object with the plug-in chain. This can be done by calling SetProcessorChainL() function of the CParser object with a list of the items in the plugin chain as a parameter.
The following code illustrates how to validate and autocorrect the parsed document:
RFs fs; User::LeaveIfError( fs.Connect() ); CleanupClosePushL( fs ); _LIT8( KXmlMimeType, "text/xml" ); TSimpleContentHandler sax; // You’ll have to implement this class… CParser* parser = CParser::NewLC( KXmlMimeType, sax ); RContentProcessorUids uids; uids.Append( KValidatorUid ); // The ECOM implementation UID of a validator plug-in CleanupClosePushL( uids ); // Sets up the chain of call-back events from the parser through to the // validating plug-in and then the client. parser->SetProcessorChainL( uids ); parser->ParseFileL( fs, KMyFile ); CleanupStack::PopAndDestroy( 3 );
Copyright ©2010 Nokia Corporation and/or its subsidiary(-ies).
All rights
reserved. Unless otherwise stated, these materials are provided under the terms of the Eclipse Public License
v1.0.