--- a/streamlet-examples/xpath.cpp Tue Jan 28 23:35:25 2020 +0100
+++ b/streamlet-examples/xpath.cpp Wed Jan 29 00:58:37 2020 +0100
@@ -62,13 +62,6 @@
else return STRING;
}
- // TODO: should not be done in particular streamlets but in the worker
- std::wstring toNullValue(std::wstring type) {
- if (type == BOOLEAN) return L"false";
- else if (type == INTEGER) return L"0";
- else return L"";
- }
-
class XPathAttribute {
public:
@@ -118,30 +111,22 @@
result = root->eval_to_boolean(xpath, ns) ? L"true" : L"false";
} else if (xpathAttribute.mode == Mode::LINE_NUMBER) {
xmlpp::NodeSet attributeNodes = root->find(xpath, ns);
- if (attributeNodes.size()) {
- result = std::to_wstring(attributeNodes[0]->get_line());
- } else {
- result = L"0";
- isNull = true;
- }
+ if (attributeNodes.size()) result = std::to_wstring(attributeNodes[0]->get_line());
+ else isNull = true;
} else if (xpathAttribute.mode == Mode::XPATH) {
xmlpp::NodeSet attributeNodes = root->find(xpath, ns);
- if (attributeNodes.size()) {
- result = convertor.from_bytes(attributeNodes[0]->get_path());
- } else {
- result = L"";
- isNull = true;
- }
+ if (attributeNodes.size()) result = convertor.from_bytes(attributeNodes[0]->get_path());
+ else isNull = true;
} else if (xpathAttribute.mode == Mode::RAW_XML) {
throw std::logic_error("Raw XML mode is not yet implemented."); // TODO: implement also RAW_XML
} else {
throw std::logic_error("Unsupported mode."); // should never happer
}
- oa.push_back({result, false});
+ oa.push_back({result, isNull});
}
} catch (xmlpp::parse_error& e) {
- for (XPathAttribute xpathAttribute : xpathAttributes) oa.push_back({toNullValue(toType(xpathAttribute.mode)), true});
+ for (XPathAttribute xpathAttribute : xpathAttributes) oa.push_back({L"", true});
// invalid XML → xmlpp::parse_error → just skip this file
// invalid XPath → xmlpp::exception → failure
}