|
|
| version 1.78, 2007/08/20 08:56:46 | version 1.87, 2012/03/16 09:24:08 |
|---|---|
| Line 1 | Line 1 |
| /** @file | /** @file |
| Parser: @b dom parser class. | Parser: @b dom parser class. |
| Copyright (c) 2001-2005 ArtLebedev Group (http://www.artlebedev.com) | Copyright (c) 2001-2012 Art. Lebedev Studio (http://www.artlebedev.com) |
| Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru) | Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru) |
| */ | */ |
| #include "classes.h" | #include "classes.h" |
| #ifdef XML | #ifdef XML |
| static const char * const IDENT_XNODE_C="$Date$"; | |
| #include "pa_vmethod_frame.h" | #include "pa_vmethod_frame.h" |
| #include "pa_charset.h" | #include "pa_charset.h" |
| Line 23 static const char * const IDENT_XNODE_C= | Line 21 static const char * const IDENT_XNODE_C= |
| #include "libxml/xpath.h" | #include "libxml/xpath.h" |
| #include "libxml/xpathInternals.h" | #include "libxml/xpathInternals.h" |
| volatile const char * IDENT_XNODE_C="$Id$" IDENT_XNODE_H; | |
| // global variable | // global variable |
| DECLARE_CLASS_VAR(xnode, new MXnode, 0); | DECLARE_CLASS_VAR(xnode, new MXnode, 0); |
| Line 99 private: | Line 99 private: |
| xmlNode& as_node(MethodParams& params, int index, const char* msg) { | xmlNode& as_node(MethodParams& params, int index, const char* msg) { |
| Value& value=params.as_no_junction(index, msg); | Value& value=params.as_no_junction(index, msg); |
| if(Value* vxnode=value.as(VXNODE_TYPE, false)) | if(Value* vxnode=value.as(VXNODE_TYPE)) |
| return static_cast<VXnode*>(vxnode)->get_xmlnode(); | return static_cast<VXnode*>(vxnode)->get_xmlnode(); |
| else | else |
| throw Exception(PARSER_RUNTIME, | throw Exception(PARSER_RUNTIME, |
| Line 111 xmlChar* as_xmlchar(Request& r, MethodPa | Line 111 xmlChar* as_xmlchar(Request& r, MethodPa |
| return r.transcode(params.as_string(index, msg)); | return r.transcode(params.as_string(index, msg)); |
| } | } |
| xmlChar* as_xmlqname(Request& r, MethodParams& params, int index, const char* msg) { | |
| xmlChar* qname=r.transcode(params.as_string(index, msg ? msg : XML_QUALIFIED_NAME_MUST_BE_STRING)); | |
| if(xmlValidateQName(qname, 0)) | |
| throw XmlException(0, XML_INVALID_QUALIFIED_NAME, qname); | |
| return qname; | |
| } | |
| xmlChar* as_xmlncname(Request& r, MethodParams& params, int index, const char* msg) { | |
| xmlChar* ncname=r.transcode(params.as_string(index, msg ? msg : XML_NC_NAME_MUST_BE_STRING)); | |
| if(xmlValidateNCName(ncname, 0)) | |
| throw XmlException(0, XML_INVALID_NC_NAME, ncname); | |
| return ncname; | |
| } | |
| xmlChar* as_xmlname(Request& r, MethodParams& params, int index, const char* msg) { | |
| xmlChar* localName=r.transcode(params.as_string(index, msg ? msg : XML_LOCAL_NAME_MUST_BE_STRING)); | |
| if(xmlValidateName(localName, 0)) | |
| throw XmlException(0, XML_INVALID_LOCAL_NAME, localName); | |
| return localName; | |
| } | |
| xmlChar* as_xmlnsuri(Request& r, MethodParams& params, int index) { | |
| return r.transcode(params.as_string(index, XML_NAMESPACEURI_MUST_BE_STRING)); | |
| } | |
| xmlAttr& as_attr(MethodParams& params, int index, const char* msg) { | xmlAttr& as_attr(MethodParams& params, int index, const char* msg) { |
| xmlNode& xmlnode=as_node(params, index, msg); | xmlNode& xmlnode=as_node(params, index, msg); |
| if(xmlnode.type!=XML_ATTRIBUTE_NODE) | if(xmlnode.type!=XML_ATTRIBUTE_NODE) |
| Line 167 xmlNs& pa_xmlMapNs(xmlDoc& doc, const xm | Line 192 xmlNs& pa_xmlMapNs(xmlDoc& doc, const xm |
| return *cur; | return *cur; |
| } | } |
| /// todo: проверить, обновляется ли parent! | /// @todo: проверить, обновляется ли parent! |
| static void pa_addAttributeNode(xmlNode& selfNode, xmlAttr& attrNode) | static void pa_addAttributeNode(xmlNode& selfNode, xmlAttr& attrNode) |
| { | { |
| if(attrNode.type!=XML_ATTRIBUTE_NODE) | if(attrNode.type!=XML_ATTRIBUTE_NODE) |
| Line 247 pa_xmlNamedPreorderTraversal ( | Line 272 pa_xmlNamedPreorderTraversal ( |
| // Node insertBefore(in Node newChild,in Node refChild) raises(DOMException); | // Node insertBefore(in Node newChild,in Node refChild) raises(DOMException); |
| static void _insertBefore(Request& r, MethodParams& params) { | static void _insertBefore(Request& r, MethodParams& params) { |
| xmlNode& newChild=as_node(params, 0, "newChild must be node"); | |
| xmlNode& refChild=as_node(params, 1, "refChild must be node"); | |
| VXnode& vnode=GET_SELF(r, VXnode); | VXnode& vnode=GET_SELF(r, VXnode); |
| VXdoc& vxdoc=vnode.get_vxdoc(); | VXdoc& vxdoc=vnode.get_vxdoc(); |
| //xmlNode& selfNode=vnode.get_xmlnode(); | //xmlNode& selfNode=vnode.get_xmlnode(); |
| xmlNode& newChild=as_node(params, 0, "newChild must be node"); | |
| xmlNode& refChild=as_node(params, 1, "refChild must be node"); | |
| xmlNode* retNode=xmlAddPrevSibling(&refChild, &newChild); | xmlNode* retNode=xmlAddPrevSibling(&refChild, &newChild); |
| // write out result | // write out result |
| Line 261 static void _insertBefore(Request& r, Me | Line 287 static void _insertBefore(Request& r, Me |
| // Node replaceChild(in Node newChild,in Node oldChild) raises(DOMException); | // Node replaceChild(in Node newChild,in Node oldChild) raises(DOMException); |
| static void _replaceChild(Request& r, MethodParams& params) { | static void _replaceChild(Request& r, MethodParams& params) { |
| xmlNode& newChild=as_node(params, 0, "newChild must be node"); | |
| xmlNode& oldChild=as_node(params, 1, "oldChild must be node"); | |
| VXnode& vnode=GET_SELF(r, VXnode); | VXnode& vnode=GET_SELF(r, VXnode); |
| VXdoc& vxdoc=vnode.get_vxdoc(); | VXdoc& vxdoc=vnode.get_vxdoc(); |
| xmlDoc& xmldoc=vxdoc.get_xmldoc(); | xmlDoc& xmldoc=vxdoc.get_xmldoc(); |
| xmlNode& selfNode=vnode.get_xmlnode(); | xmlNode& selfNode=vnode.get_xmlnode(); |
| xmlNode& newChild=as_node(params, 0, "newChild must be node"); | |
| xmlNode& oldChild=as_node(params, 1, "oldChild must be node"); | |
| if(newChild.doc!=&xmldoc) | if(newChild.doc!=&xmldoc) |
| throw Exception("xml.dom", | throw Exception("xml.dom", |
| Line 296 static void _replaceChild(Request& r, Me | Line 323 static void _replaceChild(Request& r, Me |
| // Node removeChild(in Node oldChild) raises(DOMException); | // Node removeChild(in Node oldChild) raises(DOMException); |
| static void _removeChild(Request& r, MethodParams& params) { | static void _removeChild(Request& r, MethodParams& params) { |
| xmlNode& oldChild=as_node(params, 0, "refChild must be node"); | |
| VXnode& vnode=GET_SELF(r, VXnode); | VXnode& vnode=GET_SELF(r, VXnode); |
| VXdoc& vxdoc=vnode.get_vxdoc(); | VXdoc& vxdoc=vnode.get_vxdoc(); |
| xmlDoc& xmldoc=vxdoc.get_xmldoc(); | xmlDoc& xmldoc=vxdoc.get_xmldoc(); |
| // xmlNode& selfNode=vnode.get_xmlnode(); | // xmlNode& selfNode=vnode.get_xmlnode(); |
| xmlNode& oldChild=as_node(params, 0, "refChild must be node"); | |
| if(oldChild.doc!=&xmldoc) | if(oldChild.doc!=&xmldoc) |
| throw Exception("xml.dom", | throw Exception("xml.dom", |
| Line 314 static void _removeChild(Request& r, Met | Line 342 static void _removeChild(Request& r, Met |
| // Node appendChild(in Node newChild) raises(DOMException); | // Node appendChild(in Node newChild) raises(DOMException); |
| static void _appendChild(Request& r, MethodParams& params) { | static void _appendChild(Request& r, MethodParams& params) { |
| xmlNode& newChild=as_node(params, 0, "newChild must be node"); | |
| VXnode& vnode=GET_SELF(r, VXnode); | VXnode& vnode=GET_SELF(r, VXnode); |
| VXdoc& vxdoc=vnode.get_vxdoc(); | VXdoc& vxdoc=vnode.get_vxdoc(); |
| xmlNode& selfNode=vnode.get_xmlnode(); | xmlNode& selfNode=vnode.get_xmlnode(); |
| xmlNode& newChild=as_node(params, 0, "newChild must be node"); | |
| xmlNode* retNode=xmlAddChild(&selfNode, &newChild); | xmlNode* retNode=xmlAddChild(&selfNode, &newChild); |
| // write out result | // write out result |
| Line 330 static void _hasChildNodes(Request& r, M | Line 359 static void _hasChildNodes(Request& r, M |
| xmlNode& node=vnode.get_xmlnode(); | xmlNode& node=vnode.get_xmlnode(); |
| // write out result | // write out result |
| bool result=node.children!=0; | r.write_no_lang(VBool::get(node.children!=0)); |
| r.write_no_lang(*new VBool(result)); | |
| } | } |
| // Node cloneNode(in boolean deep); | // Node cloneNode(in boolean deep); |
| static void _cloneNode(Request& r, MethodParams& params) { | static void _cloneNode(Request& r, MethodParams& params) { |
| bool deep=params.as_bool(0, "deep must be bool", r); | |
| VXnode& vnode=GET_SELF(r, VXnode); | VXnode& vnode=GET_SELF(r, VXnode); |
| xmlNode& selfNode=vnode.get_xmlnode(); | xmlNode& selfNode=vnode.get_xmlnode(); |
| VXdoc& vxdoc=vnode.get_vxdoc(); | VXdoc& vxdoc=vnode.get_vxdoc(); |
| xmlDoc& xmldoc=vxdoc.get_xmldoc(); | xmlDoc& xmldoc=vxdoc.get_xmldoc(); |
| bool deep=params.as_bool(0, "deep must be bool", r); | |
| xmlNode* retNode=xmlDocCopyNode(&selfNode, &xmldoc, deep?1: 0); | xmlNode* retNode=xmlDocCopyNode(&selfNode, &xmldoc, deep?1: 0); |
| // write out result | // write out result |
| writeNode(r, vxdoc, retNode); | writeNode(r, vxdoc, retNode); |
| Line 361 xmlNode& get_self_element(VXnode& vnode) | Line 389 xmlNode& get_self_element(VXnode& vnode) |
| return node; | return node; |
| } | } |
| // DOMString getAttribute(in DOMString name); | |
| static void _getAttribute(Request& r, MethodParams& params) { | static void _getAttribute(Request& r, MethodParams& params) { |
| const xmlChar* name=as_xmlname(r, params, 0); | |
| VXnode& vnode=GET_SELF(r, VXnode); | VXnode& vnode=GET_SELF(r, VXnode); |
| xmlNode& element=get_self_element(vnode); | xmlNode& element=get_self_element(vnode); |
| const xmlChar* name=as_xmlchar(r, params, 0, "name must be string"); | |
| // todo: when name="xmlns" | // @todo: when name="xmlns" |
| xmlChar* attribute_value=xmlGetProp(&element, name); | xmlChar* attribute_value=xmlGetProp(&element, name); |
| // write out result | // write out result |
| r.write_pass_lang(r.transcode(attribute_value)); | r.write_pass_lang(r.transcode(attribute_value)); |
| Line 375 static void _getAttribute(Request& r, Me | Line 404 static void _getAttribute(Request& r, Me |
| // void setAttribute(in DOMString name, in DOMString value) raises(DOMException); | // void setAttribute(in DOMString name, in DOMString value) raises(DOMException); |
| static void _setAttribute(Request& r, MethodParams& params) { | static void _setAttribute(Request& r, MethodParams& params) { |
| const xmlChar* name=as_xmlname(r, params, 0); | |
| const xmlChar* attribute_value=as_xmlchar(r, params, 1, XML_VALUE_MUST_BE_STRING); | |
| VXnode& vnode=GET_SELF(r, VXnode); | VXnode& vnode=GET_SELF(r, VXnode); |
| xmlNode& element=get_self_element(vnode); | xmlNode& element=get_self_element(vnode); |
| const xmlChar* name=as_xmlchar(r, params, 0, "name must be string"); | |
| const xmlChar* attribute_value=as_xmlchar(r, params, 1, "value must be string"); | |
| // todo: when name="xmlns" | // @todo: when name="xmlns" |
| if(!xmlSetProp(&element, name, attribute_value)) | if(!xmlSetProp(&element, name, attribute_value)) |
| throw XmlException(0); | throw XmlException(0); |
| } | } |
| // void removeAttribute(in DOMString name) raises(DOMException); | // void removeAttribute(in DOMString name) raises(DOMException); |
| static void _removeAttribute(Request& r, MethodParams& params) { | static void _removeAttribute(Request& r, MethodParams& params) { |
| const xmlChar* name=as_xmlname(r, params, 0); | |
| VXnode& vnode=GET_SELF(r, VXnode); | VXnode& vnode=GET_SELF(r, VXnode); |
| xmlNode& element=get_self_element(vnode); | xmlNode& element=get_self_element(vnode); |
| const xmlChar* name=as_xmlchar(r, params, 0, "name must be string"); | |
| // todo: when name="xmlns" | // @todo: when name="xmlns" |
| xmlUnsetProp(&element, name); | xmlUnsetProp(&element, name); |
| } | } |
| // Attr getAttributeNode(in DOMString name); | // Attr getAttributeNode(in DOMString name); |
| static void _getAttributeNode(Request& r, MethodParams& params) { | static void _getAttributeNode(Request& r, MethodParams& params) { |
| const xmlChar* localName=as_xmlname(r, params, 0); | |
| VXnode& vnode=GET_SELF(r, VXnode); | VXnode& vnode=GET_SELF(r, VXnode); |
| VXdoc& vxdoc=vnode.get_vxdoc(); | VXdoc& vxdoc=vnode.get_vxdoc(); |
| xmlNode& element=get_self_element(vnode); | xmlNode& element=get_self_element(vnode); |
| const xmlChar* localName=as_xmlchar(r, params, 0, "name must be string"); | |
| if(xmlNode* retNode=pa_getAttributeNodeNS(element, localName, 0)){ | if(xmlNode* retNode=pa_getAttributeNodeNS(element, localName, 0)){ |
| // write out result | // write out result |
| Line 415 static void _setAttributeNode(Request& r | Line 447 static void _setAttributeNode(Request& r |
| VXdoc& vxdoc=vnode.get_vxdoc(); | VXdoc& vxdoc=vnode.get_vxdoc(); |
| xmlNode& element=get_self_element(vnode); | xmlNode& element=get_self_element(vnode); |
| xmlDoc& xmldoc=vxdoc.get_xmldoc(); | xmlDoc& xmldoc=vxdoc.get_xmldoc(); |
| xmlAttr& newAttr=as_attr(params, 0, "newAttr must be ATTRIBUTE node"); | xmlAttr& newAttr=as_attr(params, 0, "newAttr must be ATTRIBUTE node"); |
| if(newAttr.doc!=&xmldoc) | if(newAttr.doc!=&xmldoc) |
| Line 438 static void _setAttributeNode(Request& r | Line 471 static void _setAttributeNode(Request& r |
| // Attr removeAttributeNode(in Attr oldAttr) raises(DOMException); | // Attr removeAttributeNode(in Attr oldAttr) raises(DOMException); |
| static void _removeAttributeNode(Request& r, MethodParams& params) { | static void _removeAttributeNode(Request& r, MethodParams& params) { |
| xmlAttr& oldAttr=as_attr(params, 0, "oldAttr must be ATTRIBUTE node"); | |
| VXnode& vnode=GET_SELF(r, VXnode); | VXnode& vnode=GET_SELF(r, VXnode); |
| VXdoc& vxdoc=vnode.get_vxdoc(); | VXdoc& vxdoc=vnode.get_vxdoc(); |
| xmlNode& element=get_self_element(vnode); | xmlNode& element=get_self_element(vnode); |
| xmlAttr& oldAttr=as_attr(params, 0, "oldAttr must be ATTRIBUTE node"); | |
| if(oldAttr.parent!=&element) | if(oldAttr.parent!=&element) |
| throw Exception("xml.dom", | throw Exception("xml.dom", |
| Line 455 static void _removeAttributeNode(Request | Line 489 static void _removeAttributeNode(Request |
| } | } |
| // NodeList getElementsByTagName(in DOMString name); | // NodeList getElementsByTagName(in DOMString name); |
| // '*' means all tags | |
| static void _getElementsByTagName(Request& r, MethodParams& params) { | static void _getElementsByTagName(Request& r, MethodParams& params) { |
| xmlChar* tagName=as_xmlchar(r, params, 0, XML_LOCAL_NAME_MUST_BE_STRING); | |
| if(xmlValidateName(tagName, 0) != 0 && strcmp((const char*)tagName, "*") != 0) | |
| throw XmlException(0, XML_INVALID_LOCAL_NAME, tagName); | |
| VXnode& vnode=GET_SELF(r, VXnode); | VXnode& vnode=GET_SELF(r, VXnode); |
| VXdoc& vxdoc=vnode.get_vxdoc(); | VXdoc& vxdoc=vnode.get_vxdoc(); |
| xmlNode& xmlnode=vnode.get_xmlnode(); | xmlNode& xmlnode=vnode.get_xmlnode(); |
| xmlChar* tagName=as_xmlchar(r, params, 0, "name must be string"); | |
| VHash& result=*new VHash; | VHash& result=*new VHash; |
| AccumulateFoundInfo info={&result.hash(), &vxdoc, 0}; | AccumulateFoundInfo info={&result.hash(), &vxdoc, 0}; |
| pa_xmlNamedPreorderTraversal(&xmlnode, | pa_xmlNamedPreorderTraversal(&xmlnode, |
| Line 478 static void _getElementsByTagName(Reques | Line 515 static void _getElementsByTagName(Reques |
| // DOMString getAttributeNS(in DOMString namespaceURI, in DOMString localName); | // DOMString getAttributeNS(in DOMString namespaceURI, in DOMString localName); |
| static void _getAttributeNS(Request& r, MethodParams& params) { | static void _getAttributeNS(Request& r, MethodParams& params) { |
| xmlChar* namespaceURI=as_xmlnsuri(r, params, 0); | |
| xmlChar* localName=as_xmlname(r, params, 1); | |
| VXnode& vnode=GET_SELF(r, VXnode); | VXnode& vnode=GET_SELF(r, VXnode); |
| xmlNode& element=get_self_element(vnode); | xmlNode& element=get_self_element(vnode); |
| xmlChar* namespaceURI=as_xmlchar(r, params, 0, "namespaceURI must be string"); | |
| xmlChar* localName=as_xmlchar(r, params, 1, "localName must be string"); | |
| // todo: when name="xmlns" | // todo: when name="xmlns" |
| xmlChar* attribute_value=xmlGetNsProp(&element, localName, namespaceURI); | xmlChar* attribute_value=xmlGetNsProp(&element, localName, namespaceURI); |
| // write out result | // write out result |
| Line 493 static void _getAttributeNS(Request& r, | Line 530 static void _getAttributeNS(Request& r, |
| // void setAttributeNS(in DOMString namespaceURI, in DOMString qualifiedName, in DOMString value) raises(DOMException); | // void setAttributeNS(in DOMString namespaceURI, in DOMString qualifiedName, in DOMString value) raises(DOMException); |
| static void _setAttributeNS(Request& r, MethodParams& params) { | static void _setAttributeNS(Request& r, MethodParams& params) { |
| const xmlChar* namespaceURI=as_xmlnsuri(r, params, 0); | |
| const xmlChar* qualifiedName=as_xmlqname(r, params, 1); | |
| const xmlChar* attribute_value=as_xmlchar(r, params, 2, XML_VALUE_MUST_BE_STRING); | |
| VXnode& vnode=GET_SELF(r, VXnode); | VXnode& vnode=GET_SELF(r, VXnode); |
| xmlNode& element=get_self_element(vnode); | xmlNode& element=get_self_element(vnode); |
| VXdoc& vxdoc=vnode.get_vxdoc(); | VXdoc& vxdoc=vnode.get_vxdoc(); |
| xmlDoc& xmldoc=vxdoc.get_xmldoc(); | xmlDoc& xmldoc=vxdoc.get_xmldoc(); |
| const xmlChar* namespaceURI=as_xmlchar(r, params, 0, "namespaceURI must be string"); | |
| const xmlChar* qualifiedName=as_xmlchar(r, params, 1, "qualifiedName must be string"); | |
| const xmlChar* attribute_value=as_xmlchar(r, params, 2, "value must be string"); | |
| xmlChar* prefix=0; | xmlChar* prefix=0; |
| xmlChar* localName=xmlSplitQName2(qualifiedName, &prefix); | xmlChar* localName=xmlSplitQName2(qualifiedName, &prefix); |
| // todo: name=xmlns | // @todo: name=xmlns |
| xmlAttr* attrNode; | xmlAttr* attrNode; |
| if(localName) { | if(localName) { |
| xmlNs& ns=pa_xmlMapNs(xmldoc, namespaceURI, prefix); | xmlNs& ns=pa_xmlMapNs(xmldoc, namespaceURI, prefix); |
| Line 524 static void _setAttributeNS(Request& r, | Line 562 static void _setAttributeNS(Request& r, |
| // void removeAttributeNS(in DOMString namespaceURI, in DOMString localName) raises(DOMException); | // void removeAttributeNS(in DOMString namespaceURI, in DOMString localName) raises(DOMException); |
| static void _removeAttributeNS(Request& r, MethodParams& params) { | static void _removeAttributeNS(Request& r, MethodParams& params) { |
| const xmlChar* namespaceURI=as_xmlnsuri(r, params, 0); | |
| const xmlChar* localName=as_xmlname(r, params, 1); | |
| VXnode& vnode=GET_SELF(r, VXnode); | VXnode& vnode=GET_SELF(r, VXnode); |
| xmlNode& element=get_self_element(vnode); | xmlNode& element=get_self_element(vnode); |
| VXdoc& vxdoc=vnode.get_vxdoc(); | VXdoc& vxdoc=vnode.get_vxdoc(); |
| xmlDoc& xmldoc=vxdoc.get_xmldoc(); | xmlDoc& xmldoc=vxdoc.get_xmldoc(); |
| const xmlChar* namespaceURI=as_xmlchar(r, params, 0, "namespaceURI must be string"); | |
| const xmlChar* localName=as_xmlchar(r, params, 1, "localName must be string"); | |
| // todo: when name="xmlns" | // @todo: when name="xmlns" |
| xmlNs& ns=pa_xmlMapNs(xmldoc, namespaceURI, 0); | xmlNs& ns=pa_xmlMapNs(xmldoc, namespaceURI, 0); |
| xmlUnsetNsProp(&element, &ns, localName); | xmlUnsetNsProp(&element, &ns, localName); |
| } | } |
| // Attr getAttributeNodeNS(in DOMString namespaceURI, in DOMString localName); | // Attr getAttributeNodeNS(in DOMString namespaceURI, in DOMString localName); |
| static void _getAttributeNodeNS(Request& r, MethodParams& params) { | static void _getAttributeNodeNS(Request& r, MethodParams& params) { |
| const xmlChar* namespaceURI=as_xmlnsuri(r, params, 0); | |
| const xmlChar* localName=as_xmlname(r, params, 1); | |
| VXnode& vnode=GET_SELF(r, VXnode); | VXnode& vnode=GET_SELF(r, VXnode); |
| VXdoc& vxdoc=vnode.get_vxdoc(); | VXdoc& vxdoc=vnode.get_vxdoc(); |
| xmlNode& element=get_self_element(vnode); | xmlNode& element=get_self_element(vnode); |
| const xmlChar* namespaceURI=as_xmlchar(r, params, 0, "namespaceURI must be string"); | |
| const xmlChar* localName=as_xmlchar(r, params, 1, "localName must be string"); | |
| if(xmlNode* retNode=pa_getAttributeNodeNS(element, localName, namespaceURI)){ | if(xmlNode* retNode=pa_getAttributeNodeNS(element, localName, namespaceURI)){ |
| // write out result | // write out result |
| Line 552 static void _getAttributeNodeNS(Request& | Line 592 static void _getAttributeNodeNS(Request& |
| // boolean hasAttribute(in DOMString name) raises(DOMException); | // boolean hasAttribute(in DOMString name) raises(DOMException); |
| static void _hasAttribute(Request& r, MethodParams& params) { | static void _hasAttribute(Request& r, MethodParams& params) { |
| const xmlChar* name=as_xmlname(r, params, 0); | |
| VXnode& vnode=GET_SELF(r, VXnode); | VXnode& vnode=GET_SELF(r, VXnode); |
| xmlNode& element=get_self_element(vnode); | xmlNode& element=get_self_element(vnode); |
| const xmlChar* name=as_xmlchar(r, params, 0, "name must be string"); | // @todo: when name="xmlns" |
| xmlChar* prop=xmlGetProp(&element, name); | |
| // todo: when name="xmlns" | |
| // write out result | // write out result |
| r.write_no_lang(*new VBool(prop!=0)); | r.write_no_lang(VBool::get(xmlHasProp(&element, name)!=0)); |
| } | } |
| // boolean hasAttributeNS(n DOMString namespaceURI, in DOMString localName) raises(DOMException); | // boolean hasAttributeNS(n DOMString namespaceURI, in DOMString localName) raises(DOMException); |
| static void _hasAttributeNS(Request& r, MethodParams& params) { | static void _hasAttributeNS(Request& r, MethodParams& params) { |
| const xmlChar* namespaceURI=as_xmlnsuri(r, params, 0); | |
| const xmlChar* localName=as_xmlname(r, params, 1); | |
| VXnode& vnode=GET_SELF(r, VXnode); | VXnode& vnode=GET_SELF(r, VXnode); |
| xmlNode& element=get_self_element(vnode); | xmlNode& element=get_self_element(vnode); |
| const xmlChar* namespaceURI=as_xmlchar(r, params, 0, "namespaceURI must be string"); | |
| const xmlChar* localName=as_xmlchar(r, params, 1, "localName must be string"); | |
| xmlChar* prop=xmlGetNsProp(&element, localName, namespaceURI); | |
| // write out result | // write out result |
| r.write_no_lang(*new VBool(prop!=0)); | r.write_no_lang(VBool::get(xmlHasNsProp(&element, localName, namespaceURI)!=0)); |
| } | } |
| // boolean hasAttributes | // boolean hasAttributes |
| Line 582 static void _hasAttributes(Request& r, M | Line 620 static void _hasAttributes(Request& r, M |
| xmlNode& element=get_self_element(vnode); | xmlNode& element=get_self_element(vnode); |
| // write out result | // write out result |
| r.write_no_lang(*new VBool(element.properties!=0)); | r.write_no_lang(VBool::get(element.properties!=0)); |
| } | } |
| // NodeList getElementsByTagNameNS(in DOMString namespaceURI, in DOMString localName); | |
| // '*' as namespaceURI means get all namespaces | |
| // '*' as localName means get all tags | |
| static void _getElementsByTagNameNS(Request& r, MethodParams& params) { | static void _getElementsByTagNameNS(Request& r, MethodParams& params) { |
| xmlChar* namespaceURI=as_xmlchar(r, params, 0, XML_NAMESPACEURI_MUST_BE_STRING); | |
| xmlChar* localName=as_xmlchar(r, params, 1, XML_LOCAL_NAME_MUST_BE_STRING); | |
| if(xmlValidateName(localName, 0) != 0 && strcmp((const char*)localName, "*") != 0) | |
| throw XmlException(0, XML_INVALID_LOCAL_NAME, localName); | |
| VXnode& vnode=GET_SELF(r, VXnode); | VXnode& vnode=GET_SELF(r, VXnode); |
| VXdoc& vdoc=vnode.get_vxdoc(); | VXdoc& vdoc=vnode.get_vxdoc(); |
| xmlDoc& xmldoc=vdoc.get_xmldoc(); | xmlDoc& xmldoc=vdoc.get_xmldoc(); |
| // namespaceURI;localName | |
| xmlChar* namespaceURI=as_xmlchar(r, params, 0, "namespaceURI must be string"); | |
| xmlChar* localName=as_xmlchar(r, params, 1, "name must be string"); | |
| VHash& result=*new VHash; | VHash& result=*new VHash; |
| AccumulateFoundInfo info={&result.hash(), &vdoc, 0}; | AccumulateFoundInfo info={&result.hash(), &vdoc, 0}; |
| pa_xmlNamedPreorderTraversal((xmlNode*)&xmldoc, | pa_xmlNamedPreorderTraversal((xmlNode*)&xmldoc, |
| Line 708 static void selectNodeHandler(Request& r | Line 751 static void selectNodeHandler(Request& r |
| case XPATH_UNDEFINED: | case XPATH_UNDEFINED: |
| break; | break; |
| case XPATH_NODESET: | case XPATH_NODESET: |
| if(res->nodesetval && res->nodesetval->nodeNr) { // empty result strangly has NODESET res->type | if(res->nodesetval && res->nodesetval->nodeNr) { // empty result strangely has NODESET res->type |
| if(res->nodesetval->nodeNr>1) | if(res->nodesetval->nodeNr>1) |
| throw Exception(PARSER_RUNTIME, | throw Exception(PARSER_RUNTIME, |
| &expression, | &expression, |
| Line 718 static void selectNodeHandler(Request& r | Line 761 static void selectNodeHandler(Request& r |
| } | } |
| break; | break; |
| case XPATH_BOOLEAN: | case XPATH_BOOLEAN: |
| result=new VBool(res->boolval!=0); | result=&VBool::get(res->boolval!=0); |
| break; | break; |
| case XPATH_NUMBER: | case XPATH_NUMBER: |
| result=new VDouble(res->floatval); | result=new VDouble(res->floatval); |
| Line 740 static void selectBoolHandler(Request&, | Line 783 static void selectBoolHandler(Request&, |
| Value*& result) { | Value*& result) { |
| switch(res->type) { | switch(res->type) { |
| case XPATH_BOOLEAN: | case XPATH_BOOLEAN: |
| result=new VBool(res->boolval!=0); | result=&VBool::get(res->boolval!=0); |
| break; | break; |
| case XPATH_NODESET: | case XPATH_NODESET: |
| if(!(res->nodesetval && res->nodesetval->nodeNr)) | if(!(res->nodesetval && res->nodesetval->nodeNr)) |