Example for writing a DOM tree to a stream

This commit is contained in:
jez_higgins 2003-04-28 09:54:23 +00:00
parent e094a4a8b4
commit 54b3663bcb
2 changed files with 213 additions and 0 deletions

View file

@ -0,0 +1,80 @@
// DOMWriter.cpp : Defines the entry point for the application.
//
#pragma warning(disable: 4786 4250 4503)
#include <iostream>
#include <string>
#include <DOM/SAX2DOM/SAX2DOM.h>
template<class stringT, class charT, class traitsT>
void doChildren(std::basic_ostream<charT, traitsT>& stream, DOM::Node<stringT>& node)
{
DOM::Node<stringT> child = node.getFirstChild();
while(child != 0)
{
stream << child;
child = child.getNextSibling();
} // while
} // doChildren
template<class stringT, class charT, class traitsT>
std::basic_ostream<charT, traitsT>&
operator<<(std::basic_ostream<charT, traitsT>& stream,
DOM::Node<stringT>& node)
{
switch(node.getNodeType())
{
case DOM::Node<stringT>::DOCUMENT_NODE:
doChildren(stream, node);
break;
case DOM::Node<stringT>::ELEMENT_NODE:
stream << "<" << node.getNodeName() << ">";
doChildren(stream, node);
stream << "</" << node.getNodeName() << ">";
break;
case DOM::Node<stringT>::TEXT_NODE:
stream << node.getNodeValue();
break;
} // switch
return stream;
} // operator<<
////////////////////////////////////////////////
int main(int argc, char* argv[])
{
if(argc < 2)
{
std::cout << "Usage : " << argv[0] << " xmlfile ... " << std::endl;
return 0;
} // if(argc < 2)
SAX2DOM::Parser<std::string> domParser;
for(int i = 1; i < argc; ++i)
{
std::string file(argv[i]);
SAX::InputSource is;
is.setSystemId(file);
if(file != "-")
domParser.parse(is);
else
{
is.setSystemId("stdin");
is.setByteStream(std::cin);
domParser.parse(is);
} // if(file != "-")
DOM::Document<std::string> doc = domParser.getDocument();
std::cout << doc;
} // for ...
return 0;
} // main
// end of file

View file

@ -0,0 +1,133 @@
<?xml version="1.0" encoding = "Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.00"
Name="DOMWriter"
ProjectGUID="{C1CF7801-1681-4F15-8D71-BBC814805AF2}"
Keyword="Win32Proj">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory=".\..\..\bin"
IntermediateDirectory="Debug"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\..\"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
MinimalRebuild="TRUE"
BasicRuntimeChecks="3"
RuntimeLibrary="5"
DisableLanguageExtensions="FALSE"
TreatWChar_tAsBuiltInType="TRUE"
RuntimeTypeInfo="TRUE"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="4"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
OutputFile="$(OutDir)/DOMWriter.exe"
LinkIncremental="2"
SuppressStartupBanner="TRUE"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="$(OutDir)/DOMWriter.pdb"
SubSystem="1"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory=".\..\..\bin"
IntermediateDirectory="Release"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
InlineFunctionExpansion="1"
OmitFramePointers="TRUE"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
StringPooling="TRUE"
RuntimeLibrary="4"
EnableFunctionLevelLinking="TRUE"
UsePrecompiledHeader="3"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
OutputFile="$(OutDir)/DOMWriter.exe"
LinkIncremental="1"
GenerateDebugInformation="TRUE"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
</Configuration>
</Configurations>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm">
<File
RelativePath="DOMWriter.cpp">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
TreatWChar_tAsBuiltInType="FALSE"/>
</FileConfiguration>
</File>
</Filter>
<Filter
Name="Libs"
Filter="">
<File
RelativePath="..\..\lib\SAX.lib">
</File>
<File
RelativePath="..\..\lib\Utilities.lib">
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>