diff -r 8a8b6434e4bb -r 0766d298eb1c streamlet-examples/xpath.cpp --- a/streamlet-examples/xpath.cpp Mon Jan 27 00:43:39 2020 +0100 +++ b/streamlet-examples/xpath.cpp Tue Jan 28 14:26:39 2020 +0100 @@ -17,13 +17,49 @@ #include "streamlet-common.h" +#include +#include #include class XPathStreamlet : public Streamlet { +private: + xmlpp::Node::PrefixNsMap ns; + + void findXmlnsInEnvironment() { + std::regex xmlnsEnvPattern("xmlns_(.*)=(.*)"); + std::cmatch match; + for (char **env = environ; *env; env++) if (std::regex_match(*env, match, xmlnsEnvPattern)) ns[std::string(match[1])] = match[2]; + } + + void findXmlnsInOptions() { + for (Option o : getOptions(std::wregex(L"xmlns[:_](.*)"))) ns[convertor.to_bytes(o.nameMatch[1])] = convertor.to_bytes(o.value); + for (Option o : getOptions(std::wregex(L"xmlns"), std::wregex(L"([^:]+):(.*)"))) ns[convertor.to_bytes(o.valueMatch[1])] = convertor.to_bytes(o.valueMatch[2]); + } + + class XPathAttribute { + public: + + std::wstring name; + std::wstring xpath; + }; + + std::vector xpathAttributes; + +protected: std::vector getOutputAttributesMetadata() override { + findXmlnsInEnvironment(); + findXmlnsInOptions(); + std::vector oam; - oam.push_back({getAlias(0, L"xpath"), L"string"}); + + std::vector