streamlet-examples/xpath.cpp
branchv_0
changeset 74 a2aa84f310a5
parent 70 018e2609f5bb
child 75 ecbf6504915c
equal deleted inserted replaced
73:1a067a217454 74:a2aa84f310a5
    19 
    19 
    20 #include <unistd.h>
    20 #include <unistd.h>
    21 #include <regex>
    21 #include <regex>
    22 #include <libxml++-2.6/libxml++/libxml++.h>
    22 #include <libxml++-2.6/libxml++/libxml++.h>
    23 
    23 
       
    24 /**
       
    25  * This streamlet provides values from XML files.
       
    26  * It uses the XPath language to define, what portion of XML should be returned.
       
    27  * 
       
    28  * With no options it does not provide any attributes.
       
    29  * 
       
    30  * XPath expressions are passed as 'attribute' options.
       
    31  * e.g. --option 'attribute' 'name()' will return single attribute with the name of the root node.
       
    32  * 
       
    33  * Attributes can be renamed using aliases: --option 'attribute' 'name()' --as 'name'. Otherwise the full XPath expression is used as a name.
       
    34  * Number of aliases should match the number of attributes (otherwise only first attributes are renamed, because aliases are global, not relative to the --option).
       
    35  * 
       
    36  * Like relpipe-in-xmltable, this streamlet supports several modes:
       
    37  *  - string
       
    38  *  - boolean
       
    39  *  - raw-xml
       
    40  *  - line-number
       
    41  *  - xpath
       
    42  * 
       
    43  * TODO: more OOP, move to separate repository, proper CMake project, clean-up, stabilize API
       
    44  */
    24 class XPathStreamlet : public Streamlet {
    45 class XPathStreamlet : public Streamlet {
    25 private:
    46 private:
    26 	xmlpp::Node::PrefixNsMap ns;
    47 	xmlpp::Node::PrefixNsMap ns;
    27 
    48 
    28 	void findXmlnsInEnvironment() {
    49 	void findXmlnsInEnvironment() {