dbertoni 2003/01/23 18:33:41
Added: c/samples/TransformToXercesDOM birds.xml birds.xsl
TransformToXercesDOM.cpp TransformToXercesDOM.dsp
Log:
New sample.
Revision Changes Path
1.1 xml-xalan/c/samples/TransformToXercesDOM/birds.xml
Index: birds.xml
===================================================================
<?xml version="1.0" encoding="UTF-8"?>
<Class>
<Order Name="TINAMIFORMES">
<Family Name="TINAMIDAE">
<Species Scientific_Name="Tinamus major"> Great Tinamou.</Species>
<Species Scientific_Name="Nothocercus">Highland Tinamou.</Species>
<Species Scientific_Name="Crypturellus soui">Little Tinamou.</Species>
<Species Scientific_Name="Crypturellus cinnamomeus">Thicket
Tinamou.</Species>
<Species Scientific_Name="Crypturellus boucardi">Slaty-breasted
Tinamou.</Species>
<Species Scientific_Name="Crypturellus kerriae">Choco Tinamou.</Species>
</Family>
</Order>
<Order Name="GAVIIFORMES">
<Family Name="GAVIIDAE">
<Species Scientific_Name="Gavia stellata">Red-throated Loon.</Species>
<Species Scientific_Name="Gavia arctica">Arctic Loon.</Species>
<Species Scientific_Name="Gavia pacifica">Pacific Loon.</Species>
<Species Scientific_Name="Gavia immer">Common Loon.</Species>
<Species Scientific_Name="Gavia adamsii">Yellow-billed Loon.</Species>
</Family>
</Order>
<Order Name="PODICIPEDIFORMES">
<Family Name="PODICIPEDIDAE">
<Species Scientific_Name="Tachybaptus dominicus">Least Grebe.</Species>
<Species Scientific_Name="Podilymbus podiceps">Pied-billed
Grebe.</Species>
<Species Scientific_Name="">Atitlan Grebe.</Species>
<Species Scientific_Name="">Horned Grebe.</Species>
<Species Scientific_Name="">Red-necked Grebe.</Species>
<Species Scientific_Name="">Eared Grebe.</Species>
<Species Scientific_Name="">Western Grebe.</Species>
<Species Scientific_Name="">Clark's Grebe.</Species>
<Species Scientific_Name=""/>
</Family>
</Order>
<Order Name="PROCELLARIIFORMES">
<Family Name="DIOMEDEIDAE">
<Species Scientific_Name="Thalassarche chlororhynchos">Yellow-nosed
Albatross. (A)</Species>
<Species Scientific_Name="Thalassarche cauta">Shy Albatross.
(A)</Species>
<Species Scientific_Name="Thalassarche melanophris">Black-browed
Albatross. (A)</Species>
<Species Scientific_Name="Phoebetria palpebrata">Light-mantled
Albatross. (A)</Species>
<Species Scientific_Name="Diomedea exulans">Wandering Albatross.
(A)</Species>
<Species Scientific_Name="Phoebastria immutabilis">Laysan
Albatross.</Species>
<Species Scientific_Name="Phoebastria nigripes">Black-footed
Albatross.</Species>
<Species Scientific_Name="Phoebastria albatrus">Short-tailed Albatross.
(N)</Species>
</Family>
<Family Name="PROCELLARIIDAE">
<Species Scientific_Name="Fulmarus glacialis">Northern Fulmar.</Species>
<Species Scientific_Name="Pterodroma neglecta">Kermadec Petrel.
(A)</Species>
<Species Scientific_Name="Pterodroma arminjoniana">Herald Petrel.
(A)</Species>
<Species Scientific_Name="Pterodroma ultima">Murphy's Petrel.
(N)</Species>
<Species Scientific_Name="Pterodroma inexpectata">Mottled Petrel.
(A)</Species>
<Species Scientific_Name="Pterodroma cahow">Bermuda Petrel.</Species>
<Species Scientific_Name="Pterodroma hasitata">Black-capped
Petrel.</Species>
<Species Scientific_Name="Pterodroma externa">Juan Fernandez Petrel.
(N)</Species>
<Species Scientific_Name="Pterodroma phaeopygia">Dark-rumped
Petrel.</Species>
<Species Scientific_Name="Pterodroma cervicalis">White-necked Petrel.
(H)</Species>
<Species Scientific_Name="Pterodroma hypoleuca">Bonin Petrel.
(H)</Species>
<Species Scientific_Name="Pterodroma nigripennis">Black-winged Petrel.
(H, A)</Species>
<Species Scientific_Name="Pterodroma cookii">Cook's Petrel. (N)</Species>
<Species Scientific_Name="Pterodroma longirostris">Stejneger's Petrel.
(A)</Species>
<Species Scientific_Name="Bulweria bulwerii">Bulwer's Petrel.
(H)</Species>
<Species Scientific_Name="Bulweria fallax">Jouanin's Petrel. (H,
A)</Species>
<Species Scientific_Name="Procellaria parkinsoni">Parkinson's Petrel.
(N)</Species>
<Species Scientific_Name="Calonectris leucomelas">Streaked Shearwater.
(A)</Species>
<Species Scientific_Name="Calonectris diomedea">Cory's Shearwater.
(N)</Species>
<Species Scientific_Name="Puffinus creatopus">Pink-footed Shearwater.
(N)</Species>
<Species Scientific_Name="Puffinus carneipes">Flesh-footed Shearwater.
(N)</Species>
<Species Scientific_Name="Puffinus gravis">Greater Shearwater.
(N)</Species>
<Species Scientific_Name="Puffinus pacificus">Wedge-tailed
Shearwater.</Species>
<Species Scientific_Name="Puffinus bulleri">Buller's Shearwater.
(N)</Species>
<Species Scientific_Name="Puffinus griseus">Sooty Shearwater.
(N)</Species>
<Species Scientific_Name="Puffinus tenuirostris">Short-tailed
Shearwater. (N)</Species>
<Species Scientific_Name="Puffinus nativitatis">Christmas Shearwater.
(H)</Species>
<Species Scientific_Name="Puffinus puffinus">Manx Shearwater.</Species>
<Species Scientific_Name="Puffinus auricularis">Townsend's
Shearwater.</Species>
<Species Scientific_Name="Puffinus opisthomelas">Black-vented
Shearwater.</Species>
<Species Scientific_Name="Puffinus lherminieri">Audubon's
Shearwater.</Species>
<Species Scientific_Name="Puffinus assimilis">Little Shearwater.
(A)</Species>
</Family>
<Family Name="HYDROBATIDAE">
<Species Scientific_Name="Oceanites oceanicus">Wilson's Storm-Petrel.
(N)</Species>
<Species Scientific_Name="Pelagodroma marina">White-faced Storm-Petrel.
(A)</Species>
<Species Scientific_Name="Hydrobates pelagicus">European Storm-Petrel.
(A)</Species>
<Species Scientific_Name="Oceanodroma furcata">Fork-tailed
Storm-Petrel.</Species>
<Species Scientific_Name="Oceanodroma leucorhoa">Leach's
Storm-Petrel.</Species>
<Species Scientific_Name="Oceanodroma homochroa">Ashy
Storm-Petrel.</Species>
<Species Scientific_Name="Oceanodroma castro">Band-rumped Storm-Petrel.
(N)</Species>
<Species Scientific_Name="Oceanodroma tethys">Wedge-rumped Storm-Petrel.
(N)</Species>
<Species Scientific_Name="Oceanodroma melania">Black
Storm-Petrel.</Species>
<Species Scientific_Name="Oceanodroma macrodactyla">Guadalupe
Storm-Petrel.</Species>
<Species Scientific_Name="Oceanodroma markhami">Markham's Storm-Petrel.
(A)</Species>
<Species Scientific_Name="Oceanodroma tristrami">Tristram's
Storm-Petrel. (H)</Species>
<Species Scientific_Name="Oceanodroma microsoma">Least
Storm-Petrel.</Species>
</Family>
</Order>
<Order Name="PELECANIFORMES">
<Family Name="PHAETHONTIDAE">
<Species Scientific_Name="Phaethon lepturus">White-tailed
Tropicbird.</Species>
<Species Scientific_Name="Phaethon aethereus">Red-billed
Tropicbird.</Species>
<Species Scientific_Name="Phaethon rubricauda">Red-tailed
Tropicbird.</Species>
</Family>
<Family Name="SULIDAE">
<Species Scientific_Name="Sula dactylatra">Masked Booby.</Species>
<Species Scientific_Name="Sula nebouxii">Blue-footed Booby.</Species>
<Species Scientific_Name="Sula variegata">Peruvian Booby. (A)</Species>
<Species Scientific_Name="Sula leucogaster">Brown Booby.</Species>
<Species Scientific_Name="Sula sula">Red-footed Booby.</Species>
<Species Scientific_Name="Morus bassanus">Northern Gannet.</Species>
</Family>
<Family Name="PELECANIDAE">
<Species Scientific_Name="Pelecanus erythrorhynchos">American White
Pelican.</Species>
<Species Scientific_Name="Pelecanus occidentalis">Brown
Pelican.</Species>
</Family>
<Family Name="PHALACROCORACIDAE">
<Species Scientific_Name="Phalacrocorax penicillatus">Brandt's
Cormorant.</Species>
<Species Scientific_Name="Phalacrocorax brasilianus">Neotropic
Cormorant.</Species>
<Species Scientific_Name="Phalacrocorax auritus">Double-crested
Cormorant.</Species>
<Species Scientific_Name="Phalacrocorax carbo">Great Cormorant.</Species>
<Species Scientific_Name="Phalacrocorax urile">Red-faced
Cormorant.</Species>
<Species Scientific_Name="Phalacrocorax pelagicus">Pelagic
Cormorant.</Species>
</Family>
<Family Name="ANHINGIDAE">
<Species Scientific_Name="Anhinga anhinga">Anhinga.</Species>
</Family>
<Family Name="FREGATIDAE">
<Species Scientific_Name="Fregata magnificens">Magnificent
Frigatebird.</Species>
<Species Scientific_Name="Fregata minor">Great Frigatebird.</Species>
<Species Scientific_Name="Fregata ariel">Lesser Frigatebird.
(A)</Species>
</Family>
</Order>
</Class>
1.1 xml-xalan/c/samples/TransformToXercesDOM/birds.xsl
Index: birds.xsl
===================================================================
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="Class">
<BirdInfo>
<xsl:apply-templates select="Order"/>
</BirdInfo>
</xsl:template>
<xsl:template match="Order">
Order is: <xsl:value-of select="@Name"/>
<xsl:apply-templates select="Family"/><xsl:text>
</xsl:text>
</xsl:template>
<xsl:template match="Family">
Family is: <xsl:value-of select="@Name"/>
<xsl:apply-templates select="Species | SubFamily | text()"/>
</xsl:template>
<xsl:template match="SubFamily">
SubFamily is <xsl:value-of select="@Name"/>
<xsl:apply-templates select="Species | text()"/>
</xsl:template>
<xsl:template match="Species">
<xsl:choose>
<xsl:when test="name(..)='SubFamily'">
<xsl:text> </xsl:text><xsl:value-of select="."/><xsl:text>
</xsl:text><xsl:value-of select="@Scientific_Name"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="."/><xsl:text> </xsl:text><xsl:value-of
select="@Scientific_Name"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
1.1
xml-xalan/c/samples/TransformToXercesDOM/TransformToXercesDOM.cpp
Index: TransformToXercesDOM.cpp
===================================================================
// Base header file. Must be first.
#include <Include/PlatformDefinitions.hpp>
#include <cassert>
#if defined(XALAN_CLASSIC_IOSTREAMS)
#include <iostream.h>
#else
#include <iostream>
#endif
#include <xercesc/dom/impl/DOMDocumentImpl.hpp>
#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/framework/LocalFileInputSource.hpp>
#include <XalanDOM/XalanDocument.hpp>
#include <XalanDOM/XalanElement.hpp>
#include <PlatformSupport/XalanOutputStreamPrintWriter.hpp>
#include <PlatformSupport/XalanStdOutputStream.hpp>
#include <XMLSupport/FormatterToXML.hpp>
#include <XercesParserLiaison/FormatterToXercesDOM.hpp>
#include <XercesParserLiaison/XercesDOMFormatterWalker.hpp>
#include <XalanTransformer/XalanTransformer.hpp>
XALAN_USING_STD(cerr)
XALAN_USING_STD(cout)
XALAN_USING_STD(endl)
XALAN_USING_XERCES(DOMDocument)
XALAN_USING_XALAN(XalanCompiledStylesheet)
XALAN_USING_XALAN(XalanParsedSource)
XALAN_USING_XALAN(XalanTransformer)
void
serialize(const DOMDocument& theDocument)
{
XALAN_USING_XALAN(XalanStdOutputStream)
XALAN_USING_XALAN(XalanOutputStreamPrintWriter)
XALAN_USING_XALAN(FormatterToXML)
XALAN_USING_XALAN(XercesDOMFormatterWalker)
// OK, we're going to serialize the nodes that were
// found. We should really check to make sure the
// root (document) has not been selected, since we
// really can't serialize a node list with the root.
XalanStdOutputStream theStream(cout);
XalanOutputStreamPrintWriter thePrintWriter(theStream);
FormatterToXML theFormatter(thePrintWriter);
XercesDOMFormatterWalker theWalker(theFormatter);
theWalker.traverse(&theDocument);
}
int
transformAndSerialize(
XalanTransformer& theTransformer,
const XalanParsedSource& theParsedSource,
const XalanCompiledStylesheet& theStylesheet)
{
XALAN_USING_XERCES(DOMDocumentImpl)
XALAN_USING_XALAN(FormatterToXercesDOM)
DOMDocumentImpl theDocument;
FormatterToXercesDOM theFormatter(&theDocument, 0);
int theResult =
theTransformer.transform(
theParsedSource,
&theStylesheet,
theFormatter);
if (theResult != 0)
{
cerr << "Error transforming: "
<< theTransformer.getLastError()
<< endl;
}
else
{
serialize(theDocument);
}
return theResult;
}
int
main(
int argc,
const char* argv[])
{
int theResult = 0;
if (argc != 3)
{
cerr << "Usage: TransformToXercesDOM XMLFilePath XSLFilePath" << endl;
theResult = -1;
}
else
{
try
{
XALAN_USING_XERCES(XMLPlatformUtils)
XMLPlatformUtils::Initialize();
XalanTransformer::initialize();
{
XalanTransformer theTransformer;
XalanParsedSource* theParsedSource = 0;
theResult = theTransformer.parseSource(argv[1],
theParsedSource);
if (theResult != 0)
{
cerr << "Error parsing source document: "
<< theTransformer.getLastError()
<< endl;
}
else
{
assert(theParsedSource != 0);
XalanCompiledStylesheet*
theCompiledStylesheet = 0;
theResult =
theTransformer.compileStylesheet(argv[2], theCompiledStylesheet);
if (theResult != 0)
{
cerr << "Error compiling stylesheet: "
<<
theTransformer.getLastError()
<< endl;
}
else
{
theResult =
transformAndSerialize(theTransformer, *theParsedSource, *theCompiledStylesheet);
}
}
}
XalanTransformer::terminate();
XMLPlatformUtils::Terminate();
}
catch(...)
{
cerr << "Exception caught!" << endl;
theResult = -1;
}
}
return theResult;
}
1.1
xml-xalan/c/samples/TransformToXercesDOM/TransformToXercesDOM.dsp
Index: TransformToXercesDOM.dsp
===================================================================
# Microsoft Developer Studio Project File - Name="TransformToXercesDOM" - Package
Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=TransformToXercesDOM - 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 "TransformToXercesDOM.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 "TransformToXercesDOM.mak" CFG="TransformToXercesDOM - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "TransformToXercesDOM - Win32 Release" (based on "Win32 (x86) Console
Application")
!MESSAGE "TransformToXercesDOM - 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)" == "TransformToXercesDOM - 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\TransformToXercesDOM"
# 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 xerces-c_2.lib /nologo /subsystem:console /machine:I386
/libpath:"..\..\..\..\xml-xerces\c\Build\Win32\VC6\Release"
!ELSEIF "$(CFG)" == "TransformToXercesDOM - 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\TransformToXercesDOM"
# 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 xerces-c_2D.lib /nologo /subsystem:console /map /debug /machine:I386
/pdbtype:sept /libpath:"..\..\..\..\xml-xerces\c\Build\Win32\VC6\Debug"
!ENDIF
# Begin Target
# Name "TransformToXercesDOM - Win32 Release"
# Name "TransformToXercesDOM - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\TransformToXercesDOM.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
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]