File tree 7 files changed +43
-11
lines changed
7 files changed +43
-11
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ module.exports.features = bindings.features;
24
24
module . exports . Comment = require ( './lib/comment' ) ;
25
25
module . exports . Document = Document ;
26
26
module . exports . Element = require ( './lib/element' ) ;
27
+ module . exports . Namespace = require ( './lib/namespace' ) ;
27
28
module . exports . Text = require ( './lib/text' ) ;
28
29
29
30
// Compatibility synonyms
Original file line number Diff line number Diff line change @@ -19,5 +19,9 @@ var Comment = function(doc, content) {
19
19
20
20
Comment . prototype = bindings . Comment . prototype ;
21
21
22
+ Comment . prototype . name = function ( ) {
23
+ return "comment" ;
24
+ } ;
25
+
22
26
module . exports = Comment ;
23
27
Original file line number Diff line number Diff line change
1
+ var bindings = require ( './bindings' ) ;
2
+
3
+ var Namespace = function ( ) {
4
+ throw new Error ( 'cannot be directly instantiated' ) ;
5
+ } ;
6
+
7
+ Namespace . prototype = bindings . Namespace . prototype ;
8
+
9
+ Namespace . prototype . type = function ( ) {
10
+ return "namespace_decl" ;
11
+ } ;
12
+
13
+ module . exports = Namespace ;
14
+
Original file line number Diff line number Diff line change @@ -25,4 +25,8 @@ function Text(doc, content) {
25
25
26
26
Text . prototype = bindings . Text . prototype ;
27
27
28
+ Text . prototype . name = function ( ) {
29
+ return "text" ;
30
+ } ;
31
+
28
32
module . exports = Text ;
Original file line number Diff line number Diff line change @@ -275,7 +275,7 @@ XmlElement::get_child(int32_t idx) {
275
275
if (!child)
276
276
return scope.Escape (Nan::Null ());
277
277
278
- return scope.Escape (XmlElement ::New (child));
278
+ return scope.Escape (XmlNode ::New (child));
279
279
}
280
280
281
281
v8::Local<v8::Value>
Original file line number Diff line number Diff line change @@ -218,14 +218,28 @@ XmlNode::New(xmlNode* node)
218
218
{
219
219
Nan::EscapableHandleScope scope;
220
220
switch (node->type ) {
221
+
221
222
case XML_ATTRIBUTE_NODE:
222
223
return scope.Escape (XmlAttribute::New (reinterpret_cast <xmlAttr *>(node)));
223
224
225
+ case XML_TEXT_NODE:
226
+ return scope.Escape (XmlText::New (node));
227
+
228
+ case XML_COMMENT_NODE:
229
+ return scope.Escape (XmlComment::New (node));
230
+
231
+ case XML_DOCUMENT_NODE:
232
+ case XML_HTML_DOCUMENT_NODE:
233
+ #ifdef LIBXML_DOCB_ENABLED
234
+ case XML_DOCB_DOCUMENT_NODE:
235
+ #endif
236
+ return scope.Escape (XmlDocument::New (reinterpret_cast <xmlDoc *>(node)));
237
+
238
+ case XML_NAMESPACE_DECL:
239
+ return scope.Escape (XmlNamespace::New (reinterpret_cast <xmlNs *>(node)));
240
+
241
+ case XML_ELEMENT_NODE:
224
242
default :
225
- // if we don't know how to convert to specific libxmljs wrapper,
226
- // wrap in an XmlElement. There should probably be specific
227
- // wrapper types for text nodes etc., but this is what existing
228
- // code expects.
229
243
return scope.Escape (XmlElement::New (node));
230
244
}
231
245
}
@@ -360,7 +374,7 @@ XmlNode::get_parent() {
360
374
Nan::EscapableHandleScope scope;
361
375
362
376
if (xml_obj->parent ) {
363
- return scope.Escape (XmlElement ::New (xml_obj->parent ));
377
+ return scope.Escape (XmlNode ::New (xml_obj->parent ));
364
378
}
365
379
366
380
return scope.Escape (XmlDocument::New (xml_obj->doc ));
Original file line number Diff line number Diff line change @@ -37,11 +37,6 @@ module.exports.setters = function(assert) {
37
37
module . exports . getters = function ( assert ) {
38
38
var doc = libxml . Document ( ) ;
39
39
var elem = libxml . Text ( doc , 'getters' ) ;
40
-
41
- assert . throws ( function ( ) {
42
- elem . name ( ) ;
43
- } , "text nodes should NOT expose a name" ) ;
44
-
45
40
assert . equal ( 'text' , elem . type ( ) ) ;
46
41
assert . done ( ) ;
47
42
} ;
You can’t perform that action at this time.
0 commit comments