dbertoni 01/09/28 08:19:13
Added: c/samples/SimpleXPathCAPI foo.xml SimpleXPathCAPI.c
SimpleXPathCAPI.dsp
Log:
Initial revision.
Revision Changes Path
1.1 xml-xalan/c/samples/SimpleXPathCAPI/foo.xml
Index: foo.xml
===================================================================
<?xml version="1.0"?>
<doc>
<name first="David" last="Marston"/>
<name first="David" last="Bertoni"/>
<name first="Donald" last="Leslie"/>
<name first="Emily" last="Farmer"/>
<name first="Myriam" last="Midy"/>
<name first="Paul" last="Dick"/>
<name first="Scott" last="Boag"/>
<name first="Shane" last="Curcuru"/>
<name first="Joseph" last="Kesselman"/>
<name first="Stephen" last="Auriemma"/>
</doc>
1.1 xml-xalan/c/samples/SimpleXPathCAPI/SimpleXPathCAPI.c
Index: SimpleXPathCAPI.c
===================================================================
// Base header file. Must be first.
#include <XPathCAPI/XPathCAPI.h>
#include <assert.h>
#include <malloc.h>
#include <stdio.h>
int
CreateXPath(
XalanXPathEvaluatorHandle theXalanHandle,
const char*
theXPathExpression,
XalanXPathHandle* theXPathHandle)
{
int theResult = 0;
assert(theXalanHandle);
assert(theXPathHandle);
theResult = XalanCreateXPath(theXalanHandle, theXPathExpression,
"foo-8", theXPathHandle);
if (theResult != XALAN_XPATH_API_SUCCESS)
{
fprintf(stderr, "Error creating XPath. Error code was %d.\n",
theResult);
}
return theResult;
}
int
DestroyXPath(
XalanXPathEvaluatorHandle theXalanHandle,
XalanXPathHandle theXPathHandle)
{
int theResult = 0;
theResult = XalanDestroyXPath(theXalanHandle, theXPathHandle);
if (theResult != XALAN_XPATH_API_SUCCESS)
{
fprintf(stderr, "Error creating XPath. Error code was %d.\n",
theResult);
}
return theResult;
}
char*
ReadFile(const char* theXMLFileName)
{
char* theBuffer = 0;
FILE* theFile = fopen(theXMLFileName, "rb");
if (theFile == 0)
{
fprintf(stderr, "Unable to open input file %s\n",
theXMLFileName);
}
else
{
fseek(theFile, 0, SEEK_END);
{
const int theSize = ftell(theFile);
if (theSize == -1)
{
fprintf(stderr, "Unable to determine the size
of the input file\n");
}
else
{
fseek(theFile, SEEK_SET, 0);
theBuffer = malloc(theSize + 1);
if (theBuffer == 0)
{
fprintf(stderr, "Unable to allocate
enough memory. The input file size is %d\n", theSize);
}
else
{
fread(theBuffer, 1, theSize, theFile);
theBuffer[theSize] = '\0';
}
}
}
}
return theBuffer;
}
int
EvaluateXPath(
XalanXPathEvaluatorHandle theXalanHandle,
const char*
theXMLFileName,
const char*
theXPathExpression,
int*
theBoolean)
{
XalanXPathHandle theXPathHandle;
int theResult =
CreateXPath(theXalanHandle, theXPathExpression, &theXPathHandle);
if (theResult == XALAN_XPATH_API_SUCCESS)
{
char* theBuffer = ReadFile(theXMLFileName);
if (theBuffer != NULL)
{
theResult = XalanEvaluateXPathAsBoolean(theXalanHandle,
theXPathHandle, theBuffer, theBoolean);
if (theResult != XALAN_XPATH_API_SUCCESS)
{
fprintf(stderr, "Unable to evaluate XPath
expression. Error code was %d.\n", theResult);
}
free(theBuffer);
}
DestroyXPath(theXalanHandle, theXPathHandle);
}
return theResult;
}
int
main(
int argc,
const char* argv[])
{
int theResult = 0;
if (argc != 3)
{
fprintf(stderr, "Usage: SimpleXPathAPI XMLFilePath
XPathExpression\n");
theResult = -1;
}
else
{
theResult = XalanXPathAPIInitialize();
if (theResult != XALAN_XPATH_API_SUCCESS)
{
fprintf(stderr, "Unable to initialize the API. Error
code was %d.\n", theResult);
}
else
{
XalanXPathEvaluatorHandle theXalanHandle;
theResult = XalanCreateXPathEvaluator(&theXalanHandle);
if (theResult != XALAN_XPATH_API_SUCCESS)
{
fprintf(stderr, "Error creating evaluator.
Error code was %d.\n", theResult);
}
else
{
int theBoolean = 0;
theResult = EvaluateXPath(theXalanHandle,
argv[1], argv[2], &theBoolean);
if (theResult == XALAN_XPATH_API_SUCCESS)
{
fprintf(stdout, "The result of the
expression was '%s'.", theBoolean == 0 ? "false" : "true");
}
theResult =
XalanDestroyXPathEvaluator(theXalanHandle);
if (theResult != XALAN_XPATH_API_SUCCESS)
{
fprintf(stderr, "Error destroying
evaluator. Error code was %d.\n", theResult);
}
}
theResult = XalanXPathAPITerminate();
if (theResult != XALAN_XPATH_API_SUCCESS)
{
fprintf(stderr, "Error terminating the API.
Error code was %d.\n", theResult);
}
}
}
return theResult;
};
1.1 xml-xalan/c/samples/SimpleXPathCAPI/SimpleXPathCAPI.dsp
Index: SimpleXPathCAPI.dsp
===================================================================
# Microsoft Developer Studio Project File - Name="SimpleXPathCAPI" - Package
Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=SimpleXPathCAPI - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "SimpleXPathCAPI.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "SimpleXPathCAPI.mak" CFG="SimpleXPathCAPI - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "SimpleXPathCAPI - Win32 Release" (based on "Win32 (x86) Console
Application")
!MESSAGE "SimpleXPathCAPI - Win32 Debug" (based on "Win32 (x86) Console
Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "SimpleXPathCAPI - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "..\..\Build\Win32\VC6\Release"
# PROP Intermediate_Dir "..\..\Build\Win32\VC6\Release\SimpleXPathCAPI"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D
"_MBCS" /YX /FD /c
# ADD CPP /nologo /MD /W4 /GR /GX /O2 /Ob2 /I "..\..\..\..\xml-xerces\c\src"
/I "..\..\src" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /FD /c
# SUBTRACT CPP /YX
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib
advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib
odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib
advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib
odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32
..\..\..\..\..\..\xml-xerces\c\Build\Win32\VC6\Release\xerces-c_1.lib /nologo
/subsystem:console /machine:I386
!ELSEIF "$(CFG)" == "SimpleXPathCAPI - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "..\..\Build\Win32\VC6\Debug"
# PROP Intermediate_Dir "..\..\Build\Win32\VC6\Debug\SimpleXPathCAPI"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D
"_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /MDd /W4 /Gm /GR /GX /Zi /Od /I
"..\..\..\..\xml-xerces\c\src" /I "..\..\src" /D "_CONSOLE" /D "WIN32" /D
"_DEBUG" /D "_MBCS" /YX /FD /GZ /c
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib
advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib
odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib
advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib
odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32
..\..\..\..\..\..\xml-xerces\c\Build\Win32\VC6\Debug\xerces-c_1D.lib /nologo
/subsystem:console /map /debug /machine:I386 /pdbtype:sept
!ENDIF
# Begin Target
# Name "SimpleXPathCAPI - Win32 Release"
# Name "SimpleXPathCAPI - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\SimpleXPathCAPI.c
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# End Target
# End Project
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]