2 * DOM Document implementation
4 * Copyright 2005 Mike McCormack
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
33 #include "msxml_private.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
41 static const xmlChar DT_prefix[] = "dt";
42 static const xmlChar DT_nsURI[] = "urn:schemas-microsoft-com:datatypes";
44 typedef struct _domelem
47 IXMLDOMElement IXMLDOMElement_iface;
51 static inline domelem *impl_from_IXMLDOMElement( IXMLDOMElement *iface )
53 return CONTAINING_RECORD(iface, domelem, IXMLDOMElement_iface);
56 static inline xmlNodePtr get_element( const domelem *This )
58 return This->node.node;
61 static HRESULT WINAPI domelem_QueryInterface(
62 IXMLDOMElement *iface,
66 domelem *This = impl_from_IXMLDOMElement( iface );
68 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
70 if ( IsEqualGUID( riid, &IID_IXMLDOMElement ) ||
71 IsEqualGUID( riid, &IID_IXMLDOMNode ) ||
72 IsEqualGUID( riid, &IID_IDispatch ) ||
73 IsEqualGUID( riid, &IID_IUnknown ) )
75 *ppvObject = &This->IXMLDOMElement_iface;
77 else if(node_query_interface(&This->node, riid, ppvObject))
79 return *ppvObject ? S_OK : E_NOINTERFACE;
83 FIXME("interface %s not implemented\n", debugstr_guid(riid));
87 IUnknown_AddRef( (IUnknown*)*ppvObject );
91 static ULONG WINAPI domelem_AddRef(
92 IXMLDOMElement *iface )
94 domelem *This = impl_from_IXMLDOMElement( iface );
95 LONG ref = InterlockedIncrement(&This->ref);
97 TRACE("(%p) ref=%d\n", This, ref);
102 static ULONG WINAPI domelem_Release(
103 IXMLDOMElement *iface )
105 domelem *This = impl_from_IXMLDOMElement( iface );
106 ULONG ref = InterlockedDecrement(&This->ref);
108 TRACE("(%p) ref=%d\n", This, ref);
111 destroy_xmlnode(&This->node);
118 static HRESULT WINAPI domelem_GetTypeInfoCount(
119 IXMLDOMElement *iface,
122 domelem *This = impl_from_IXMLDOMElement( iface );
124 TRACE("(%p)->(%p)\n", This, pctinfo);
131 static HRESULT WINAPI domelem_GetTypeInfo(
132 IXMLDOMElement *iface,
133 UINT iTInfo, LCID lcid,
134 ITypeInfo** ppTInfo )
136 domelem *This = impl_from_IXMLDOMElement( iface );
139 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
141 hr = get_typeinfo(IXMLDOMElement_tid, ppTInfo);
146 static HRESULT WINAPI domelem_GetIDsOfNames(
147 IXMLDOMElement *iface,
148 REFIID riid, LPOLESTR* rgszNames,
149 UINT cNames, LCID lcid, DISPID* rgDispId )
151 domelem *This = impl_from_IXMLDOMElement( iface );
155 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
158 if(!rgszNames || cNames == 0 || !rgDispId)
161 hr = get_typeinfo(IXMLDOMElement_tid, &typeinfo);
164 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
165 ITypeInfo_Release(typeinfo);
171 static HRESULT WINAPI domelem_Invoke(
172 IXMLDOMElement *iface,
173 DISPID dispIdMember, REFIID riid, LCID lcid,
174 WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
175 EXCEPINFO* pExcepInfo, UINT* puArgErr )
177 domelem *This = impl_from_IXMLDOMElement( iface );
181 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
182 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
184 hr = get_typeinfo(IXMLDOMElement_tid, &typeinfo);
187 hr = ITypeInfo_Invoke(typeinfo, &This->IXMLDOMElement_iface, dispIdMember, wFlags,
188 pDispParams, pVarResult, pExcepInfo, puArgErr);
189 ITypeInfo_Release(typeinfo);
195 static HRESULT WINAPI domelem_get_nodeName(
196 IXMLDOMElement *iface,
199 domelem *This = impl_from_IXMLDOMElement( iface );
201 TRACE("(%p)->(%p)\n", This, p);
203 return node_get_nodeName(&This->node, p);
206 static HRESULT WINAPI domelem_get_nodeValue(
207 IXMLDOMElement *iface,
210 domelem *This = impl_from_IXMLDOMElement( iface );
212 TRACE("(%p)->(%p)\n", This, value);
217 V_VT(value) = VT_NULL;
218 V_BSTR(value) = NULL; /* tests show that we should do this */
222 static HRESULT WINAPI domelem_put_nodeValue(
223 IXMLDOMElement *iface,
226 domelem *This = impl_from_IXMLDOMElement( iface );
227 TRACE("(%p)->(v%d)\n", This, V_VT(&value));
231 static HRESULT WINAPI domelem_get_nodeType(
232 IXMLDOMElement *iface,
233 DOMNodeType* domNodeType )
235 domelem *This = impl_from_IXMLDOMElement( iface );
237 TRACE("(%p)->(%p)\n", This, domNodeType);
239 *domNodeType = NODE_ELEMENT;
243 static HRESULT WINAPI domelem_get_parentNode(
244 IXMLDOMElement *iface,
245 IXMLDOMNode** parent )
247 domelem *This = impl_from_IXMLDOMElement( iface );
249 TRACE("(%p)->(%p)\n", This, parent);
251 return node_get_parent(&This->node, parent);
254 static HRESULT WINAPI domelem_get_childNodes(
255 IXMLDOMElement *iface,
256 IXMLDOMNodeList** outList)
258 domelem *This = impl_from_IXMLDOMElement( iface );
260 TRACE("(%p)->(%p)\n", This, outList);
262 return node_get_child_nodes(&This->node, outList);
265 static HRESULT WINAPI domelem_get_firstChild(
266 IXMLDOMElement *iface,
267 IXMLDOMNode** domNode)
269 domelem *This = impl_from_IXMLDOMElement( iface );
271 TRACE("(%p)->(%p)\n", This, domNode);
273 return node_get_first_child(&This->node, domNode);
276 static HRESULT WINAPI domelem_get_lastChild(
277 IXMLDOMElement *iface,
278 IXMLDOMNode** domNode)
280 domelem *This = impl_from_IXMLDOMElement( iface );
282 TRACE("(%p)->(%p)\n", This, domNode);
284 return node_get_last_child(&This->node, domNode);
287 static HRESULT WINAPI domelem_get_previousSibling(
288 IXMLDOMElement *iface,
289 IXMLDOMNode** domNode)
291 domelem *This = impl_from_IXMLDOMElement( iface );
293 TRACE("(%p)->(%p)\n", This, domNode);
295 return node_get_previous_sibling(&This->node, domNode);
298 static HRESULT WINAPI domelem_get_nextSibling(
299 IXMLDOMElement *iface,
300 IXMLDOMNode** domNode)
302 domelem *This = impl_from_IXMLDOMElement( iface );
304 TRACE("(%p)->(%p)\n", This, domNode);
306 return node_get_next_sibling(&This->node, domNode);
309 static HRESULT WINAPI domelem_get_attributes(
310 IXMLDOMElement *iface,
311 IXMLDOMNamedNodeMap** attributeMap)
313 domelem *This = impl_from_IXMLDOMElement( iface );
315 TRACE("(%p)->(%p)\n", This, attributeMap);
317 *attributeMap = create_nodemap((IXMLDOMNode*)&This->IXMLDOMElement_iface);
321 static HRESULT WINAPI domelem_insertBefore(
322 IXMLDOMElement *iface,
323 IXMLDOMNode* newNode, VARIANT refChild,
324 IXMLDOMNode** outOldNode)
326 domelem *This = impl_from_IXMLDOMElement( iface );
328 TRACE("(%p)->(%p x%d %p)\n", This, newNode, V_VT(&refChild), outOldNode);
330 return node_insert_before(&This->node, newNode, &refChild, outOldNode);
333 static HRESULT WINAPI domelem_replaceChild(
334 IXMLDOMElement *iface,
335 IXMLDOMNode* newNode,
336 IXMLDOMNode* oldNode,
337 IXMLDOMNode** outOldNode)
339 domelem *This = impl_from_IXMLDOMElement( iface );
341 TRACE("(%p)->(%p %p %p)\n", This, newNode, oldNode, outOldNode);
343 return node_replace_child(&This->node, newNode, oldNode, outOldNode);
346 static HRESULT WINAPI domelem_removeChild(
347 IXMLDOMElement *iface,
348 IXMLDOMNode* domNode, IXMLDOMNode** oldNode)
350 domelem *This = impl_from_IXMLDOMElement( iface );
351 return IXMLDOMNode_removeChild( IXMLDOMNode_from_impl(&This->node), domNode, oldNode );
354 static HRESULT WINAPI domelem_appendChild(
355 IXMLDOMElement *iface,
356 IXMLDOMNode* newNode, IXMLDOMNode** outNewNode)
358 domelem *This = impl_from_IXMLDOMElement( iface );
359 return IXMLDOMNode_appendChild( IXMLDOMNode_from_impl(&This->node), newNode, outNewNode );
362 static HRESULT WINAPI domelem_hasChildNodes(
363 IXMLDOMElement *iface,
366 domelem *This = impl_from_IXMLDOMElement( iface );
367 return IXMLDOMNode_hasChildNodes( IXMLDOMNode_from_impl(&This->node), pbool );
370 static HRESULT WINAPI domelem_get_ownerDocument(
371 IXMLDOMElement *iface,
372 IXMLDOMDocument** domDocument)
374 domelem *This = impl_from_IXMLDOMElement( iface );
375 return IXMLDOMNode_get_ownerDocument( IXMLDOMNode_from_impl(&This->node), domDocument );
378 static HRESULT WINAPI domelem_cloneNode(
379 IXMLDOMElement *iface,
380 VARIANT_BOOL deep, IXMLDOMNode** outNode)
382 domelem *This = impl_from_IXMLDOMElement( iface );
383 TRACE("(%p)->(%d %p)\n", This, deep, outNode);
384 return node_clone( &This->node, deep, outNode );
387 static HRESULT WINAPI domelem_get_nodeTypeString(
388 IXMLDOMElement *iface,
391 domelem *This = impl_from_IXMLDOMElement( iface );
392 static const WCHAR elementW[] = {'e','l','e','m','e','n','t',0};
394 TRACE("(%p)->(%p)\n", This, p);
396 return return_bstr(elementW, p);
399 static HRESULT WINAPI domelem_get_text(
400 IXMLDOMElement *iface,
403 domelem *This = impl_from_IXMLDOMElement( iface );
404 return IXMLDOMNode_get_text( IXMLDOMNode_from_impl(&This->node), p );
407 static HRESULT WINAPI domelem_put_text(
408 IXMLDOMElement *iface,
411 domelem *This = impl_from_IXMLDOMElement( iface );
412 TRACE("(%p)->(%s)\n", This, debugstr_w(p));
413 return node_put_text( &This->node, p );
416 static HRESULT WINAPI domelem_get_specified(
417 IXMLDOMElement *iface,
418 VARIANT_BOOL* isSpecified)
420 domelem *This = impl_from_IXMLDOMElement( iface );
421 FIXME("(%p)->(%p) stub!\n", This, isSpecified);
422 *isSpecified = VARIANT_TRUE;
426 static HRESULT WINAPI domelem_get_definition(
427 IXMLDOMElement *iface,
428 IXMLDOMNode** definitionNode)
430 domelem *This = impl_from_IXMLDOMElement( iface );
431 FIXME("(%p)->(%p)\n", This, definitionNode);
435 static inline BYTE hex_to_byte(xmlChar c)
437 if(c <= '9') return c-'0';
438 if(c <= 'F') return c-'A'+10;
442 static inline BYTE base64_to_byte(xmlChar c)
444 if(c == '+') return 62;
445 if(c == '/') return 63;
446 if(c <= '9') return c-'0'+52;
447 if(c <= 'Z') return c-'A';
451 static inline HRESULT VARIANT_from_DT(XDR_DT dt, xmlChar* str, VARIANT* v)
455 BOOL handled = FALSE;
470 V_BSTR(v) = bstr_from_xmlChar(str);
473 return E_OUTOFMEMORY;
491 st.wDayOfWeek = st.wHour = st.wMinute = st.wSecond = st.wMilliseconds = 0;
493 V_VT(&src) = VT_BSTR;
494 V_BSTR(&src) = bstr_from_xmlChar(str);
497 return E_OUTOFMEMORY;
500 e = p + SysStringLen(V_BSTR(&src));
502 if(p+4<e && *(p+4)=='-') /* parse date (yyyy-mm-dd) */
505 st.wMonth = atoiW(p+5);
506 st.wDay = atoiW(p+8);
512 if(p+2<e && *(p+2)==':') /* parse time (hh:mm:ss.?) */
515 st.wMinute = atoiW(p+3);
516 st.wSecond = atoiW(p+6);
522 while(isdigitW(*p)) p++;
526 SystemTimeToVariantTime(&st, &date);
530 if(*p == '+') /* parse timezone offset (+hh:mm) */
531 V_DATE(v) += (DOUBLE)atoiW(p+1)/24 + (DOUBLE)atoiW(p+4)/1440;
532 else if(*p == '-') /* parse timezone offset (-hh:mm) */
533 V_DATE(v) -= (DOUBLE)atoiW(p+1)/24 + (DOUBLE)atoiW(p+4)/1440;
544 len = xmlStrlen(str)/2;
548 V_VT(v) = (VT_ARRAY|VT_UI1);
549 V_ARRAY(v) = SafeArrayCreate(VT_UI1, 1, &sab);
552 return E_OUTOFMEMORY;
555 ((BYTE*)V_ARRAY(v)->pvData)[i] = (hex_to_byte(str[2*i])<<4)
556 + hex_to_byte(str[2*i+1]);
565 len = xmlStrlen(str);
566 if(str[len-2] == '=') i = 2;
567 else if(str[len-1] == '=') i = 1;
571 sab.cElements = len/4*3-i;
573 V_VT(v) = (VT_ARRAY|VT_UI1);
574 V_ARRAY(v) = SafeArrayCreate(VT_UI1, 1, &sab);
577 return E_OUTOFMEMORY;
579 for(i=0; i<len/4; i++)
581 ((BYTE*)V_ARRAY(v)->pvData)[3*i] = (base64_to_byte(str[4*i])<<2)
582 + (base64_to_byte(str[4*i+1])>>4);
583 if(3*i+1 < sab.cElements)
584 ((BYTE*)V_ARRAY(v)->pvData)[3*i+1] = (base64_to_byte(str[4*i+1])<<4)
585 + (base64_to_byte(str[4*i+2])>>2);
586 if(3*i+2 < sab.cElements)
587 ((BYTE*)V_ARRAY(v)->pvData)[3*i+2] = (base64_to_byte(str[4*i+2])<<6)
588 + base64_to_byte(str[4*i+3]);
639 FIXME("need to handle dt:%s\n", dt_to_str(dt));
641 V_BSTR(v) = bstr_from_xmlChar(str);
643 return E_OUTOFMEMORY;
650 V_VT(&src) = VT_BSTR;
651 V_BSTR(&src) = bstr_from_xmlChar(str);
654 return E_OUTOFMEMORY;
656 hr = VariantChangeTypeEx(v, &src,
657 MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT),0, V_VT(v));
663 static HRESULT WINAPI domelem_get_nodeTypedValue(
664 IXMLDOMElement *iface,
667 domelem *This = impl_from_IXMLDOMElement( iface );
672 TRACE("(%p)->(%p)\n", This, var1);
677 V_VT(var1) = VT_NULL;
679 dt = element_get_dt(get_element(This));
680 content = xmlNodeGetContent(get_element(This));
681 hr = VARIANT_from_DT(dt, content, var1);
687 static HRESULT WINAPI domelem_put_nodeTypedValue(
688 IXMLDOMElement *iface,
691 domelem *This = impl_from_IXMLDOMElement( iface );
695 TRACE("(%p)\n", This);
697 /* for untyped node coerce to BSTR and set */
698 if (IXMLDOMElement_get_dataType(iface, &type) == S_FALSE)
700 if (V_VT(&value) != VT_BSTR)
702 hr = VariantChangeType(&value, &value, 0, VT_BSTR);
705 hr = node_set_content(&This->node, V_BSTR(&value));
706 VariantClear(&value);
710 hr = node_set_content(&This->node, V_BSTR(&value));
714 FIXME("not implemented for typed nodes. type %s\n", debugstr_w(V_BSTR(&value)));
722 XDR_DT element_get_dt(xmlNodePtr node)
724 XDR_DT dt = DT_INVALID;
726 TRACE("(%p)\n", node);
727 if(node->type != XML_ELEMENT_NODE)
729 FIXME("invalid element node\n");
733 if (node->ns && xmlStrEqual(node->ns->href, DT_nsURI))
735 dt = str_to_dt(node->name, -1);
739 xmlChar* pVal = xmlGetNsProp(node, BAD_CAST "dt", DT_nsURI);
742 dt = str_to_dt(pVal, -1);
747 IXMLDOMDocument3* doc = (IXMLDOMDocument3*)create_domdoc((xmlNodePtr)node->doc);
753 if (IXMLDOMDocument3_get_schemas(doc, &v) == S_OK &&
754 V_VT(&v) == VT_DISPATCH)
756 dt = SchemaCache_get_node_dt((IXMLDOMSchemaCollection2*)V_DISPATCH(&v), node);
759 IXMLDOMDocument3_Release(doc);
764 TRACE("=> dt:%s\n", dt_to_str(dt));
768 static HRESULT WINAPI domelem_get_dataType(
769 IXMLDOMElement *iface,
772 domelem *This = impl_from_IXMLDOMElement( iface );
775 TRACE("(%p)->(%p)\n", This, typename);
780 dt = element_get_dt(get_element(This));
809 V_VT(typename) = VT_BSTR;
810 V_BSTR(typename) = SysAllocString(dt_to_bstr(dt));
812 if (!V_BSTR(typename))
813 return E_OUTOFMEMORY;
816 /* Other types (DTD equivalents) do not return anything here,
817 * but the pointer part of the VARIANT is set to NULL */
818 V_VT(typename) = VT_NULL;
819 V_BSTR(typename) = NULL;
822 return (V_VT(typename) != VT_NULL) ? S_OK : S_FALSE;
825 static HRESULT WINAPI domelem_put_dataType(
826 IXMLDOMElement *iface,
829 domelem *This = impl_from_IXMLDOMElement( iface );
834 TRACE("(%p)->(%s)\n", This, debugstr_w(dtName));
839 dt = bstr_to_dt(dtName, -1);
841 /* An example of this is. The Text in the node needs to be a 0 or 1 for a boolean type.
842 This applies to changing types (string->bool) or setting a new one
844 str = xmlNodeGetContent(get_element(This));
845 hr = dt_validate(dt, str);
848 /* Check all supported types. */
883 xmlAttrPtr attr = xmlHasNsProp(get_element(This), DT_prefix, DT_nsURI);
886 attr = xmlSetNsProp(get_element(This), attr->ns, DT_prefix, dt_to_str(dt));
891 xmlNsPtr ns = xmlNewNs(get_element(This), DT_nsURI, DT_prefix);
894 attr = xmlNewNsProp(get_element(This), ns, DT_prefix, dt_to_str(dt));
897 xmlAddChild(get_element(This), (xmlNodePtr)attr);
901 ERR("Failed to create Attribute\n");
904 ERR("Failed to create Namespace\n");
909 FIXME("need to handle dt:%s\n", dt_to_str(dt));
917 static HRESULT WINAPI domelem_get_xml(
918 IXMLDOMElement *iface,
921 domelem *This = impl_from_IXMLDOMElement( iface );
923 TRACE("(%p)->(%p)\n", This, p);
925 return node_get_xml(&This->node, TRUE, FALSE, p);
928 static HRESULT WINAPI domelem_transformNode(
929 IXMLDOMElement *iface,
930 IXMLDOMNode* domNode, BSTR* p)
932 domelem *This = impl_from_IXMLDOMElement( iface );
933 return IXMLDOMNode_transformNode( IXMLDOMNode_from_impl(&This->node), domNode, p );
936 static HRESULT WINAPI domelem_selectNodes(
937 IXMLDOMElement *iface,
938 BSTR p, IXMLDOMNodeList** outList)
940 domelem *This = impl_from_IXMLDOMElement( iface );
941 return IXMLDOMNode_selectNodes( IXMLDOMNode_from_impl(&This->node), p, outList );
944 static HRESULT WINAPI domelem_selectSingleNode(
945 IXMLDOMElement *iface,
946 BSTR p, IXMLDOMNode** outNode)
948 domelem *This = impl_from_IXMLDOMElement( iface );
949 return IXMLDOMNode_selectSingleNode( IXMLDOMNode_from_impl(&This->node), p, outNode );
952 static HRESULT WINAPI domelem_get_parsed(
953 IXMLDOMElement *iface,
954 VARIANT_BOOL* isParsed)
956 domelem *This = impl_from_IXMLDOMElement( iface );
957 FIXME("(%p)->(%p) stub!\n", This, isParsed);
958 *isParsed = VARIANT_TRUE;
962 static HRESULT WINAPI domelem_get_namespaceURI(
963 IXMLDOMElement *iface,
966 domelem *This = impl_from_IXMLDOMElement( iface );
967 return IXMLDOMNode_get_namespaceURI( IXMLDOMNode_from_impl(&This->node), p );
970 static HRESULT WINAPI domelem_get_prefix(
971 IXMLDOMElement *iface,
974 domelem *This = impl_from_IXMLDOMElement( iface );
975 TRACE("(%p)->(%p)\n", This, prefix);
976 return node_get_prefix( &This->node, prefix );
979 static HRESULT WINAPI domelem_get_baseName(
980 IXMLDOMElement *iface,
983 domelem *This = impl_from_IXMLDOMElement( iface );
984 TRACE("(%p)->(%p)\n", This, name);
985 return node_get_base_name( &This->node, name );
988 static HRESULT WINAPI domelem_transformNodeToObject(
989 IXMLDOMElement *iface,
990 IXMLDOMNode* domNode, VARIANT var1)
992 domelem *This = impl_from_IXMLDOMElement( iface );
993 return IXMLDOMNode_transformNodeToObject( IXMLDOMNode_from_impl(&This->node), domNode, var1 );
996 static HRESULT WINAPI domelem_get_tagName(
997 IXMLDOMElement *iface,
1000 domelem *This = impl_from_IXMLDOMElement( iface );
1002 const xmlChar *prefix;
1005 TRACE("(%p)->(%p)\n", This, p );
1007 if (!p) return E_INVALIDARG;
1009 element = get_element( This );
1013 prefix = element->ns ? element->ns->prefix : NULL;
1014 qname = xmlBuildQName(element->name, prefix, NULL, 0);
1016 *p = bstr_from_xmlChar(qname);
1017 if (qname != element->name) xmlFree(qname);
1019 return *p ? S_OK : E_OUTOFMEMORY;
1022 static HRESULT WINAPI domelem_getAttribute(
1023 IXMLDOMElement *iface,
1024 BSTR name, VARIANT* value)
1026 domelem *This = impl_from_IXMLDOMElement( iface );
1028 xmlChar *xml_name, *xml_value = NULL;
1029 HRESULT hr = S_FALSE;
1031 TRACE("(%p)->(%s %p)\n", This, debugstr_w(name), value);
1034 return E_INVALIDARG;
1036 element = get_element( This );
1040 V_BSTR(value) = NULL;
1041 V_VT(value) = VT_NULL;
1043 xml_name = xmlChar_from_wchar( name );
1045 if(!xmlValidateNameValue(xml_name))
1048 xml_value = xmlGetNsProp(element, xml_name, NULL);
1050 heap_free(xml_name);
1053 V_VT(value) = VT_BSTR;
1054 V_BSTR(value) = bstr_from_xmlChar( xml_value );
1062 static HRESULT WINAPI domelem_setAttribute(
1063 IXMLDOMElement *iface,
1064 BSTR name, VARIANT value)
1066 domelem *This = impl_from_IXMLDOMElement( iface );
1068 xmlChar *xml_name, *xml_value;
1072 TRACE("(%p)->(%s var)\n", This, debugstr_w(name));
1074 element = get_element( This );
1079 hr = VariantChangeType(&var, &value, 0, VT_BSTR);
1082 FIXME("VariantChangeType failed\n");
1086 xml_name = xmlChar_from_wchar( name );
1087 xml_value = xmlChar_from_wchar( V_BSTR(&var) );
1089 if(!xmlSetNsProp(element, NULL, xml_name, xml_value))
1092 heap_free(xml_value);
1093 heap_free(xml_name);
1099 static HRESULT WINAPI domelem_removeAttribute(
1100 IXMLDOMElement *iface,
1103 domelem *This = impl_from_IXMLDOMElement( iface );
1104 IXMLDOMNamedNodeMap *attr;
1107 TRACE("(%p)->(%s)\n", This, debugstr_w(p));
1109 hr = IXMLDOMElement_get_attributes(iface, &attr);
1110 if (hr != S_OK) return hr;
1112 hr = IXMLDOMNamedNodeMap_removeNamedItem(attr, p, NULL);
1113 IXMLDOMNamedNodeMap_Release(attr);
1118 static HRESULT WINAPI domelem_getAttributeNode(
1119 IXMLDOMElement *iface,
1120 BSTR p, IXMLDOMAttribute** attributeNode )
1122 domelem *This = impl_from_IXMLDOMElement( iface );
1127 HRESULT hr = S_FALSE;
1129 TRACE("(%p)->(%s %p)\n", This, debugstr_w(p), attributeNode);
1134 *attributeNode = NULL;
1136 element = get_element( This );
1140 xml_name = xmlChar_from_wchar(p);
1142 if(!xmlValidateNameValue(xml_name))
1144 heap_free(xml_name);
1148 attr = xmlHasProp(element, xml_name);
1150 unk = create_attribute((xmlNodePtr)attr);
1151 hr = IUnknown_QueryInterface(unk, &IID_IXMLDOMAttribute, (void**)attributeNode);
1152 IUnknown_Release(unk);
1155 heap_free(xml_name);
1160 static HRESULT WINAPI domelem_setAttributeNode(
1161 IXMLDOMElement *iface,
1162 IXMLDOMAttribute* attribute,
1163 IXMLDOMAttribute** old)
1165 domelem *This = impl_from_IXMLDOMElement( iface );
1166 xmlChar *name, *value;
1172 FIXME("(%p)->(%p %p): semi-stub\n", This, attribute, old);
1174 if (!attribute) return E_INVALIDARG;
1176 if (old) *old = NULL;
1178 hr = IXMLDOMAttribute_get_nodeName(attribute, &nameW);
1179 if (hr != S_OK) return hr;
1181 hr = IXMLDOMAttribute_get_nodeValue(attribute, &valueW);
1184 SysFreeString(nameW);
1188 TRACE("attribute: %s=%s\n", debugstr_w(nameW), debugstr_w(V_BSTR(&valueW)));
1190 hr = IXMLDOMAttribute_get_prefix(attribute, &prefix);
1193 FIXME("namespaces not supported: %s\n", debugstr_w(prefix));
1194 SysFreeString(prefix);
1197 name = xmlChar_from_wchar(nameW);
1198 value = xmlChar_from_wchar(V_BSTR(&valueW));
1200 if (!name || !value)
1202 SysFreeString(nameW);
1203 VariantClear(&valueW);
1206 return E_OUTOFMEMORY;
1209 attr = xmlSetNsProp(get_element(This), NULL, name, value);
1211 SysFreeString(nameW);
1212 VariantClear(&valueW);
1216 return attr ? S_OK : E_FAIL;
1219 static HRESULT WINAPI domelem_removeAttributeNode(
1220 IXMLDOMElement *iface,
1221 IXMLDOMAttribute* domAttribute,
1222 IXMLDOMAttribute** attributeNode)
1224 domelem *This = impl_from_IXMLDOMElement( iface );
1225 FIXME("(%p)->(%p %p)\n", This, domAttribute, attributeNode);
1229 static HRESULT WINAPI domelem_getElementsByTagName(
1230 IXMLDOMElement *iface,
1231 BSTR tagName, IXMLDOMNodeList** resultList)
1233 domelem *This = impl_from_IXMLDOMElement( iface );
1238 TRACE("(%p)->(%s, %p)\n", This, debugstr_w(tagName), resultList);
1240 if (!tagName || !resultList) return E_INVALIDARG;
1242 XPath = is_xpathmode(get_element(This)->doc);
1243 set_xpathmode(get_element(This)->doc, TRUE);
1244 query = tagName_to_XPath(tagName);
1245 hr = queryresult_create(get_element(This), query, resultList);
1247 set_xpathmode(get_element(This)->doc, XPath);
1252 static HRESULT WINAPI domelem_normalize(
1253 IXMLDOMElement *iface )
1255 domelem *This = impl_from_IXMLDOMElement( iface );
1256 FIXME("%p\n", This);
1260 static const struct IXMLDOMElementVtbl domelem_vtbl =
1262 domelem_QueryInterface,
1265 domelem_GetTypeInfoCount,
1266 domelem_GetTypeInfo,
1267 domelem_GetIDsOfNames,
1269 domelem_get_nodeName,
1270 domelem_get_nodeValue,
1271 domelem_put_nodeValue,
1272 domelem_get_nodeType,
1273 domelem_get_parentNode,
1274 domelem_get_childNodes,
1275 domelem_get_firstChild,
1276 domelem_get_lastChild,
1277 domelem_get_previousSibling,
1278 domelem_get_nextSibling,
1279 domelem_get_attributes,
1280 domelem_insertBefore,
1281 domelem_replaceChild,
1282 domelem_removeChild,
1283 domelem_appendChild,
1284 domelem_hasChildNodes,
1285 domelem_get_ownerDocument,
1287 domelem_get_nodeTypeString,
1290 domelem_get_specified,
1291 domelem_get_definition,
1292 domelem_get_nodeTypedValue,
1293 domelem_put_nodeTypedValue,
1294 domelem_get_dataType,
1295 domelem_put_dataType,
1297 domelem_transformNode,
1298 domelem_selectNodes,
1299 domelem_selectSingleNode,
1301 domelem_get_namespaceURI,
1303 domelem_get_baseName,
1304 domelem_transformNodeToObject,
1305 domelem_get_tagName,
1306 domelem_getAttribute,
1307 domelem_setAttribute,
1308 domelem_removeAttribute,
1309 domelem_getAttributeNode,
1310 domelem_setAttributeNode,
1311 domelem_removeAttributeNode,
1312 domelem_getElementsByTagName,
1316 static const tid_t domelem_iface_tids[] = {
1321 static dispex_static_data_t domelem_dispex = {
1328 IUnknown* create_element( xmlNodePtr element )
1332 This = heap_alloc( sizeof *This );
1336 This->IXMLDOMElement_iface.lpVtbl = &domelem_vtbl;
1339 init_xmlnode(&This->node, element, (IXMLDOMNode*)&This->IXMLDOMElement_iface, &domelem_dispex);
1341 return (IUnknown*)&This->IXMLDOMElement_iface;