mirror of
https://github.com/jezhiggins/arabica
synced 2025-01-30 08:38:15 +01:00
Added xmlbase - a simple example that picks up xml:base attributes
and reports xlink:hrefs in a document
This commit is contained in:
parent
d0994d8b46
commit
def15dfbbe
3 changed files with 230 additions and 0 deletions
|
@ -23,6 +23,10 @@ WRITER_SRCS = writer.cpp
|
|||
WRITER_HDRS = $(patsubst %.c,%.h,$(patsubst %.cpp,%.h,$(WRITER_SRCS)))
|
||||
WRITER_OBJS = $(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(WRITER_SRCS)))
|
||||
|
||||
XMLBASE_SRC = xmlbase.cpp
|
||||
XMLBASE_HDRS = $(patsubst %.c,%.h,$(patsubst %.cpp,%.h,$(XMLBASE_SRCS)))
|
||||
XMLBASE_OBJS = $(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(XMLBASE_SRCS)))
|
||||
|
||||
######################################
|
||||
# High level rules
|
||||
all : pyx simple_handler writer
|
||||
|
@ -39,6 +43,10 @@ writer : $(WRITER_OBJS)
|
|||
$(LD) $(LDFLAGS) -o $@ $(WRITER_OBJS) $(LIBS_DIRS) $(STATIC_LIBS) $(DYNAMIC_LIBS)
|
||||
$(COPY) writer$(EXESUFFIX) ../../bin
|
||||
|
||||
xmlbase : $(XMLBASE_OBJS)
|
||||
$(LD) $(LDFLAGS) -o $@ $(XMLBASE_OBJS) $(LIBS_DIRS) $(STATIC_LIBS) $(DYNAMIC_LIBS)
|
||||
$(COPY) xmlbase$(EXESUFFIX) ../../bin
|
||||
|
||||
######################
|
||||
# Compile rules
|
||||
####
|
||||
|
@ -53,6 +61,8 @@ clean :
|
|||
../../bin/pyx$(EXESUFFIX) \
|
||||
writer$(EXESUFFIX) \
|
||||
../../bin/writer$(EXESUFFIX) \
|
||||
xmlbase$(EXESUFFIX) \
|
||||
../../bin/xmlbase$(EXESUFFIX) \
|
||||
simple_handler$(EXESUFFIX) \
|
||||
../../bin/simple_handler$(EXESUFFIX)
|
||||
|
||||
|
|
135
examples/SAX/example_XMLBase.vcproj
Normal file
135
examples/SAX/example_XMLBase.vcproj
Normal file
|
@ -0,0 +1,135 @@
|
|||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="7.10"
|
||||
Name="example_XMLBase"
|
||||
ProjectGUID="{1E3CEC10-26EB-40C0-AC9A-72020BD5A40A}"
|
||||
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;_CONSOLE"
|
||||
MinimalRebuild="TRUE"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="5"
|
||||
TreatWChar_tAsBuiltInType="TRUE"
|
||||
RuntimeTypeInfo="TRUE"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="TRUE"
|
||||
DebugInformationFormat="4"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
OutputFile="$(OutDir)/XMLBase.exe"
|
||||
LinkIncremental="2"
|
||||
GenerateDebugInformation="TRUE"
|
||||
ProgramDatabaseFile="$(OutDir)/example_XMLBase.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="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory=".\..\..\bin"
|
||||
IntermediateDirectory="Release"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories="..\..\"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
|
||||
RuntimeLibrary="4"
|
||||
TreatWChar_tAsBuiltInType="TRUE"
|
||||
RuntimeTypeInfo="TRUE"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="TRUE"
|
||||
DebugInformationFormat="3"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
OutputFile="$(OutDir)/XMLBase.exe"
|
||||
LinkIncremental="1"
|
||||
GenerateDebugInformation="TRUE"
|
||||
SubSystem="1"
|
||||
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="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
||||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
|
||||
<File
|
||||
RelativePath=".\xmlbase.cpp">
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="libs"
|
||||
Filter="">
|
||||
<File
|
||||
RelativePath="..\..\lib\Arabica.lib">
|
||||
</File>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
85
examples/SAX/xmlbase.cpp
Normal file
85
examples/SAX/xmlbase.cpp
Normal file
|
@ -0,0 +1,85 @@
|
|||
//////////////////////////////////////////////////
|
||||
//
|
||||
// An example application which tracks xml:base declarations,
|
||||
// and prints out resolved xlink:hrefs, like those in the
|
||||
// XML Base spec example
|
||||
// http://www.w3.org/TR/xmlbase/
|
||||
// $Id$
|
||||
//
|
||||
//////////////////////////////////////////////////
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable : 4786)
|
||||
#endif
|
||||
|
||||
#include <SAX/helpers/DefaultHandler.h>
|
||||
#include <SAX/InputSource.h>
|
||||
#include <SAX/XMLReader.h>
|
||||
#include <SAX/helpers/XMLBaseSupport.h>
|
||||
#include <iostream>
|
||||
|
||||
class hrefPrinter : public SAX::DefaultHandler
|
||||
{
|
||||
public:
|
||||
virtual void startElement(const std::string& namespaceURI, const std::string& localName,
|
||||
const std::string& qName, const SAX::Attributes& atts);
|
||||
virtual void endElement(const std::string& namespaceURI, const std::string& localName,
|
||||
const std::string& qName);
|
||||
|
||||
virtual void warning(const SAX::SAXParseException& e) { fatalError(e); }
|
||||
virtual void error(const SAX::SAXParseException& e) { fatalError(e); }
|
||||
|
||||
private:
|
||||
SAX::XMLBaseSupport xmlbaseTracker_;
|
||||
}; // class SimpleHandler
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
if(argc == 1)
|
||||
{
|
||||
std::cout << "Usage : " << argv[0] << " xmlfile ... " << std::endl;
|
||||
return 0;
|
||||
} // if(argc == 0)
|
||||
|
||||
hrefPrinter handler;
|
||||
|
||||
for(int i = 1; i < argc; ++i)
|
||||
{
|
||||
try
|
||||
{
|
||||
SAX::XMLReader<std::string> myParser;
|
||||
myParser.setContentHandler(handler);
|
||||
myParser.setErrorHandler(handler);
|
||||
|
||||
SAX::InputSource is(argv[i]);
|
||||
myParser.parse(is);
|
||||
} // try
|
||||
catch(std::runtime_error& e)
|
||||
{
|
||||
std::cerr << "Parse problem " << e.what() << std::endl;
|
||||
} // catch
|
||||
} // for ...
|
||||
|
||||
return 0;
|
||||
} // main
|
||||
|
||||
|
||||
void hrefPrinter::startElement(const std::string&, const std::string& localName,
|
||||
const std::string&, const SAX::Attributes& atts)
|
||||
{
|
||||
xmlbaseTracker_.startElement(atts);
|
||||
|
||||
std::string href = atts.getValue("http://www.w3.org/1999/xlink", "href");
|
||||
if(href.empty())
|
||||
return;
|
||||
|
||||
std::cout << "href '" << href << "' resolves to the URI '" << xmlbaseTracker_.makeAbsolute(href) << "'" << std::endl;
|
||||
} // startElement
|
||||
|
||||
void hrefPrinter::endElement(const std::string&, const std::string& localName,
|
||||
const std::string&)
|
||||
{
|
||||
xmlbaseTracker_.endElement();
|
||||
} // endElement
|
||||
|
||||
// end of file
|
Loading…
Add table
Reference in a new issue