# HG changeset patch # User František Kučera # Date 1609319001 -3600 # Node ID 682c378bc4a20adc8578f874657aa1c9298dacb2 # Parent c58c7f2d4785be38e39c93c4b8e3a16222868cca add XML namespace support, xmlns diff -r c58c7f2d4785 -r 682c378bc4a2 src/XPathHandler.h --- a/src/XPathHandler.h Wed Dec 30 09:58:39 2020 +0100 +++ b/src/XPathHandler.h Wed Dec 30 10:03:21 2020 +0100 @@ -52,6 +52,7 @@ size_t currentRecordNumber = 1; + xmlpp::Node::PrefixNsMap xmlns; xmlpp::DomParser dom; xmlpp::Element* recordElement = nullptr; relpipe::in::xmltable::XMLNameCodec xmlNameCodec; // TODO: move to a common library @@ -93,7 +94,7 @@ void writeOutputAttributes() { for (auto oa : currentRelationConfiguration->outputAttributes) { - auto value = recordElement->eval_to_string(s2x(oa.xpath)); + auto value = recordElement->eval_to_string(s2x(oa.xpath), xmlns); relationalWriter->writeAttribute(x2s(value)); } } @@ -101,6 +102,11 @@ public: XPathHandler(shared_ptr relationalWriter, Configuration configuration) : relationalWriter(relationalWriter), configuration(configuration) { + for (int i = 0; i < configuration.namespaceMappings.size(); i++) { + std::string prefix = convertor.to_bytes(configuration.namespaceMappings[i]); + std::string uri = convertor.to_bytes(configuration.namespaceMappings[++i]); + xmlns[prefix] = uri; + } } virtual ~XPathHandler() { @@ -152,7 +158,7 @@ currentAttributeIndex++; if (currentAttributeIndex == currentReaderMetadata.size()) { - if (currentRelationConfiguration->where.empty() || recordElement->eval_to_boolean(s2x(currentRelationConfiguration->where))) { + if (currentRelationConfiguration->where.empty() || recordElement->eval_to_boolean(s2x(currentRelationConfiguration->where), xmlns)) { if (isPrependingInputAttributes()) writeInputAttributes(); writeOutputAttributes(); if (isAppendingInputAttributes()) writeInputAttributes();