~ubuntu-branches/ubuntu/natty/libxml++2.6/natty

« back to all changes in this revision

Viewing changes to libxml++/nodes/node.cc

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-09-18 11:32:24 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20070918113224-7x031mzf1shoozxx
Tags: 2.20.0-0ubuntu1
* New upstream release:
  - Element: Added get_attribute_value(), to get a simple text value for an
    attribute.
  - Added an experimental --enable-api-exceptions configure option, to allow
    libxml++ to build without exceptions.
* debian/libxml++2.6-doc.docs: 2.18 -> 2.20.

Show diffs side-by-side

added added

removed removed

Lines of Context:
101
101
   xmlNs* ns = 0;
102
102
 
103
103
   if(impl_->type != XML_ELEMENT_NODE)
 
104
   {
 
105
      #ifdef LIBXMLCPP_EXCEPTIONS_ENABLED
104
106
      throw internal_error("You can only add child nodes to element nodes");
 
107
      #else
 
108
      return 0;
 
109
      #endif //LIBXMLCPP_EXCEPTIONS_ENABLED
 
110
   }
105
111
 
106
112
   //Ignore the namespace if none was specified:
107
113
   if(!ns_prefix.empty())
109
115
     //Use the existing namespace if one exists:
110
116
     ns = xmlSearchNs(impl_->doc, impl_, (const xmlChar*)ns_prefix.c_str());
111
117
     if (!ns)
 
118
     {
 
119
       #ifdef LIBXMLCPP_EXCEPTIONS_ENABLED
112
120
       throw exception("The namespace prefix (" + ns_prefix + ") has not been declared.");
 
121
       #else
 
122
       return 0;
 
123
       #endif //LIBXMLCPP_EXCEPTIONS_ENABLED
 
124
     }
113
125
   }
114
126
 
115
127
   node = xmlAddChild(impl_, xmlNewNode(ns, (const xmlChar*)name.c_str()));
133
145
  //Create the node, by copying:
134
146
  xmlNode* imported_node = xmlDocCopyNode(const_cast<xmlNode*>(node->cobj()), impl_->doc, recursive);
135
147
  if (!imported_node)
 
148
  {
 
149
    #ifdef LIBXMLCPP_EXCEPTIONS_ENABLED
136
150
    throw exception("Unable to import node");
 
151
    #else
 
152
    return 0;
 
153
    #endif //LIBXMLCPP_EXCEPTIONS_ENABLED
 
154
  }
137
155
 
138
156
  //Add the node:
139
157
  xmlNode* added_node = xmlAddChild(this->cobj(),imported_node);
140
158
  if (!added_node)
141
159
  {
142
160
    xmlFreeNode(imported_node);
 
161
 
 
162
    #ifdef LIBXMLCPP_EXCEPTIONS_ENABLED
143
163
    throw exception("Unable to add imported node to current node");
 
164
    #else
 
165
    return 0;
 
166
    #endif //LIBXMLCPP_EXCEPTIONS_ENABLED
144
167
  }
145
168
 
146
169
  return static_cast<Node*>(imported_node->_private);
187
210
  if(!result)
188
211
  {
189
212
    xmlXPathFreeContext(ctxt);
 
213
 
 
214
    #ifdef LIBXMLCPP_EXCEPTIONS_ENABLED
190
215
    throw exception("Invalid XPath: " + xpath);
 
216
    #else
 
217
    return NodeSet();
 
218
    #endif //LIBXMLCPP_EXCEPTIONS_ENABLED
191
219
  }
192
220
 
193
221
  if(result->type != XPATH_NODESET)
194
222
  {
195
223
    xmlXPathFreeObject(result);
196
224
    xmlXPathFreeContext(ctxt);
 
225
 
 
226
    #ifdef LIBXMLCPP_EXCEPTIONS_ENABLE
197
227
    throw internal_error("Only nodeset result types are supported.");
 
228
    #else
 
229
    return NodeSet();
 
230
    #endif //LIBXMLCPP_EXCEPTIONS_ENABLED
198
231
  }
199
232
 
200
233
  xmlNodeSet* nodeset = result->nodesetval;
288
321
  }
289
322
  else
290
323
  {
 
324
    #ifdef LIBXMLCPP_EXCEPTIONS_ENABLE
291
325
    throw exception("The namespace (" + ns_prefix + ") has not been declared.");
 
326
    #endif //LIBXMLCPP_EXCEPTIONS_ENABLE
292
327
  }
293
328
}
294
329