streamlet examples: xpath: support XInclude (like in relpipe-tr-xmltable) v_0 v0.15
authorFrantišek Kučera <franta-hg@frantovo.cz>
Thu, 30 Jan 2020 23:27:49 +0100
branchv_0
changeset 78 5a63bf594f53
parent 77 a680bcd946cd
child 79 288a7f075777
streamlet examples: xpath: support XInclude (like in relpipe-tr-xmltable)
streamlet-examples/xpath.cpp
--- a/streamlet-examples/xpath.cpp	Thu Jan 30 18:04:10 2020 +0100
+++ b/streamlet-examples/xpath.cpp	Thu Jan 30 23:27:49 2020 +0100
@@ -48,6 +48,8 @@
  *  - raw-xml-attribute-wrapper-uri
  *  - raw-xml-attribute-wrapper-prefix
  * 
+ * XInclude processing may be turned on using: --option xinclude true
+ * 
  * TODO: more OOP, move to separate repository, proper CMake project, clean-up, stabilize API
  */
 class XPathStreamlet : public Streamlet {
@@ -65,6 +67,12 @@
 		for (Option o : getOptions(std::wregex(L"xmlns"), std::wregex(L"([^:]+):(.*)"))) ns[toBytes(o.valueMatch[1])] = toBytes(o.valueMatch[2]);
 	}
 
+	bool xinclude = false;
+
+	void findXIncludeOptions() {
+		for (Option o : getOptions(L"xinclude")) xinclude = o.value == L"true";
+	}
+
 	std::wstring rawXmlNodeListWrapperName;
 	std::wstring rawXmlNodeListWrapperUri;
 	std::wstring rawXmlNodeListWrapperPrefix;
@@ -163,6 +171,7 @@
 		findXmlnsInEnvironment();
 		findXmlnsInOptions();
 		findRawXmlOptions();
+		findXIncludeOptions();
 
 		std::vector<AttributeMetadata> oam;
 
@@ -184,6 +193,7 @@
 		try {
 			xmlpp::DomParser parser;
 			parser.parse_file(toBytes(getCurrentFile()));
+			if (xinclude) parser.get_document()->process_xinclude(true);
 			xmlpp::Element* root = parser.get_document()->get_root_node();
 
 			for (XPathAttribute xpathAttribute : xpathAttributes) {