1. Shlomi Fish
  2. perl-XML-LibXML

Commits

ph...@9ae0c189-cd1f-4510-a509-f4891f5cf20d  committed 55a17cd

Modified Files:
dom.c dom.h
+ new: domGetNodeValue()
returns the nodeValue of a node if available.

  • Participants
  • Parent commits e5ab892
  • Branches default

Comments (0)

Files changed (2)

File dom.c

View file
     return oldnode;
 }
 
+xmlChar*
+domGetNodeValue( xmlNodePtr n ) {
+    xmlChar * retval = NULL;
+    if( n != NULL ) {
+        if ( n->type != XML_ATTRIBUTE_NODE ){
+            if ( n->content != NULL ) {
+                retval = xmlStrdup(n->content);
+            }
+            else {
+                if ( n->children != NULL ) {
+                    xmlNodePtr cnode = n->children;
+                    xs_warn ( "oh the node has children ..." );
+                    /* ok then toString in this case ... */
+                    while (cnode) {
+                        xmlBufferPtr buffer = xmlBufferCreate();
+                        /* buffer = xmlBufferCreate(); */
+                        xmlNodeDump( buffer, n->doc, cnode, 0, 0 );
+                        if ( buffer->content != NULL ) {
+                            xs_warn( "add item" );
+                            if ( retval != NULL ) {
+                                retval = xmlStrcat( retval, buffer->content );
+                            }
+                            else {
+                                retval = xmlStrdup( buffer->content );
+                            }
+                        }
+                        xmlBufferFree( buffer );
+                        cnode = cnode->next;
+                    }
+                }
+            }                    
+        }
+        else if ( n->children != NULL ) {
+            xs_warn("copy kiddies content!");
+            retval = xmlStrdup(n->children->content);
+        }
+        else {
+            xs_warn( "no bloddy data!" );
+        }
+    }
+
+    return retval;
+}
+
 void
 domSetNodeValue( xmlNodePtr n , xmlChar* val ){
     if ( n == NULL ) 

File dom.h

View file
                 xmlNodePtr refChild );
 
 /* A.3 extra functionality not specified in DOM L1/2*/
+xmlChar*
+domGetNodeValue( xmlNodePtr self );
 void
 domSetNodeValue( xmlNodePtr self, xmlChar* value );
 void