1 /* ------------------------------------------------
2 Copyright 2014 AT&T Intellectual Property
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
7 http://www.apache.org/licenses/LICENSE-2.0
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ------------------------------------------- */
16 #ifndef __XML_T_DEFINED_
17 #define __XML_T_DEFINED_
27 void xmlParser_setfileinput(FILE *f);
28 void xmlParser_setstringinput(char *s);
32 struct name_val_pair_t{
36 name_val_pair_t(const char *n, const char *v){
42 struct name_val_list_t{
43 std::vector<name_val_pair_t *> nvp_list;
48 name_val_list_t(name_val_pair_t *nvp){
49 nvp_list.push_back(nvp);
52 name_val_list_t *append(name_val_pair_t *nvp){
53 nvp_list.push_back(nvp);
60 std::vector<name_val_pair_t *> nvp_list;
62 tag_t(const char *n, name_val_list_t *nvl){
64 nvp_list = nvl->nvp_list;
73 std::string end_tag_name;
74 std::vector<name_val_pair_t *> attribs;
76 std::vector<xml_t *> subtrees;
80 xml_t(tag_t *s, xml_list_t *xl,const char *e);
82 xml_t(tag_t *s, char *e){
84 attribs = s->nvp_list;
88 xml_t(const char *n, name_val_list_t *nvl){
90 attribs=nvl->nvp_list;
93 std::string to_string(){
96 std::string to_string(std::string indent){
98 std::string whitespace;
101 ret += indent+"<"+name;
102 for(i=0;i<attribs.size();++i)
103 ret += " "+attribs[i]->name+"="+attribs[i]->val;
105 if(subtrees.size()>0){
107 for(i=0;i<subtrees.size();++i){
108 ret += subtrees[i]->to_string(indent+" ");
110 ret += indent + "</"+name+">\n";
117 void get_roots(std::string type, std::vector<xml_t *> &ret);
118 void get_roots(std::set<std::string> type, std::vector<xml_t *> &ret);
120 bool get_attrib_val(std::string name, std::string &val){
123 for(i=0;i<attribs.size();++i){
124 if(attribs[i]->name == name){
125 val = attribs[i]->val;
135 std::vector<xml_t *> xlist;
137 xml_list_t(xml_t *x){
141 xml_list_t *append(xml_t *x){