# HG changeset patch # User František Kučera # Date 1580081396 -3600 # Node ID 6944a03fb88306993ea4d8a3f1c3831a75f44d98 # Parent 7ba9d703fadb1679623c6e1585b38cc9a642605d streamlet examples: xpath – parse and validate XML document diff -r 7ba9d703fadb -r 6944a03fb883 streamlet-examples/xpath.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/streamlet-examples/xpath.cpp Mon Jan 27 00:29:56 2020 +0100 @@ -0,0 +1,46 @@ +/** + * Relational pipes + * Copyright © 2020 František Kučera (Frantovo.cz, GlobalCode.info) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "streamlet-common.h" + +#include + +class XPathStreamlet : public Streamlet { + + std::vector getOutputAttributesMetadata() override { + std::vector oam; + oam.push_back({getAlias(0, L"xpath"), L"string"}); + return oam; + } + + std::vector getOutputAttributes() override { + std::vector oa; + + try { + xmlpp::DomParser parser; + parser.parse_file(convertor.to_bytes(currentFile)); + xmlpp::Element* root = parser.get_document()->get_root_node(); + oa.push_back({L"XML OK", false}); + } catch (...) { + oa.push_back({L"invalid XML", true}); + } + + return oa; + } +}; + +STREAMLET_RUN(XPathStreamlet)