mirror of
https://github.com/jezhiggins/arabica
synced 2024-12-26 21:58:39 +01:00
*** empty log message ***
This commit is contained in:
parent
5403308ed3
commit
5e7e8ce0a4
5 changed files with 247 additions and 7 deletions
|
@ -5,7 +5,64 @@
|
|||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
#include <DOM/SAX2DOM/SAX2DOM.h>
|
||||
#include <XML/UnicodeCharacters.h>
|
||||
|
||||
template<typename char_type, typename traits_type>
|
||||
class escaper
|
||||
{
|
||||
private:
|
||||
typedef char_type charT;
|
||||
typedef traits_type traitsT;
|
||||
typedef std::basic_ostream<charT, traitsT> ostreamT;
|
||||
typedef Unicode<charT> UnicodeT;
|
||||
|
||||
public:
|
||||
escaper(ostreamT& stream) : stream_(stream) { }
|
||||
void operator()(charT ch)
|
||||
{
|
||||
if(ch == UnicodeT::LESS_THAN_SIGN)
|
||||
{
|
||||
stream_ << UnicodeT::AMPERSAND
|
||||
<< UnicodeT::LOWERCASE_L
|
||||
<< UnicodeT::LOWERCASE_T
|
||||
<< UnicodeT::SEMI_COLON;
|
||||
return;
|
||||
} // if(ch == UnicodeT::LESS_THAN_SIGN)
|
||||
if(ch == UnicodeT::GREATER_THAN_SIGN)
|
||||
{
|
||||
stream_ << UnicodeT::AMPERSAND
|
||||
<< UnicodeT::LOWERCASE_G
|
||||
<< UnicodeT::LOWERCASE_T
|
||||
<< UnicodeT::SEMI_COLON;
|
||||
return;
|
||||
} // if(ch == UnicodeT::GREATER_THAN_SIGN)
|
||||
if(ch == UnicodeT::AMPERSAND)
|
||||
{
|
||||
stream_ << UnicodeT::AMPERSAND
|
||||
<< UnicodeT::LOWERCASE_A
|
||||
<< UnicodeT::LOWERCASE_M
|
||||
<< UnicodeT::LOWERCASE_P
|
||||
<< UnicodeT::SEMI_COLON;
|
||||
return;
|
||||
} // if(ch == case UnicodeT::AMPERSAND)
|
||||
if(ch == UnicodeT::QUOTATION_MARK)
|
||||
{
|
||||
stream_ << UnicodeT::AMPERSAND
|
||||
<< UnicodeT::LOWERCASE_Q
|
||||
<< UnicodeT::LOWERCASE_U
|
||||
<< UnicodeT::LOWERCASE_O
|
||||
<< UnicodeT::LOWERCASE_T
|
||||
<< UnicodeT::SEMI_COLON;
|
||||
return;
|
||||
} // if(ch == UnicodeT::QUOTATION_MARK)
|
||||
stream_ << ch;
|
||||
} // operator()
|
||||
|
||||
private:
|
||||
ostreamT& stream_;
|
||||
}; // escaper
|
||||
|
||||
template<class stringT, class charT, class traitsT>
|
||||
void doChildren(std::basic_ostream<charT, traitsT>& stream, DOM::Node<stringT>& node)
|
||||
|
@ -24,18 +81,99 @@ std::basic_ostream<charT, traitsT>&
|
|||
operator<<(std::basic_ostream<charT, traitsT>& stream,
|
||||
DOM::Node<stringT>& node)
|
||||
{
|
||||
typedef Unicode<charT> UnicodeT;
|
||||
|
||||
switch(node.getNodeType())
|
||||
{
|
||||
case DOM::Node<stringT>::DOCUMENT_NODE:
|
||||
stream << UnicodeT::LESS_THAN_SIGN
|
||||
<< UnicodeT::QUESTION_MARK
|
||||
<< UnicodeT::LOWERCASE_X
|
||||
<< UnicodeT::LOWERCASE_M
|
||||
<< UnicodeT::LOWERCASE_L
|
||||
<< UnicodeT::SPACE
|
||||
<< UnicodeT::LOWERCASE_V
|
||||
<< UnicodeT::LOWERCASE_E
|
||||
<< UnicodeT::LOWERCASE_R
|
||||
<< UnicodeT::LOWERCASE_S
|
||||
<< UnicodeT::LOWERCASE_I
|
||||
<< UnicodeT::LOWERCASE_O
|
||||
<< UnicodeT::LOWERCASE_N
|
||||
<< UnicodeT::EQUALS_SIGN
|
||||
<< UnicodeT::QUOTATION_MARK
|
||||
<< UnicodeT::NUMBER_1
|
||||
<< UnicodeT::FULL_STOP
|
||||
<< UnicodeT::NUMBER_0
|
||||
<< UnicodeT::QUOTATION_MARK
|
||||
<< UnicodeT::QUESTION_MARK
|
||||
<< UnicodeT::GREATER_THAN_SIGN
|
||||
<< std::endl;
|
||||
doChildren(stream, node);
|
||||
break;
|
||||
case DOM::Node<stringT>::ELEMENT_NODE:
|
||||
stream << "<" << node.getNodeName() << ">";
|
||||
doChildren(stream, node);
|
||||
stream << "</" << node.getNodeName() << ">";
|
||||
{
|
||||
stream << UnicodeT::LESS_THAN_SIGN << node.getNodeName();
|
||||
DOM::NamedNodeMap<stringT> attrs = node.getAttributes();
|
||||
for(unsigned int a = 0; a < attrs.getLength(); ++a)
|
||||
{
|
||||
DOM::Node<stringT> attr = attrs.item(a);
|
||||
stream << UnicodeT::SPACE
|
||||
<< attr.getNodeName()
|
||||
<< UnicodeT::EQUALS_SIGN
|
||||
<< UnicodeT::QUOTATION_MARK;
|
||||
stringT value = attr.getNodeValue();
|
||||
std::for_each(value.begin(), value.end(), escaper<charT, traitsT>(stream));
|
||||
stream << UnicodeT::QUOTATION_MARK;
|
||||
}
|
||||
stream << UnicodeT::GREATER_THAN_SIGN;
|
||||
doChildren(stream, node);
|
||||
stream << UnicodeT::LESS_THAN_SIGN << UnicodeT::SLASH << node.getNodeName() << UnicodeT::GREATER_THAN_SIGN;
|
||||
}
|
||||
break;
|
||||
case DOM::Node<stringT>::TEXT_NODE:
|
||||
stream << node.getNodeValue();
|
||||
{
|
||||
stringT value = node.getNodeValue();
|
||||
std::for_each(value.begin(), value.end(), escaper<charT, traitsT>(stream));
|
||||
}
|
||||
break;
|
||||
case DOM::Node<stringT>::ENTITY_REFERENCE_NODE:
|
||||
stream << UnicodeT::AMPERSAND
|
||||
<< node.getNodeName()
|
||||
<< UnicodeT::SEMI_COLON;
|
||||
break;
|
||||
case DOM::Node<stringT>::CDATA_SECTION_NODE:
|
||||
stream << UnicodeT::LESS_THAN_SIGN
|
||||
<< UnicodeT::EXCLAMATION_MARK
|
||||
<< UnicodeT::LEFT_SQUARE_BRACKET
|
||||
<< UnicodeT::CAPITAL_C
|
||||
<< UnicodeT::CAPITAL_D
|
||||
<< UnicodeT::CAPITAL_A
|
||||
<< UnicodeT::CAPITAL_T
|
||||
<< UnicodeT::CAPITAL_A
|
||||
<< UnicodeT::LEFT_SQUARE_BRACKET
|
||||
<< node.getNodeValue()
|
||||
<< UnicodeT::RIGHT_SQUARE_BRACKET
|
||||
<< UnicodeT::RIGHT_SQUARE_BRACKET
|
||||
<< UnicodeT::GREATER_THAN_SIGN;
|
||||
break;
|
||||
case DOM::Node<stringT>::PROCESSING_INSTRUCTION_NODE:
|
||||
stream << UnicodeT::LESS_THAN_SIGN
|
||||
<< UnicodeT::QUESTION_MARK
|
||||
<< node.getNodeName()
|
||||
<< UnicodeT::SPACE
|
||||
<< node.getNodeValue()
|
||||
<< UnicodeT::QUESTION_MARK
|
||||
<< UnicodeT::GREATER_THAN_SIGN;
|
||||
break;
|
||||
case DOM::Node<stringT>::COMMENT_NODE:
|
||||
stream << UnicodeT::LESS_THAN_SIGN
|
||||
<< UnicodeT::EXCLAMATION_MARK
|
||||
<< UnicodeT::HYPHEN_MINUS
|
||||
<< UnicodeT::HYPHEN_MINUS
|
||||
<< node.getNodeValue()
|
||||
<< UnicodeT::HYPHEN_MINUS
|
||||
<< UnicodeT::HYPHEN_MINUS
|
||||
<< UnicodeT::GREATER_THAN_SIGN;
|
||||
break;
|
||||
} // switch
|
||||
|
||||
|
|
102
examples/SAX2DOM/DOMWriter.dsp
Normal file
102
examples/SAX2DOM/DOMWriter.dsp
Normal file
|
@ -0,0 +1,102 @@
|
|||
# Microsoft Developer Studio Project File - Name="DOMWriter" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||
|
||||
CFG=DOMWriter - 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 "DOMWriter.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 "DOMWriter.mak" CFG="DOMWriter - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "DOMWriter - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE "DOMWriter - 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)" == "DOMWriter - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "DOMWriter___Win32_Release"
|
||||
# PROP BASE Intermediate_Dir "DOMWriter___Win32_Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "..\..\bin"
|
||||
# PROP Intermediate_Dir "DOMWriter___Win32_Release"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD CPP /nologo /W3 /GR /GX /O2 /I "..\..\\" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /FD /c
|
||||
# SUBTRACT CPP /YX
|
||||
# ADD BASE RSC /l 0x809 /d "NDEBUG"
|
||||
# ADD RSC /l 0x809 /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 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
|
||||
|
||||
!ELSEIF "$(CFG)" == "DOMWriter - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "DOMWriter___Win32_Debug"
|
||||
# PROP BASE Intermediate_Dir "DOMWriter___Win32_Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "..\..\bin"
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
# 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 /W3 /Gm /GR /GX /ZI /Od /I "..\..\\" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FD /GZ /c
|
||||
# SUBTRACT CPP /YX
|
||||
# ADD BASE RSC /l 0x809 /d "_DEBUG"
|
||||
# ADD RSC /l 0x809 /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 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
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "DOMWriter - Win32 Release"
|
||||
# Name "DOMWriter - Win32 Debug"
|
||||
# Begin Group "Source Files"
|
||||
|
||||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\DOMWriter.cpp
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\lib\Utilities.lib
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\lib\SAX.lib
|
||||
# End Source File
|
||||
# End Target
|
||||
# End Project
|
|
@ -21,7 +21,7 @@
|
|||
Optimization="0"
|
||||
AdditionalIncludeDirectories="..\..\"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
|
||||
MinimalRebuild="TRUE"
|
||||
MinimalRebuild="FALSE"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="5"
|
||||
DisableLanguageExtensions="FALSE"
|
||||
|
|
|
@ -41,7 +41,7 @@ RSC=rc.exe
|
|||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD CPP /nologo /W3 /GX /O2 /I "..\..\\" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD BASE RSC /l 0x809 /d "NDEBUG"
|
||||
# ADD RSC /l 0x809 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
|
|
|
@ -72,7 +72,7 @@ CLEAN :
|
|||
"$(OUTDIR)" :
|
||||
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
|
||||
|
||||
CPP_PROJ=/nologo /ML /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /Fp"$(INTDIR)\SAX2DOM_test.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c
|
||||
CPP_PROJ=/nologo /ML /W3 /GX /O2 /I "..\..\\" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /Fp"$(INTDIR)\SAX2DOM_test.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c
|
||||
BSC32=bscmake.exe
|
||||
BSC32_FLAGS=/nologo /o"$(OUTDIR)\SAX2DOM_test.bsc"
|
||||
BSC32_SBRS= \
|
||||
|
|
Loading…
Reference in a new issue