Diff for /parser3/src/classes/xnode.C between versions 1.32 and 1.39

version 1.32, 2002/01/24 14:10:08 version 1.39, 2002/02/19 15:03:10
Line 1 Line 1
 /** @file  /** @file
         Parser: @b dom parser class.          Parser: @b dom parser class.
   
         Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)          Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com)
         Author: Alexander Petrosyan <paf@design.ru> (http://paf.design.ru)          Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
   
         $Id$          $Id$
 */  */
Line 12 Line 12
 #include "pa_charset.h"  #include "pa_charset.h"
 #include "pa_request.h"  #include "pa_request.h"
 #include "pa_vxnode.h"  #include "pa_vxnode.h"
   #include "pa_vxdoc.h"
 #include "pa_vvoid.h"  #include "pa_vvoid.h"
   
 #include "xnode.h"  #include "xnode.h"
Line 23  extern "C" { Line 24  extern "C" {
 #include "gdome.h"  #include "gdome.h"
 #include "libxml/xpath.h"  #include "libxml/xpath.h"
   
   // defines 
   
   #define XNODE_CLASS_NAME "xnode"
   
 // classes  // classes
   
 class xmlXPathObject_auto_ptr {  class xmlXPathObject_auto_ptr {
Line 91  private: Line 96  private:
         xmlXPathContext *_Ptr;          xmlXPathContext *_Ptr;
 };  };
   
 // defines  
   
 #define XNODE_CLASS_NAME "xnode"  
   
 // helpers  // helpers
   
 GdomeNode *as_node(Pool& pool, const String& method_name, MethodParams *params,   GdomeNode *as_node(Pool& pool, const String& method_name, MethodParams *params, 
                                                 int index, const char *msg) {                                                  int index, const char *msg) {
         Value& value=params->as_no_junction(index, msg);          Value& value=params->as_no_junction(index, msg);
         if(strcmp(value.type(), VXNODE_TYPE)!=0)          if(!(strcmp(value.type(), VXNODE_TYPE)==0 
                   || strcmp(value.type(), VXDOC_TYPE)==0))
                 throw Exception(0, 0,                  throw Exception(0, 0,
                         &method_name,                          &method_name,
                         msg);                          msg);
Line 212  static void _hasChildNodes(Request& r, c Line 214  static void _hasChildNodes(Request& r, c
 }  }
   
 // Node cloneNode(in boolean deep);  // Node cloneNode(in boolean deep);
 /// @test ownerDocument=?  
 static void _cloneNode(Request& r, const String& method_name, MethodParams *params) {  static void _cloneNode(Request& r, const String& method_name, MethodParams *params) {
         Pool& pool=r.pool();          Pool& pool=r.pool();
         VXnode& vnode=*static_cast<VXnode *>(r.self);          VXnode& vnode=*static_cast<VXnode *>(r.self);
Line 367  static void _getElementsByTagName(Reques Line 368  static void _getElementsByTagName(Reques
         r.write_no_lang(result);          r.write_no_lang(result);
 }  }
   
   static void _getElementsByTagNameNS(Request& r, const String& method_name, MethodParams *params) {
           Pool& pool=r.pool();
           GdomeElement *element=get_self_element(r, method_name);
   
           // namespaceURI;localName
           const String& namespaceURI=params->as_string(0, "namespaceURI must be string");
           const String& localName=params->as_string(1, "localName must be string");
   
           GdomeException exc;
           VHash& result=*new(pool) VHash(pool);
           if(GdomeNodeList *nodes=
                   gdome_el_getElementsByTagNameNS(
                           element, 
                           pool.transcode(namespaceURI).get(),
                           pool.transcode(localName).get(),
                           &exc)) {
                   gulong length=gdome_nl_length(nodes, &exc);
                   for(gulong i=0; i<length; i++) {
                           String& skey=*new(pool) String(pool);
                           {
                                   char *buf=(char *)pool.malloc(MAX_NUMBER);
                                   snprintf(buf, MAX_NUMBER, "%d", i);
                                   skey << buf;
                           }
   
                           result.hash(0).put(skey, new(pool) VXnode(pool, gdome_nl_item(nodes, i, &exc)));
                   }
           }
   
           // write out result
           r.write_no_lang(result);
   }
   
 // void normalize();  // void normalize();
 static void _normalize(Request& r, const String& method_name, MethodParams *) {  static void _normalize(Request& r, const String& method_name, MethodParams *) {
         Pool& pool=r.pool();          Pool& pool=r.pool();
Line 398  static void _selectX(Request& r, const S Line 432  static void _selectX(Request& r, const S
         GdomeDocument *dome_document=gdome_n_ownerDocument(dome_node, &exc);          GdomeDocument *dome_document=gdome_n_ownerDocument(dome_node, &exc);
         if(!dome_document) // document does not own itself, so ownerDocument = 0          if(!dome_document) // document does not own itself, so ownerDocument = 0
                 dome_document=GDOME_DOC(dome_node); // and we need downcast                  dome_document=GDOME_DOC(dome_node); // and we need downcast
         xmlDoc *xml_document=((_Gdome_xml_Document *)dome_document)->n;          xmlDoc *xml_document=gdome_xml_doc_get_xmlDoc(dome_document);
     xmlXPathContext_auto_ptr ctxt(xmlXPathNewContext(xml_document));      xmlXPathContext_auto_ptr ctxt(xmlXPathNewContext(xml_document));
         ctxt->node=gdome_xml_n_get_xmlNode(dome_node);          ctxt->node=gdome_xml_n_get_xmlNode(dome_node);
         /*error to stderr for now*/          /*error to stderr for now*/
Line 617  MXnode::MXnode(Pool& apool) : Methoded(a Line 651  MXnode::MXnode(Pool& apool) : Methoded(a
         add_native_method("removeAttributeNode", Method::CT_DYNAMIC, _removeAttributeNode, 1, 1);          add_native_method("removeAttributeNode", Method::CT_DYNAMIC, _removeAttributeNode, 1, 1);
         // NodeList getElementsByTagName(in DOMString name);          // NodeList getElementsByTagName(in DOMString name);
         add_native_method("getElementsByTagName", Method::CT_DYNAMIC, _getElementsByTagName, 1, 1);          add_native_method("getElementsByTagName", Method::CT_DYNAMIC, _getElementsByTagName, 1, 1);
           // NodeList getElementsByTagNameNS(in DOMString namespaceURI, in DOMString localName);
           add_native_method("getElementsByTagNameNS", Method::CT_DYNAMIC, _getElementsByTagNameNS, 2, 2);
         // void normalize();          // void normalize();
         add_native_method("normalize", Method::CT_DYNAMIC, _normalize, 0, 0);          add_native_method("normalize", Method::CT_DYNAMIC, _normalize, 0, 0);
   

Removed from v.1.32  
changed lines
  Added in v.1.39


E-mail: