src/XMLTableCommand.h
author František Kučera <franta-hg@frantovo.cz>
Sat, 04 Dec 2021 21:14:50 +0100
branchv_0
changeset 19 7dd30da105d8
parent 17 0c828326aa7b
permissions -rw-r--r--
Added tag v0.18 for changeset a7210cd32c87
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
/**
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
 * Relational pipes
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     3
 * Copyright © 2019 František Kučera (Frantovo.cz, GlobalCode.info)
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     4
 *
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     5
 * This program is free software: you can redistribute it and/or modify
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
4
a0689654b3c2 fix license version: GNU GPLv3
František Kučera <franta-hg@frantovo.cz>
parents: 2
diff changeset
     7
 * the Free Software Foundation, version 3 of the License.
0
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
 *
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
 * GNU General Public License for more details.
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
 *
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    15
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
 */
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
#pragma once
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
#include <cstdlib>
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
#include <iostream>
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
#include <string>
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
#include <sstream>
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
#include <vector>
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
#include <algorithm>
8
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    25
#include <exception>
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    26
#include <regex>
0
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
#include <libxml++-2.6/libxml++/libxml++.h>
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    30
#include <relpipe/writer/typedefs.h>
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    31
2
0d3eb5129582 convert arbitrary XML to one or more relations
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    32
#include "Configuration.h"
14
5be268bc4c69 separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
    33
#include "XMLDocumentConstructor.h"
0
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    34
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    35
namespace relpipe {
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    36
namespace in {
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    37
namespace xmltable {
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    38
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    39
using namespace relpipe::writer;
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    40
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    41
class XMLCommand {
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    42
private:
2
0d3eb5129582 convert arbitrary XML to one or more relations
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    43
	std::wstring_convert<codecvt_utf8<wchar_t>> convertor; // TODO: support also other encodings.
0
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    44
8
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    45
	string_t formatRawXML(string_t rawXML) {
17
0c828326aa7b fix raw-xml formatting (remove XML declaration)
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    46
		std::wregex pattern(L"^(<\\?xml version=\"1.0\" encoding=\"UTF-8\"\\?>\\s*)+|\n$");
0c828326aa7b fix raw-xml formatting (remove XML declaration)
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    47
		// libxml sometimes returns doubled XML declaration (probably a bug), see:
0c828326aa7b fix raw-xml formatting (remove XML declaration)
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    48
		// --relation ini --records '/' --attribute 'xml' string '.' --mode raw-xml # (but not for --records '//*')
0c828326aa7b fix raw-xml formatting (remove XML declaration)
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    49
		// so we remove all of them and also trailing line ends (if any).
8
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    50
		return std::regex_replace(rawXML, pattern, L"");
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    51
	}
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    52
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    53
	void importNode(xmlpp::Node* parent, xmlpp::Node* child, AttributeRecipe attributeRecipe) {
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    54
		if (dynamic_cast<xmlpp::AttributeNode*> (child)) parent->add_child_with_new_ns(
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    55
				convertor.to_bytes(attributeRecipe.rawXmlAttributeWrapper.name),
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    56
				convertor.to_bytes(attributeRecipe.rawXmlAttributeWrapper.uri),
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    57
				convertor.to_bytes(attributeRecipe.rawXmlAttributeWrapper.prefix))->import_node(child);
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    58
		else parent->import_node(child, true);
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    59
	}
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    60
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    61
	void importNode(xmlpp::Document* document, xmlpp::Node* child, AttributeRecipe attributeRecipe) {
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    62
		if (dynamic_cast<xmlpp::AttributeNode*> (child)) document->create_root_node(
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    63
				convertor.to_bytes(attributeRecipe.rawXmlAttributeWrapper.name),
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    64
				convertor.to_bytes(attributeRecipe.rawXmlAttributeWrapper.uri),
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    65
				convertor.to_bytes(attributeRecipe.rawXmlAttributeWrapper.prefix))->import_node(child);
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    66
		else document->create_root_node_by_import(child, true);
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    67
	}
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    68
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    69
	string_t toRawXML(xmlpp::Node* parent, AttributeRecipe attributeRecipe, xmlpp::Node::PrefixNsMap ns) {
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    70
		xmlpp::Document d;
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    71
		xmlpp::NodeSet nodes = parent->find(convertor.to_bytes(attributeRecipe.xpath), ns);
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    72
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    73
		if (attributeRecipe.rawXmlNodeListWrapper.name.size()) {
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    74
			d.create_root_node(
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    75
					convertor.to_bytes(attributeRecipe.rawXmlNodeListWrapper.name),
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    76
					convertor.to_bytes(attributeRecipe.rawXmlNodeListWrapper.uri),
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    77
					convertor.to_bytes(attributeRecipe.rawXmlNodeListWrapper.prefix));
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    78
			for (xmlpp::Node* node : nodes) importNode(d.get_root_node(), node, attributeRecipe);
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    79
		} else {
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    80
			if (nodes.size() == 1) importNode(&d, nodes[0], attributeRecipe);
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    81
			else if (nodes.size() > 1) throw std::invalid_argument("Multiple nodes found where only one was expected. Use nodelist wrapper."); // TODO: better relpipe exception
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    82
			else return L""; // TODO: null
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    83
		}
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    84
		return formatRawXML(convertor.from_bytes(d.write_to_string()));
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    85
	}
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    86
0
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    87
public:
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    88
2
0d3eb5129582 convert arbitrary XML to one or more relations
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    89
	void process(std::istream& input, std::ostream& output, Configuration& configuration) {
0d3eb5129582 convert arbitrary XML to one or more relations
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    90
		std::shared_ptr<RelationalWriter> writer(Factory::create(output));
0
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    91
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    92
		xmlpp::DomParser parser;
14
5be268bc4c69 separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
    93
		XMLDocumentConstructor documentConstructor(&input, &parser);
15
917b8fbd29b9 add --parser-option
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
    94
		for (ParserOptionRecipe o : configuration.parserOptions) documentConstructor.setOption(convertor.to_bytes(o.uri), convertor.to_bytes(o.value));
14
5be268bc4c69 separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
    95
		documentConstructor.process();
7
ff69af3c67a3 XInclude support – option: --xinclude true
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    96
		if (configuration.xinclude) parser.get_document()->process_xinclude(true);
2
0d3eb5129582 convert arbitrary XML to one or more relations
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    97
		xmlpp::Element* root = parser.get_document()->get_root_node();
0
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    98
2
0d3eb5129582 convert arbitrary XML to one or more relations
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    99
		xmlpp::Node::PrefixNsMap ns;
0d3eb5129582 convert arbitrary XML to one or more relations
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
   100
		for (int i = 0; i < configuration.namespaceMappings.size(); i++) {
0d3eb5129582 convert arbitrary XML to one or more relations
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
   101
			std::string prefix = convertor.to_bytes(configuration.namespaceMappings[i]);
0d3eb5129582 convert arbitrary XML to one or more relations
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
   102
			std::string uri = convertor.to_bytes(configuration.namespaceMappings[++i]);
0d3eb5129582 convert arbitrary XML to one or more relations
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
   103
			ns[prefix] = uri;
0
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   104
		}
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   105
2
0d3eb5129582 convert arbitrary XML to one or more relations
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
   106
		for (const RelationConfiguration& r : configuration.relationConfigurations) {
0d3eb5129582 convert arbitrary XML to one or more relations
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
   107
			std::vector<relpipe::writer::AttributeMetadata> attributesMetadata;
0d3eb5129582 convert arbitrary XML to one or more relations
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
   108
			for (AttributeRecipe a : r.attributes) attributesMetadata.push_back(AttributeMetadata{a.name, a.type});
0d3eb5129582 convert arbitrary XML to one or more relations
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
   109
			relpipe::writer::string_t name = r.nameIsXPath ? convertor.from_bytes(root->eval_to_string(convertor.to_bytes(r.relation), ns)) : r.relation;
0d3eb5129582 convert arbitrary XML to one or more relations
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
   110
			writer->startRelation(name, attributesMetadata, true);
0d3eb5129582 convert arbitrary XML to one or more relations
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
   111
			for (xmlpp::Node* n : root->find(convertor.to_bytes(r.xpath), ns)) {
0d3eb5129582 convert arbitrary XML to one or more relations
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
   112
				for (AttributeRecipe a : r.attributes) {
0d3eb5129582 convert arbitrary XML to one or more relations
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
   113
					// TODO: convert to bytes only once
8
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
   114
					std::string attributeXpath = convertor.to_bytes(a.xpath);
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
   115
					if (a.mode == Mode::STRING) {
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
   116
						writer->writeAttribute(convertor.from_bytes(n->eval_to_string(attributeXpath, ns)));
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
   117
					} else if (a.mode == Mode::BOOLEAN) {
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
   118
						writer->writeAttribute(n->eval_to_boolean(attributeXpath, ns) ? L"true" : L"false");
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
   119
					} else if (a.mode == Mode::LINE_NUMBER) {
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
   120
						xmlpp::NodeSet attributeNodes = n->find(attributeXpath, ns);
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
   121
						string_t line = attributeNodes.size() ? std::to_wstring(attributeNodes[0]->get_line()) : L""; // TODO: null
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
   122
						writer->writeAttribute(line);
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
   123
					} else if (a.mode == Mode::XPATH) {
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
   124
						xmlpp::NodeSet attributeNodes = n->find(attributeXpath, ns);
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
   125
						string_t line = attributeNodes.size() ? convertor.from_bytes(attributeNodes[0]->get_path()) : L""; // TODO: null
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
   126
						writer->writeAttribute(line);
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
   127
					} else if (a.mode == Mode::RAW_XML) {
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
   128
						writer->writeAttribute(toRawXML(n, a, ns));
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
   129
					} else {
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
   130
						throw logic_error("Unsupported mode."); // should never happer, TODO: better relpipe exception
8730e2d0db0e suport multiple modes of reading from XML: string, boolean, raw-xml, line-number, xpath
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
   131
					}
2
0d3eb5129582 convert arbitrary XML to one or more relations
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
   132
				}
0d3eb5129582 convert arbitrary XML to one or more relations
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
   133
			}
0d3eb5129582 convert arbitrary XML to one or more relations
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
   134
		}
0
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   135
	}
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   136
};
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   137
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   138
}
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   139
}
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   140
}