You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by db...@apache.org on 2001/04/27 22:57:55 UTC
cvs commit: xml-xalan/c/samples/DocumentBuilder DocumentBuilder.cpp DocumentBuilder.dsp foo.out foo.xsl
dbertoni 01/04/27 13:57:55
Added: c/samples/DocumentBuilder DocumentBuilder.cpp
DocumentBuilder.dsp foo.out foo.xsl
Log:
Initial revision.
Revision Changes Path
1.1 xml-xalan/c/samples/DocumentBuilder/DocumentBuilder.cpp
Index: DocumentBuilder.cpp
===================================================================
// Base header file. Must be first.
#include <Include/PlatformDefinitions.hpp>
#if !defined(NDEBUG) && defined(_MSC_VER)
#include <crtdbg.h>
#endif
#include <sax2/ContentHandler.hpp>
#include <util/PlatformUtils.hpp>
#include <PlatformSupport/AttributesImpl.hpp>
#include <XalanTransformer/XalanTransformer.hpp>
void
BuildDocument(XalanDocumentBuilder* theBuilder)
{
// Get the SAX2 ContentHandler from the builder...
ContentHandler* const theContentHandler = theBuilder->getContentHandler();
assert(theContentHandler != 0);
// This will hold the attributes for the elements we create...
AttributesImpl theAttributes;
// Some handy scratch strings for adding elements, attributes, and text nodes...
XalanDOMString theElementName;
XalanDOMString theAttributeName;
XalanDOMString theAttributeValue;
const XalanDOMString theAttributeType("CDATA");
XalanDOMString theTextValue;
const XalanDOMChar theEmptyString = 0;
// start the document...
theContentHandler->startDocument();
// start the document element...
assign(theElementName, XALAN_STATIC_UCODE_STRING("foo"));
theContentHandler->startElement(&theEmptyString, &theEmptyString, c_wstr(theElementName), theAttributes);
// Create an element child...
// Set the name of the element...
assign(theElementName, XALAN_STATIC_UCODE_STRING("foobar"));
// Add an attribute...
assign(theAttributeName, XALAN_STATIC_UCODE_STRING("attribute1"));
assign(theAttributeValue, XALAN_STATIC_UCODE_STRING("value1"));
theAttributes.addAttribute(c_wstr(theAttributeName), c_wstr(theAttributeType), c_wstr(theAttributeValue));
theContentHandler->startElement(&theEmptyString, &theEmptyString, c_wstr(theElementName), theAttributes);
// Add a text node...
assign(theTextValue, XALAN_STATIC_UCODE_STRING("The first foobar"));
theContentHandler->characters(c_wstr(theTextValue), length(theTextValue));
// End the element...
theContentHandler->endElement(&theEmptyString, &theEmptyString, c_wstr(theElementName));
theAttributes.clear();
assign(theAttributeName, XALAN_STATIC_UCODE_STRING("attribute2"));
assign(theAttributeValue, XALAN_STATIC_UCODE_STRING("value2"));
theAttributes.addAttribute(c_wstr(theAttributeName), c_wstr(theAttributeType), c_wstr(theAttributeValue));
theContentHandler->startElement(&theEmptyString, &theEmptyString, c_wstr(theElementName), theAttributes);
assign(theTextValue, XALAN_STATIC_UCODE_STRING("The second foobar"));
theContentHandler->characters(c_wstr(theTextValue), length(theTextValue));
theContentHandler->endElement(&theEmptyString, &theEmptyString, c_wstr(theElementName));
theAttributes.clear();
assign(theAttributeName, XALAN_STATIC_UCODE_STRING("attribute3"));
assign(theAttributeValue, XALAN_STATIC_UCODE_STRING("value3"));
theAttributes.addAttribute(c_wstr(theAttributeName), c_wstr(theAttributeType), c_wstr(theAttributeValue));
theContentHandler->startElement(&theEmptyString, &theEmptyString, c_wstr(theElementName), theAttributes);
assign(theTextValue, XALAN_STATIC_UCODE_STRING("The third foobar"));
theContentHandler->characters(c_wstr(theTextValue), length(theTextValue));
theContentHandler->endElement(&theEmptyString, &theEmptyString, c_wstr(theElementName));
// end the document element...
assign(theElementName, XALAN_STATIC_UCODE_STRING("foo"));
theContentHandler->endElement(&theEmptyString, &theEmptyString, c_wstr(theElementName));
// end the document...
theContentHandler->endDocument();
}
int
main(
int argc,
const char* /* argv */ [])
{
#if !defined(XALAN_USE_ICU) && !defined(NDEBUG) && defined(_MSC_VER)
_CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_LEAK_CHECK_DF);
_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
_CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
#endif
#if !defined(XALAN_NO_NAMESPACES)
using std::cerr;
using std::endl;
#endif
int theResult = 0;
if (argc != 1)
{
cerr << "Usage: DocumentBuilder" << endl;
theResult = -1;
}
else
{
// Call the static initializer for Xerces.
XMLPlatformUtils::Initialize();
// Initialize Xalan.
XalanTransformer::initialize();
{
// Create a XalanTransformer.
XalanTransformer theXalanTransformer;
// Our stylesheet file. The assumption is that the executable will be run
// from same directory as the file.
const char* const theXSLFileName = "foo.xsl";
// Our output target...
const char* const theOutputFileName = "foo.out";
// Get a document builder from the transformer...
XalanDocumentBuilder* const theBuilder = theXalanTransformer.createDocumentBuilder();
BuildDocument(theBuilder);
// Do the transform.
theResult = theXalanTransformer.transform(*theBuilder, theXSLFileName, theOutputFileName);
if(theResult != 0)
{
cerr << "DocumentBuilder error: \n" << theXalanTransformer.getLastError()
<< endl
<< endl;
}
}
// Terminate Xalan.
XalanTransformer::terminate();
// Call the static terminator for Xerces.
XMLPlatformUtils::Terminate();
}
return theResult;
}
1.1 xml-xalan/c/samples/DocumentBuilder/DocumentBuilder.dsp
Index: DocumentBuilder.dsp
===================================================================
# Microsoft Developer Studio Project File - Name="DocumentBuilder" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=DocumentBuilder - 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 "DocumentBuilder.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 "DocumentBuilder.mak" CFG="DocumentBuilder - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "DocumentBuilder - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "DocumentBuilder - 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)" == "DocumentBuilder - 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\DocumentBuilder"
# 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)" == "DocumentBuilder - 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\DocumentBuilder"
# 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 "WIN32" /D "_DEBUG" /D "_CONSOLE" /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 /debug /machine:I386 /pdbtype:sept
!ENDIF
# Begin Target
# Name "DocumentBuilder - Win32 Release"
# Name "DocumentBuilder - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\DocumentBuilder.cpp
# 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
1.1 xml-xalan/c/samples/DocumentBuilder/foo.out
Index: foo.out
===================================================================
<?xml version="1.0" encoding="UTF-8"?>
<out><foobar attribute1="value1">The first foobar</foobar><foobar attribute2="value2">The second foobar</foobar><foobar attribute3="value3">The third foobar</foobar></out>
1.1 xml-xalan/c/samples/DocumentBuilder/foo.xsl
Index: foo.xsl
===================================================================
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="foo">
<out><xsl:apply-templates select="*"/></out>
</xsl:template>
<xsl:template match="foobar">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org