#include "cconsolestream.h"
#include "cfilestream.h"
#include "namespaces.h"
using namespace P6R;
using namespace P6EXAMPLES;
namespace {
{
if(
P6SUCCEEDED(err = cpFileInit->initialize(pszFilepath))) {
}
}
return err;
}
{
if(
P6SUCCEEDED(err = cpDOM->initialize(P6DOMXML_NOFLAGS,pOutStream))) {
}
}
return err;
}
{
if(
P6SUCCEEDED(err = cpXPath->initialize(P6XPATH_NOFLAGS,pOutStream))) {
}
}
return err;
}
{
if (
P6SUCCEEDED( err = cpInit->defineNamespace(
"start", 4,
"http://www.p6r.com/books/type1", (
P6UINT32)strlen(
"http://www.p6r.com/books/type1" )))) {
if (
P6SUCCEEDED( err = cpInit->defineNamespace(
"last", 4,
"http://www.p6r.com/books/type2", (
P6UINT32)strlen(
"http://www.p6r.com/books/type2" )))) {
}
}
}
}
return err;
}
{
"<?xml version='1.0' encoding='UTF-8' ?>" \
"<book xmlns:start='http://www.p6r.com/books/type1' " \
" xmlns:end='http://www.p6r.com/books/type2'>" \
"<title>P6R book of development</title>" \
"<TOC>" \
" <chapter>One</chapter>" \
" <chapter>Two</chapter>" \
"</TOC>" \
"<chapter>" \
" <section>" \
" <footnote>footnote 1.1.0</footnote>" \
" <para>1 2 3éé 4 5 6</para>" \
" <para>7 8 9 10 11</para>" \
" <testcase> abc <![CDATA[ abéc > 123 ]]> hey there </testcase>" \
" </section>" \
" <section>" \
" <para>a b c d e f g h</para>" \
" <footnote>footnote 1.2.0</footnote>" \
" <footnote id='ab'>footnote 1.2.1</footnote>" \
" </section>" \
"</chapter>" \
"<chapter>" \
" <para>0 0 0 0 0 0 </para>" \
" <section>" \
" <para>i j k l m n o p</para>" \
" <footnote>footnote 1.3.0</footnote>" \
" </section>" \
"</chapter>" \
"<index>" \
" <start:item>Index 1.0</start:item>" \
" <start:item>Index 2.0</start:item>" \
" <abc>" \
" <item>Index 2.1</item>" \
" <item>Index 2.2</item>" \
" </abc>" \
" <item>Index 3.0</item>" \
"</index>" \
"<appendixA>" \
" <end:item>appendix A 1.0</end:item>" \
" <end:item>appendix A 2.0</end:item>" \
"</appendixA>" \
"<appendixB>" \
" <end:item>appendix B 1.0</end:item>" \
" <end:item>appendix B 2.0</end:item>" \
" <end:item>appendix B 3.0</end:item>" \
"</appendixB>" \
"<appendixC>" \
" <end:item>appendix C 1.0</end:item>" \
" <abc>" \
" <item>appendix C 2.0</item>" \
" </abc>" \
"</appendixC>" \
"</book>";
cpStr->strlen( pXML, 100000, &bufSize );
if (
P6SUCCEEDED( err )) err = cpStream->processStream( pXML, bufSize );
cpStream = NULL;
err = cpXPath->compileExpression(
P6CTEXT(
"//last:item"), 19, cpContext );
if (
P6SUCCEEDED( err = cpXPath->eval( cpDOM, NULL, NULL, &result )))
{
pConsole->
writeStdout(
"Expected [ %1$ ] but got [ %2$ ]\n",&args[0],2,NULL);
return eFail;
}
number = 0;
if (number != 6) {
pConsole->
writeStdout(
"Expected [ 6 ] but got [ %1$ ]\n",&args[0],1,NULL);
return eFail;
}
count = 0;
{
retval = -1;
length = 200;
if (
P6SUCCEEDED( err = cpChild->toString( testStr, &length )))
{
switch( count ) {
case 0: err = cpStr->wstrncmp(
P6CTEXT(
"appendix A 1.0"), testStr, 14, &retval );
break;
case 1: err = cpStr->wstrncmp(
P6CTEXT(
"appendix A 2.0"), testStr, 14, &retval );
break;
case 2: err = cpStr->wstrncmp(
P6CTEXT(
"appendix B 1.0"), testStr, 14, &retval );
break;
case 3: err = cpStr->wstrncmp(
P6CTEXT(
"appendix B 2.0"), testStr, 14, &retval );
break;
case 4: err = cpStr->wstrncmp(
P6CTEXT(
"appendix B 3.0"), testStr, 14, &retval );
break;
case 5: err = cpStr->wstrncmp(
P6CTEXT(
"appendix C 1.0"), testStr, 14, &retval );
break;
}
if (retval != 0) {
pConsole->
writeStdout(
"Expected [ 0 ] but got [ %1$ ]\n",&args[0],1,NULL);
}
count++;
}
}
if (eEndOfRecord == err) err = eOk;
{
}
}
pConsole->
writeStdout(
"ERROR: Example failed with [ %1$ ]\n", &args[0], 1, NULL );
}
return err;
}
}
int main(int argc,char *argv[])
{
err = runDOM( cpConsole, cpDebugStream );
cpConsole->writeStdout("runDOM result: [ %1$ ]\n",&args[0],1,NULL);
cpConsole = NULL;
}
else printf("ERROR: Failed to retrieve console interface [ %x ]\n", err );
}
else printf("ERROR: Failed to initialize the loader [ %x ]\n", err );
}
else printf( "ERROR: Failed to create CConsoleStream [ %x ]\n", err );
return err;
}