libyang  1.0.253
YANG data modeling language library
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
Xml.hpp
Go to the documentation of this file.
1 
15 #ifndef XML_H
16 #define XML_H
17 
18 #include <iostream>
19 #include <memory>
20 #include <exception>
21 #include <vector>
22 
23 #include "Internal.hpp"
24 
25 extern "C" {
26 #include "libyang.h"
27 #include "xml.h"
28 }
29 
30 namespace libyang {
31 
43 class Xml_Ns
44 {
45 public:
47  Xml_Ns(const struct lyxml_ns *ns, S_Deleter deleter);
48  ~Xml_Ns();
50  LYXML_ATTR_TYPE type() {return ns->type;};
52  S_Xml_Ns next();
53  //struct lyxml_elem *parent; /**< parent node of the attribute */
55  const char *prefix() {return ns->prefix;};
57  const char *value() {return ns->value;};
58 
59 private:
60  struct lyxml_ns *ns;
61  S_Deleter deleter;
62 };
63 
64 class Xml_Attr
65 {
66 public:
68  Xml_Attr(struct lyxml_attr *attr, S_Deleter deleter);
69  ~Xml_Attr();
71  LYXML_ATTR_TYPE type() {return attr->type;};
73  S_Xml_Attr next();
75  S_Xml_Ns ns();
77  const char *name() {return attr->name;};
79  const char *value() {return attr->value;};
80 
81 private:
82  struct lyxml_attr *attr;
83  S_Deleter deleter;
84 };
85 
86 class Xml_Elem
87 {
88 public:
90  Xml_Elem(S_Context context, struct lyxml_elem *elem, S_Deleter deleter);
91  ~Xml_Elem();
93  char flags() {return elem->flags;};
95  S_Xml_Elem parent();
97  S_Xml_Attr attr();
99  S_Xml_Elem child();
101  S_Xml_Elem next();
103  S_Xml_Elem prev();
105  const char *name() {return elem->name;};
107  S_Xml_Ns ns();
109  const char *content() {return elem->content;};
110 
111  /* methods */
113  const char *get_attr(const char *name, const char *ns = nullptr);
115  S_Xml_Ns get_ns(const char *prefix);
117  std::string print_mem(int options);
118  //int lyxml_print_fd(int fd, const struct lyxml_elem *elem, int options);
119  //int lyxml_print_file(FILE * stream, const struct lyxml_elem *elem, int options);
120 
121  /* emulate TREE macro's */
123  std::vector<S_Xml_Elem> tree_for();
125  std::vector<S_Xml_Elem> tree_dfs();
126 
127  /* TODO
128  struct lyxml_elem *lyxml_dup(struct ly_ctx *ctx, struct lyxml_elem *root);
129  struct lyxml_elem *lyxml_parse_mem(struct ly_ctx *ctx, const char *data, int options);
130  struct lyxml_elem *lyxml_parse_path(struct ly_ctx *ctx, const char *filename, int options);
131  */
132 
133  friend Data_Node;
134  friend Context;
135 
136 private:
137  S_Context context;
138  struct lyxml_elem *elem;
139  S_Deleter deleter;
140 };
141 
144 }
145 
146 #endif
std::vector< S_Xml_Elem > tree_for()
Definition: Xml.cpp:77
class for wrapping lyxml_ns.
Definition: Xml.hpp:43
char flags
Definition: xml.h:93
LYXML_ATTR_TYPE type()
Definition: Xml.hpp:50
S_Xml_Attr next()
Definition: Xml.cpp:42
LYXML_ATTR_TYPE type()
Definition: Xml.hpp:71
const char * content()
Definition: Xml.hpp:109
Element&#39;s attribute definition.
Definition: xml.h:75
S_Xml_Ns next()
Definition: Xml.cpp:35
S_Xml_Attr attr()
Definition: Xml.cpp:52
const char * content
Definition: xml.h:105
S_Xml_Ns ns()
Definition: Xml.cpp:43
friend Context
Definition: Xml.hpp:134
char flags()
Definition: Xml.hpp:93
const char * prefix
Definition: xml.h:62
const char * prefix()
Definition: Xml.hpp:55
Xml_Ns(const struct lyxml_ns *ns, S_Deleter deleter)
Definition: Xml.cpp:30
S_Xml_Ns ns()
Definition: Xml.cpp:56
const char * name
Definition: xml.h:79
S_Xml_Elem parent()
Definition: Xml.cpp:51
Xml_Attr(struct lyxml_attr *attr, S_Deleter deleter)
Definition: Xml.cpp:37
S_Xml_Ns get_ns(const char *prefix)
Definition: Xml.cpp:60
S_Xml_Elem next()
Definition: Xml.cpp:54
Public API of libyang XML parser.
std::string print_mem(int options)
Definition: Xml.cpp:64
const char * name()
Definition: Xml.hpp:105
Structure describing an element in an XML tree.
Definition: xml.h:92
const char * value
Definition: xml.h:63
S_Xml_Elem child()
Definition: Xml.cpp:53
const char * value()
Definition: Xml.hpp:79
friend Data_Node
Definition: Xml.hpp:133
S_Xml_Elem prev()
Definition: Xml.cpp:55
const char * get_attr(const char *name, const char *ns=nullptr)
Definition: Xml.cpp:57
const char * value()
Definition: Xml.hpp:57
Xml_Elem(S_Context context, struct lyxml_elem *elem, S_Deleter deleter)
Definition: Xml.cpp:45
Namespace definition.
Definition: xml.h:58
std::vector< S_Xml_Elem > tree_dfs()
Definition: Xml.cpp:87
const char * name()
Definition: Xml.hpp:77
LYXML_ATTR_TYPE type
Definition: xml.h:59
enum lyxml_attr_type LYXML_ATTR_TYPE
enumeration of attribute types