src/XMLTableCommand.h
author František Kučera <franta-hg@frantovo.cz>
Sun, 25 Oct 2020 21:48:11 +0100
branchv_0
changeset 14 5be268bc4c69
parent 8 8730e2d0db0e
child 15 917b8fbd29b9
permissions -rw-r--r--
separate the „std::istream to DOM“ phase
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) {
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
    46
		std::wregex pattern(L"^<\\?xml version=\"1.0\" encoding=\"UTF-8\"\\?>\n|\n$");
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
    47
		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
    48
	}
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
    49
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
	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
    51
		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
    52
				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
    53
				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
    54
				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
    55
		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
    56
	}
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
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
	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
    59
		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
    60
				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
    61
				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
    62
				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
    63
		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
    64
	}
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
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
	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
    67
		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
    68
		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
    69
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
		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
    71
			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
    72
					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
    73
					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
    74
					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
    75
			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
    76
		} 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
    77
			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
    78
			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
    79
			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
    80
		}
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
		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
    82
	}
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
0
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    84
public:
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    85
2
0d3eb5129582 convert arbitrary XML to one or more relations
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    86
	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
    87
		std::shared_ptr<RelationalWriter> writer(Factory::create(output));
0
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    88
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    89
		xmlpp::DomParser parser;
14
5be268bc4c69 separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
    90
		XMLDocumentConstructor documentConstructor(&input, &parser);
5be268bc4c69 separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
    91
		documentConstructor.process();
7
ff69af3c67a3 XInclude support – option: --xinclude true
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    92
		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
    93
		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
    94
2
0d3eb5129582 convert arbitrary XML to one or more relations
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    95
		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
    96
		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
    97
			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
    98
			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
    99
			ns[prefix] = uri;
0
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   100
		}
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   101
2
0d3eb5129582 convert arbitrary XML to one or more relations
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
   102
		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
   103
			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
   104
			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
   105
			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
   106
			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
   107
			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
   108
				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
   109
					// 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
   110
					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
   111
					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
   112
						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
   113
					} 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
   114
						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
   115
					} 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
   116
						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
   117
						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
   118
						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
   119
					} 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
   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() ? 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
   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::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
   124
						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
   125
					} 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
   126
						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
   127
					}
2
0d3eb5129582 convert arbitrary XML to one or more relations
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
   128
				}
0d3eb5129582 convert arbitrary XML to one or more relations
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
   129
			}
0d3eb5129582 convert arbitrary XML to one or more relations
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
   130
		}
0
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   131
	}
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   132
};
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   133
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   134
}
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
}