|
|
| version 1.65, 2004/02/11 15:33:13 | version 1.66, 2004/03/10 10:04:30 |
|---|---|
| Line 26 extern "C" { | Line 26 extern "C" { |
| }; | }; |
| #include "gdome.h" | #include "gdome.h" |
| #include "libxml/xpath.h" | #include "libxml/xpath.h" |
| #include "libxml/xpathInternals.h" | |
| // global variable | // global variable |
| Line 475 static void _normalize(Request& r, Metho | Line 476 static void _normalize(Request& r, Metho |
| throw XmlException(0, exc); | throw XmlException(0, exc); |
| } | } |
| #ifndef DOXYGEN | |
| struct Register_one_ns_info { | |
| Request* r; | |
| xmlXPathContextPtr ctxt; | |
| }; | |
| #endif | |
| static void register_one_ns( | |
| HashStringValue::key_type key, | |
| HashStringValue::value_type value, | |
| Register_one_ns_info* info) { | |
| if(const String* svalue=value->get_string()) | |
| xmlXPathRegisterNs(info->ctxt, | |
| BAD_CAST info->r->transcode(key)->str, | |
| BAD_CAST info->r->transcode(*svalue)->str); | |
| else | |
| throw Exception("parser.runtime", | |
| new String(key, String::L_TAINTED), | |
| "value is %s, must be string or number", value->type()); | |
| } | |
| static void _selectX(Request& r, MethodParams& params, | static void _selectX(Request& r, MethodParams& params, |
| void (*handler)(Request& r, | void (*handler)(Request& r, |
| const String& expression, | const String& expression, |
| Line 484 static void _selectX(Request& r, MethodP | Line 504 static void _selectX(Request& r, MethodP |
| // expression | // expression |
| const String& expression=params.as_string(0, "expression must be string"); | const String& expression=params.as_string(0, "expression must be string"); |
| HashStringValue* namespaces=0; | |
| if(params.count()>1) { | |
| Value* vnamespaces=params.get(1); | |
| namespaces=vnamespaces->get_hash(); | |
| if(!namespaces && !vnamespaces->is_string()) | |
| throw Exception("parser.runtime", | |
| 0, | |
| "namespaces parameter must be hash"); | |
| } | |
| GdomeException exc; | GdomeException exc; |
| GdomeNode* dome_node=vnode.get_node(); | GdomeNode* dome_node=vnode.get_node(); |
| Line 492 static void _selectX(Request& r, MethodP | Line 521 static void _selectX(Request& r, MethodP |
| 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_doc_get_xmlDoc(dome_document); | xmlDoc *xml_document=gdome_xml_doc_get_xmlDoc(dome_document); |
| xmlXPathContext_auto_ptr ctxt(xmlXPathNewContext(xml_document)); | xmlXPathContext_auto_ptr ctxt(xmlXPathNewContext(xml_document)); |
| if(namespaces) { | |
| Register_one_ns_info info={&r, ctxt.get()}; | |
| namespaces->for_each(register_one_ns, &info); | |
| } | |
| 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*/ |
| xmlXPathObject_auto_ptr res( | xmlXPathObject_auto_ptr res( |
| Line 722 MXnode::MXnode(const char* aname, VState | Line 755 MXnode::MXnode(const char* aname, VState |
| /// parser | /// parser |
| // ^node.select[/some/xpath/query] = hash $.#[dnode] | // ^node.select[/some/xpath/query] = hash $.#[dnode] |
| add_native_method("select", Method::CT_DYNAMIC, _select, 1, 1); | add_native_method("select", Method::CT_DYNAMIC, _select, 1, 2); |
| // ^node.selectSingle[/some/xpath/query] = first node [if any] | // ^node.selectSingle[/some/xpath/query] = first node [if any] |
| add_native_method("selectSingle", Method::CT_DYNAMIC, _selectSingle, 1, 1); | add_native_method("selectSingle", Method::CT_DYNAMIC, _selectSingle, 1, 2); |
| // ^node.selectBool[/some/xpath/query] = bool value [if any] | // ^node.selectBool[/some/xpath/query] = bool value [if any] |
| add_native_method("selectBool", Method::CT_DYNAMIC, _selectBool, 1, 1); | add_native_method("selectBool", Method::CT_DYNAMIC, _selectBool, 1, 2); |
| // ^node.selectNumber[/some/xpath/query] = double value [if any] | // ^node.selectNumber[/some/xpath/query] = double value [if any] |
| add_native_method("selectNumber", Method::CT_DYNAMIC, _selectNumber, 1, 1); | add_native_method("selectNumber", Method::CT_DYNAMIC, _selectNumber, 1, 2); |
| // ^node.selectString[/some/xpath/query] = strinv value [if any] | // ^node.selectString[/some/xpath/query] = strinv value [if any] |
| add_native_method("selectString", Method::CT_DYNAMIC, _selectString, 1, 1); | add_native_method("selectString", Method::CT_DYNAMIC, _selectString, 1, 2); |
| // consts | // consts |