--- parser3/src/classes/xnode.C 2002/01/14 15:29:41 1.26 +++ parser3/src/classes/xnode.C 2002/01/28 10:40:06 1.34 @@ -4,7 +4,7 @@ Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) Author: Alexander Petrosyan (http://paf.design.ru) - $Id: xnode.C,v 1.26 2002/01/14 15:29:41 paf Exp $ + $Id: xnode.C,v 1.34 2002/01/28 10:40:06 paf Exp $ */ #include "classes.h" #ifdef XML @@ -12,23 +12,28 @@ #include "pa_charset.h" #include "pa_request.h" #include "pa_vxnode.h" +#include "pa_vxdoc.h" #include "pa_vvoid.h" #include "xnode.h" extern "C" { #include "gdomecore/gdome-xml-node.h" -}; #include "gdomecore/gdome-xml-document.h" +}; #include "gdome.h" #include "libxml/xpath.h" +// defines + +#define XNODE_CLASS_NAME "xdoc" + // classes class xmlXPathObject_auto_ptr { public: - explicit xmlXPathObject_auto_ptr(xmlXPathObject *_P = 0) - : _Owns(_P != 0), _Ptr(_P) {} + explicit xmlXPathObject_auto_ptr(xmlXPathObject *_APtr = 0) + : _Owns(_APtr != 0), _Ptr(_APtr) {} xmlXPathObject_auto_ptr(const xmlXPathObject_auto_ptr& _Y) : _Owns(_Y._Owns), _Ptr(_Y.release()) {} xmlXPathObject_auto_ptr& operator=(const xmlXPathObject_auto_ptr& _Y) @@ -60,8 +65,8 @@ private: class xmlXPathContext_auto_ptr { public: - explicit xmlXPathContext_auto_ptr(xmlXPathContext *_P = 0) - : _Owns(_P != 0), _Ptr(_P) {} + explicit xmlXPathContext_auto_ptr(xmlXPathContext *_APtr = 0) + : _Owns(_APtr != 0), _Ptr(_APtr) {} xmlXPathContext_auto_ptr(const xmlXPathContext_auto_ptr& _Y) : _Owns(_Y._Owns), _Ptr(_Y.release()) {} xmlXPathContext_auto_ptr& operator=(const xmlXPathContext_auto_ptr& _Y) @@ -91,16 +96,13 @@ private: xmlXPathContext *_Ptr; }; -// defines - -#define XNODE_CLASS_NAME "xnode" - // helpers GdomeNode *as_node(Pool& pool, const String& method_name, MethodParams *params, int index, const char *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, &method_name, msg); @@ -396,15 +398,22 @@ static void _selectX(Request& r, const S GdomeException exc; GdomeNode *dome_node=vnode.get_node(&method_name); GdomeDocument *dome_document=gdome_n_ownerDocument(dome_node, &exc); - if(!dome_document) - dome_document=GDOME_DOC(dome_node); - xmlDoc *xml_document=((_Gdome_xml_Document *)dome_document)->n; + if(!dome_document) // document does not own itself, so ownerDocument = 0 + dome_document=GDOME_DOC(dome_node); // and we need downcast + xmlDoc *xml_document=gdome_xml_doc_get_xmlDoc(dome_document); xmlXPathContext_auto_ptr ctxt(xmlXPathNewContext(xml_document)); - ctxt->node=xmlDocGetRootElement(xml_document); + ctxt->node=gdome_xml_n_get_xmlNode(dome_node); /*error to stderr for now*/ xmlXPathObject_auto_ptr res( xmlXPathEvalExpression(BAD_CAST pool.transcode(expression)->str, ctxt.get())); + if(xmlHaveGenericErrors()) { + GdomeException exc=0; + throw Exception(0, 0, + &expression, + exc); + } + Value *result=0; if(res.get()) handler(pool, expression, res, result); @@ -418,12 +427,12 @@ static void selectNodesHandler(Pool& poo const String& expression, xmlXPathObject_auto_ptr res, Value *& result) { + VHash *vhash=new(pool) VHash(pool); result=vhash; switch(res->type) { case XPATH_UNDEFINED: break; case XPATH_NODESET: if(int size=res->nodesetval->nodeNr) { - VHash *vhash=new(pool) VHash(pool); Hash& hash=vhash->hash(0); for(int i=0; inodesetval->nodeTab[0]))); + gdome_xml_n_mkref(res->nodesetval->nodeTab[i]))); } - result=vhash; } break; default: