|
|
| version 1.92, 2016/03/31 21:46:20 | version 1.104, 2026/09/20 00:27:40 |
|---|---|
| Line 1 | Line 1 |
| /** @file | /** @file |
| Parser: @b dom parser class. | Parser: @b dom parser class. |
| Copyright (c) 2001-2015 Art. Lebedev Studio (http://www.artlebedev.com) | Copyright (c) 2001-2026 Art. Lebedev Studio (https://www.artlebedev.com) |
| Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru) | Authors: Konstantin Morshnev <moko@design.ru>, Alexandr Petrosian <paf@design.ru> |
| */ | */ |
| #include "classes.h" | #include "classes.h" |
| #ifdef XML | #ifdef XML |
| Line 23 | Line 23 |
| volatile const char * IDENT_XNODE_C="$Id$" IDENT_XNODE_H; | volatile const char * IDENT_XNODE_C="$Id$" IDENT_XNODE_H; |
| // global variable | |
| DECLARE_CLASS_VAR(xnode, new MXnode); | |
| // classes | // classes |
| class xmlXPathObject_auto_ptr { | class xmlXPathObject_auto_ptr { |
| Line 99 private: | Line 95 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)) | if(VXnode* vxnode=dynamic_cast<VXnode*>(&value)) |
| return static_cast<VXnode*>(vxnode)->get_xmlnode(); | return vxnode->get_xmlnode(); |
| else | else |
| throw Exception(PARSER_RUNTIME, | throw Exception(PARSER_RUNTIME, 0, msg); |
| 0, | |
| msg); | |
| } | } |
| xmlChar* as_xmlchar(Request& r, MethodParams& params, int index, const char* msg) { | xmlChar* as_xmlchar(Request& r, MethodParams& params, int index, const char* msg) { |
| Line 151 static void writeNode(Request& r, VXdoc& | Line 145 static void writeNode(Request& r, VXdoc& |
| throw XmlException(0, r); // OOM, bad name, things like that | throw XmlException(0, r); // OOM, bad name, things like that |
| // write out result | // write out result |
| r.write_no_lang(xdoc.wrap(*node)); | r.write(xdoc.wrap(*node)); |
| } | } |
| static xmlNode* pa_getAttributeNodeNS(xmlNode& selfNode, | static xmlNode* pa_getAttributeNodeNS(xmlNode& selfNode, |
| Line 236 struct AccumulateFoundInfo | Line 230 struct AccumulateFoundInfo |
| #endif | #endif |
| static void AccumulateFound(xmlNode& node, AccumulateFoundInfo* info) | static void AccumulateFound(xmlNode& node, AccumulateFoundInfo* info) |
| { | { |
| info->hash->put( | info->hash->put(String::Body::uitoa(info->index++), &info->vdoc->wrap(node)); |
| String::Body::Format(info->index++), | |
| &info->vdoc->wrap(node)); | |
| } | } |
| template<typename I> static void | template<typename I> static void |
| pa_xmlNamedPreorderTraversal ( | pa_xmlNamedPreorderTraversal ( |
| Line 359 static void _hasChildNodes(Request& r, M | Line 351 static void _hasChildNodes(Request& r, M |
| xmlNode& node=vnode.get_xmlnode(); | xmlNode& node=vnode.get_xmlnode(); |
| // write out result | // write out result |
| r.write_no_lang(VBool::get(node.children!=0)); | r.write(VBool::get(node.children!=0)); |
| } | } |
| // Node cloneNode(in boolean deep); | // Node cloneNode(in boolean deep); |
| Line 399 static void _getAttribute(Request& r, Me | Line 391 static void _getAttribute(Request& r, Me |
| // @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(r.transcode(attribute_value)); |
| } | } |
| // void setAttribute(in DOMString name, in DOMString value) raises(DOMException); | // void setAttribute(in DOMString name, in DOMString value) raises(DOMException); |
| Line 508 static void _getElementsByTagName(Reques | Line 500 static void _getElementsByTagName(Reques |
| &info); | &info); |
| // write out result | // write out result |
| r.write_no_lang(result); | r.write(result); |
| } | } |
| // DOM 2 | // DOM 2 |
| Line 524 static void _getAttributeNS(Request& r, | Line 516 static void _getAttributeNS(Request& r, |
| // 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 |
| r.write_pass_lang(r.transcode(attribute_value)); | r.write(r.transcode(attribute_value)); |
| } | } |
| Line 599 static void _hasAttribute(Request& r, Me | Line 591 static void _hasAttribute(Request& r, Me |
| // @todo: when name="xmlns" | // @todo: when name="xmlns" |
| // write out result | // write out result |
| r.write_no_lang(VBool::get(xmlHasProp(&element, name)!=0)); | r.write(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); |
| Line 611 static void _hasAttributeNS(Request& r, | Line 603 static void _hasAttributeNS(Request& r, |
| xmlNode& element=get_self_element(vnode); | xmlNode& element=get_self_element(vnode); |
| // write out result | // write out result |
| r.write_no_lang(VBool::get(xmlHasNsProp(&element, localName, namespaceURI)!=0)); | r.write(VBool::get(xmlHasNsProp(&element, localName, namespaceURI)!=0)); |
| } | } |
| // boolean hasAttributes | // boolean hasAttributes |
| Line 620 static void _hasAttributes(Request& r, M | Line 612 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(VBool::get(element.properties!=0)); | r.write(VBool::get(element.properties!=0)); |
| } | } |
| // NodeList getElementsByTagNameNS(in DOMString namespaceURI, in DOMString localName); | // NodeList getElementsByTagNameNS(in DOMString namespaceURI, in DOMString localName); |
| Line 646 static void _getElementsByTagNameNS(Requ | Line 638 static void _getElementsByTagNameNS(Requ |
| &info); | &info); |
| // write out result | // write out result |
| r.write_no_lang(result); | r.write(result); |
| } | } |
| Line 712 static void _selectX(Request& r, MethodP | Line 704 static void _selectX(Request& r, MethodP |
| if(res.get()) | if(res.get()) |
| handler(r, expression, res, vdoc, result); | handler(r, expression, res, vdoc, result); |
| if(result) | if(result) |
| r.write_no_lang(*result); | r.write(*result); |
| } | } |
| static void selectNodesHandler(Request&, | static void selectNodesHandler(Request&, |
| Line 729 static void selectNodesHandler(Request&, | Line 721 static void selectNodesHandler(Request&, |
| if(int size=res->nodesetval->nodeNr) { | if(int size=res->nodesetval->nodeNr) { |
| HashStringValue& hash=vhash.hash(); | HashStringValue& hash=vhash.hash(); |
| for(int i=0; i<size; i++) | for(int i=0; i<size; i++) |
| hash.put( | hash.put(String::Body::uitoa(i), &xdoc.wrap(*res->nodesetval->nodeTab[i])); |
| String::Body::Format(i), | |
| &xdoc.wrap(*res->nodesetval->nodeTab[i])); | |
| } | } |
| break; | break; |
| default: | default: |
| Line 869 static void _selectString(Request& r, Me | Line 859 static void _selectString(Request& r, Me |
| // constructor | // constructor |
| /// @bug one can change const and ruin other's work, we need unchangable VIntConst class | /// @bug one can change const and ruin other's work, we need unchangable VIntConst class |
| MXnode::MXnode(const char* aname, VStateless_class *abase): | MXnode::MXnode(const char* aname): Methoded(aname?aname:"xnode") { |
| Methoded(aname?aname:"xnode", abase) | |
| { | |
| /// DOM1 node | /// DOM1 node |
| // Node insertBefore(in Node newChild,in Node refChild) raises(DOMException); | // Node insertBefore(in Node newChild,in Node refChild) raises(DOMException); |
| Line 943 MXnode::MXnode(const char* aname, VState | Line 931 MXnode::MXnode(const char* aname, VState |
| // consts | // consts |
| #define CONST(name) consts.put(#name, new VInt(XML_##name)) | #define PA_CONST(name) consts.put(#name, new VInt(XML_##name)) |
| #define CONST2(name, value) consts.put(#name, new VInt(value)) | #define PA_CONST2(name, value) consts.put(#name, new VInt(value)) |
| CONST(ELEMENT_NODE); | PA_CONST(ELEMENT_NODE); |
| CONST(ATTRIBUTE_NODE); | PA_CONST(ATTRIBUTE_NODE); |
| CONST(TEXT_NODE); | PA_CONST(TEXT_NODE); |
| CONST(CDATA_SECTION_NODE); | PA_CONST(CDATA_SECTION_NODE); |
| CONST2(ENTITY_REFERENCE_NODE, XML_ENTITY_REF_NODE); | PA_CONST2(ENTITY_REFERENCE_NODE, XML_ENTITY_REF_NODE); |
| CONST(ENTITY_NODE); | PA_CONST(ENTITY_NODE); |
| CONST2(PROCESSING_INSTRUCTION_NODE, XML_PI_NODE); | PA_CONST2(PROCESSING_INSTRUCTION_NODE, XML_PI_NODE); |
| CONST(COMMENT_NODE); | PA_CONST(COMMENT_NODE); |
| CONST(DOCUMENT_NODE); | PA_CONST(DOCUMENT_NODE); |
| CONST(DOCUMENT_TYPE_NODE); | PA_CONST(DOCUMENT_TYPE_NODE); |
| CONST2(DOCUMENT_FRAGMENT_NODE, XML_DOCUMENT_FRAG_NODE); | PA_CONST2(DOCUMENT_FRAGMENT_NODE, XML_DOCUMENT_FRAG_NODE); |
| CONST(NOTATION_NODE); | PA_CONST(NOTATION_NODE); |
| } | } |
| #else | |
| // global variable | |
| DECLARE_CLASS_VAR(xnode, 0); // fictive | |
| #endif | #endif |