--- parser3/src/classes/Attic/dnode.C 2001/09/18 12:25:06 1.1 +++ parser3/src/classes/Attic/dnode.C 2001/09/21 14:46:09 1.5 @@ -5,20 +5,17 @@ Author: Alexander Petrosyan (http://design.ru/paf) */ -static const char *RCSId="$Id: dnode.C,v 1.1 2001/09/18 12:25:06 parser Exp $"; +#include "classes.h" +#ifdef XML -#if _MSC_VER -# pragma warning(disable:4291) // disable warning -// "no matching operator delete found; memory will not be freed if initialization throws an exception -#endif +static const char *RCSId="$Id: dnode.C,v 1.5 2001/09/21 14:46:09 parser Exp $"; -#include "classes.h" #include "pa_request.h" #include "pa_vdnode.h" + #include "dnode.h" #include -//#include #include #include #include @@ -31,10 +28,10 @@ static const char *RCSId="$Id: dnode.C,v // methods -static void _xpath(Request& r, const String& method_name, MethodParams *params) { +static void _select(Request& r, const String& method_name, MethodParams *params) { // _asm int 3; Pool& pool=r.pool(); - VDnode& vdnode=*static_cast(r.self); + VDnode& vnode=*static_cast(r.self); // expression const String& expression=params->as_string(0, "expression must not be code"); @@ -50,7 +47,7 @@ static void _xpath(Request& r, const Str try { NodeRefList list=evaluator.selectNodeList(dom_support, - &vdnode.get_node(pool, &method_name), + &vnode.get_node(pool, &method_name), expression_dcstr); VHash& result=*new(pool) VHash(pool); @@ -67,7 +64,38 @@ static void _xpath(Request& r, const Str result.set_name(method_name); r.write_no_lang(result); } catch(const XSLException& e) { - _throw(pool, &expression, e); + r._throw(&expression, e); + } +} + +static void _select_single(Request& r, const String& method_name, MethodParams *params) { +// _asm int 3; + Pool& pool=r.pool(); + VDnode& vnode=*static_cast(r.self); + + // expression + const String& expression=params->as_string(0, "expression must not be code"); + const char *expression_cstr=expression.cstr(String::UL_AS_IS); + XalanDOMString dstring(expression_cstr); + const XalanDOMChar *expression_dcstr=dstring.c_str(); + + XPathEvaluator evaluator; + // Initialize the XalanSourceTree subsystem... +// XalanSourceTreeInit theSourceTreeInit; + // We'll use these to parse the XML file. + XalanSourceTreeDOMSupport dom_support; + + try { + if(XalanNode *node=evaluator.selectSingleNode(dom_support, + &vnode.get_node(pool, &method_name), + expression_dcstr)) { + + VDnode& result=*new(pool) VDnode(pool, node); + result.set_name(method_name); + r.write_no_lang(result); + } + } catch(const XSLException& e) { + r._throw(&expression, e); } } @@ -76,16 +104,26 @@ static void _xpath(Request& r, const Str MDnode::MDnode(Pool& apool) : Methoded(apool) { set_name(*NEW String(pool(), DNODE_CLASS_NAME)); - // ^node.xpath[/some/xpath/query] - add_native_method("xpath", Method::CT_DYNAMIC, _xpath, 1, 1); + // ^node.select[/some/xpath/query] = hash $.#[dnode] + add_native_method("select", Method::CT_DYNAMIC, _select, 1, 1); + + // ^node.select-single[/some/xpath/query] = first dnode + add_native_method("select-single", Method::CT_DYNAMIC, _select_single, 1, 1); } // global variable Methoded *Dnode_class; -// creator +#endif +// creator Methoded *MDnode_create(Pool& pool) { - return Dnode_class=new(pool) MDnode(pool); + return +#ifdef XML + Dnode_class=new(pool) MDnode(pool) +#else + 0 +#endif + ; }