From 6dd832dd0adb35f63148a0e7bd5bdcfb28516c3b Mon Sep 17 00:00:00 2001 From: Adrian Kummerländer Date: Fri, 18 Apr 2014 19:51:24 +0200 Subject: Implemented basic XML reading capabilities * command "read-xml-file" reads a XML file and allows it to be transformed by the calling XSLT * this will allow workflows like the following: ** a tranformation reads all the markdown files in a directory ** these markdown files are converted to a xml representation by a external function calling a appropriate C++ markdown parser ** the XML representation of each markdown file is converted to XHTML inside the XSL transformation ** ... and embedded into the output XHTML document ** => all inside a single XSL tranformation *** i.e. it is provided with only a empty dummy XML input file and fetches the actual input by itself * as all current code contained within this repository this is just a quick and dirty proof-of-concept and not in any way good code --- src/read_xml_file_command.h | 57 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/read_xml_file_command.h (limited to 'src/read_xml_file_command.h') diff --git a/src/read_xml_file_command.h b/src/read_xml_file_command.h new file mode 100644 index 0000000..96b6c5d --- /dev/null +++ b/src/read_xml_file_command.h @@ -0,0 +1,57 @@ +#include +#include +#include +#include +#include +#include +#include + +#include "utility.h" + +namespace xalan = xalanc_1_11; + +class FunctionReadXmlFile : public xalan::Function { + public: + virtual xalan::XObjectPtr execute( + xalan::XPathExecutionContext& executionContext, + xalan::XalanNode* context, + const xalan::Function::XObjectArgVectorType& args, + const xalan::Locator* locator + ) const { + if ( args.size() != 1 ) { + xalan::XPathExecutionContext::GetAndReleaseCachedString guard( + executionContext + ); + + generalError(executionContext, context, locator); + } + + if ( this->liaison == nullptr ) { + const_cast(this)->liaison = new xalan::XercesParserLiaison(); + } + + xalan::XSLTInputSource file(args[0]->str()); + + return executionContext.getXObjectFactory().createNodeSet( + liaison->parseXMLStream(file) + ); + } + + virtual FunctionReadXmlFile* clone(xalan::MemoryManager& manager) const { + return xalan::XalanCopyConstruct(manager, *this); + } + + protected: + xalan::XercesParserLiaison* liaison = nullptr; + + const xalan::XalanDOMString& getError(xalan::XalanDOMString& result) const { + result.assign("The read-file() function expects one argument."); + + return result; + } + + private: + FunctionReadXmlFile& operator=(const FunctionReadXmlFile&); + bool operator==(const FunctionReadXmlFile&) const; + +}; -- cgit v1.2.3