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
27 # include <libxml/parser.h>
28 # include <libxml/xmlerror.h>
38 #include "msxml_private.h"
40 #include "wine/debug.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
46 static const xmlChar DT_prefix[] = "dt";
47 static const xmlChar DT_nsURI[] = "urn:schemas-microsoft-com:datatypes";
49 typedef struct _domelem
52 IXMLDOMElement IXMLDOMElement_iface;
56 static inline domelem *impl_from_IXMLDOMElement( IXMLDOMElement *iface )
58 return CONTAINING_RECORD(iface, domelem, IXMLDOMElement_iface);
61 static inline xmlNodePtr get_element( const domelem *This )
63 return This->node.node;
66 static HRESULT WINAPI domelem_QueryInterface(
67 IXMLDOMElement *iface,
71 domelem *This = impl_from_IXMLDOMElement( iface );
73 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
75 if ( IsEqualGUID( riid, &IID_IXMLDOMElement ) ||
76 IsEqualGUID( riid, &IID_IXMLDOMNode ) ||
77 IsEqualGUID( riid, &IID_IDispatch ) ||
78 IsEqualGUID( riid, &IID_IUnknown ) )
80 *ppvObject = &This->IXMLDOMElement_iface;
82 else if(node_query_interface(&This->node, riid, ppvObject))
84 return *ppvObject ? S_OK : E_NOINTERFACE;
88 TRACE("interface %s not implemented\n", debugstr_guid(riid));
93 IUnknown_AddRef( (IUnknown*)*ppvObject );
97 static ULONG WINAPI domelem_AddRef(
98 IXMLDOMElement *iface )
100 domelem *This = impl_from_IXMLDOMElement( iface );
101 LONG ref = InterlockedIncrement(&This->ref);
103 TRACE("(%p)->(%d)\n", This, ref);
108 static ULONG WINAPI domelem_Release(
109 IXMLDOMElement *iface )
111 domelem *This = impl_from_IXMLDOMElement( iface );
112 ULONG ref = InterlockedDecrement(&This->ref);
114 TRACE("(%p)->(%d)\n", This, ref);
117 destroy_xmlnode(&This->node);
124 static HRESULT WINAPI domelem_GetTypeInfoCount(
125 IXMLDOMElement *iface,
128 domelem *This = impl_from_IXMLDOMElement( iface );
130 TRACE("(%p)->(%p)\n", This, pctinfo);
137 static HRESULT WINAPI domelem_GetTypeInfo(
138 IXMLDOMElement *iface,
139 UINT iTInfo, LCID lcid,
140 ITypeInfo** ppTInfo )
142 domelem *This = impl_from_IXMLDOMElement( iface );
145 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
147 hr = get_typeinfo(IXMLDOMElement_tid, ppTInfo);
152 static HRESULT WINAPI domelem_GetIDsOfNames(
153 IXMLDOMElement *iface,
154 REFIID riid, LPOLESTR* rgszNames,
155 UINT cNames, LCID lcid, DISPID* rgDispId )
157 domelem *This = impl_from_IXMLDOMElement( iface );
161 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
164 if(!rgszNames || cNames == 0 || !rgDispId)
167 hr = get_typeinfo(IXMLDOMElement_tid, &typeinfo);
170 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
171 ITypeInfo_Release(typeinfo);
177 static HRESULT WINAPI domelem_Invoke(
178 IXMLDOMElement *iface,
179 DISPID dispIdMember, REFIID riid, LCID lcid,
180 WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
181 EXCEPINFO* pExcepInfo, UINT* puArgErr )
183 domelem *This = impl_from_IXMLDOMElement( iface );
187 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
188 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
190 hr = get_typeinfo(IXMLDOMElement_tid, &typeinfo);
193 hr = ITypeInfo_Invoke(typeinfo, &This->IXMLDOMElement_iface, dispIdMember, wFlags,
194 pDispParams, pVarResult, pExcepInfo, puArgErr);
195 ITypeInfo_Release(typeinfo);
201 static HRESULT WINAPI domelem_get_nodeName(
202 IXMLDOMElement *iface,
205 domelem *This = impl_from_IXMLDOMElement( iface );
207 TRACE("(%p)->(%p)\n", This, p);
209 return node_get_nodeName(&This->node, p);
212 static HRESULT WINAPI domelem_get_nodeValue(
213 IXMLDOMElement *iface,
216 domelem *This = impl_from_IXMLDOMElement( iface );
218 TRACE("(%p)->(%p)\n", This, value);
223 V_VT(value) = VT_NULL;
224 V_BSTR(value) = NULL; /* tests show that we should do this */
228 static HRESULT WINAPI domelem_put_nodeValue(
229 IXMLDOMElement *iface,
232 domelem *This = impl_from_IXMLDOMElement( iface );
233 TRACE("(%p)->(%s)\n", This, debugstr_variant(&value));
237 static HRESULT WINAPI domelem_get_nodeType(
238 IXMLDOMElement *iface,
239 DOMNodeType* domNodeType )
241 domelem *This = impl_from_IXMLDOMElement( iface );
243 TRACE("(%p)->(%p)\n", This, domNodeType);
245 *domNodeType = NODE_ELEMENT;
249 static HRESULT WINAPI domelem_get_parentNode(
250 IXMLDOMElement *iface,
251 IXMLDOMNode** parent )
253 domelem *This = impl_from_IXMLDOMElement( iface );
255 TRACE("(%p)->(%p)\n", This, parent);
257 return node_get_parent(&This->node, parent);
260 static HRESULT WINAPI domelem_get_childNodes(
261 IXMLDOMElement *iface,
262 IXMLDOMNodeList** outList)
264 domelem *This = impl_from_IXMLDOMElement( iface );
266 TRACE("(%p)->(%p)\n", This, outList);
268 return node_get_child_nodes(&This->node, outList);
271 static HRESULT WINAPI domelem_get_firstChild(
272 IXMLDOMElement *iface,
273 IXMLDOMNode** domNode)
275 domelem *This = impl_from_IXMLDOMElement( iface );
277 TRACE("(%p)->(%p)\n", This, domNode);
279 return node_get_first_child(&This->node, domNode);
282 static HRESULT WINAPI domelem_get_lastChild(
283 IXMLDOMElement *iface,
284 IXMLDOMNode** domNode)
286 domelem *This = impl_from_IXMLDOMElement( iface );
288 TRACE("(%p)->(%p)\n", This, domNode);
290 return node_get_last_child(&This->node, domNode);
293 static HRESULT WINAPI domelem_get_previousSibling(
294 IXMLDOMElement *iface,
295 IXMLDOMNode** domNode)
297 domelem *This = impl_from_IXMLDOMElement( iface );
299 TRACE("(%p)->(%p)\n", This, domNode);
301 return node_get_previous_sibling(&This->node, domNode);
304 static HRESULT WINAPI domelem_get_nextSibling(
305 IXMLDOMElement *iface,
306 IXMLDOMNode** domNode)
308 domelem *This = impl_from_IXMLDOMElement( iface );
310 TRACE("(%p)->(%p)\n", This, domNode);
312 return node_get_next_sibling(&This->node, domNode);
315 static HRESULT WINAPI domelem_get_attributes(
316 IXMLDOMElement *iface,
317 IXMLDOMNamedNodeMap** map)
319 domelem *This = impl_from_IXMLDOMElement( iface );
321 TRACE("(%p)->(%p)\n", This, map);
323 *map = create_nodemap(This->node.node);
327 static HRESULT WINAPI domelem_insertBefore(
328 IXMLDOMElement *iface,
329 IXMLDOMNode* newNode, VARIANT refChild,
330 IXMLDOMNode** outOldNode)
332 domelem *This = impl_from_IXMLDOMElement( iface );
334 TRACE("(%p)->(%p %s %p)\n", This, newNode, debugstr_variant(&refChild), outOldNode);
336 return node_insert_before(&This->node, newNode, &refChild, outOldNode);
339 static HRESULT WINAPI domelem_replaceChild(
340 IXMLDOMElement *iface,
341 IXMLDOMNode* newNode,
342 IXMLDOMNode* oldNode,
343 IXMLDOMNode** outOldNode)
345 domelem *This = impl_from_IXMLDOMElement( iface );
347 TRACE("(%p)->(%p %p %p)\n", This, newNode, oldNode, outOldNode);
349 return node_replace_child(&This->node, newNode, oldNode, outOldNode);
352 static HRESULT WINAPI domelem_removeChild(
353 IXMLDOMElement *iface,
354 IXMLDOMNode *child, IXMLDOMNode **oldChild)
356 domelem *This = impl_from_IXMLDOMElement( iface );
357 TRACE("(%p)->(%p %p)\n", This, child, oldChild);
358 return node_remove_child(&This->node, child, oldChild);
361 static HRESULT WINAPI domelem_appendChild(
362 IXMLDOMElement *iface,
363 IXMLDOMNode *child, IXMLDOMNode **outChild)
365 domelem *This = impl_from_IXMLDOMElement( iface );
366 TRACE("(%p)->(%p %p)\n", This, child, outChild);
367 return node_append_child(&This->node, child, outChild);
370 static HRESULT WINAPI domelem_hasChildNodes(
371 IXMLDOMElement *iface,
374 domelem *This = impl_from_IXMLDOMElement( iface );
375 TRACE("(%p)->(%p)\n", This, ret);
376 return node_has_childnodes(&This->node, ret);
379 static HRESULT WINAPI domelem_get_ownerDocument(
380 IXMLDOMElement *iface,
381 IXMLDOMDocument **doc)
383 domelem *This = impl_from_IXMLDOMElement( iface );
384 TRACE("(%p)->(%p)\n", This, doc);
385 return node_get_owner_doc(&This->node, doc);
388 static HRESULT WINAPI domelem_cloneNode(
389 IXMLDOMElement *iface,
390 VARIANT_BOOL deep, IXMLDOMNode** outNode)
392 domelem *This = impl_from_IXMLDOMElement( iface );
393 TRACE("(%p)->(%d %p)\n", This, deep, outNode);
394 return node_clone( &This->node, deep, outNode );
397 static HRESULT WINAPI domelem_get_nodeTypeString(
398 IXMLDOMElement *iface,
401 domelem *This = impl_from_IXMLDOMElement( iface );
402 static const WCHAR elementW[] = {'e','l','e','m','e','n','t',0};
404 TRACE("(%p)->(%p)\n", This, p);
406 return return_bstr(elementW, p);
409 static HRESULT WINAPI domelem_get_text(
410 IXMLDOMElement *iface,
413 domelem *This = impl_from_IXMLDOMElement( iface );
414 TRACE("(%p)->(%p)\n", This, p);
415 return node_get_text(&This->node, p);
418 static HRESULT WINAPI domelem_put_text(
419 IXMLDOMElement *iface,
422 domelem *This = impl_from_IXMLDOMElement( iface );
423 TRACE("(%p)->(%s)\n", This, debugstr_w(p));
424 return node_put_text( &This->node, p );
427 static HRESULT WINAPI domelem_get_specified(
428 IXMLDOMElement *iface,
429 VARIANT_BOOL* isSpecified)
431 domelem *This = impl_from_IXMLDOMElement( iface );
432 FIXME("(%p)->(%p) stub!\n", This, isSpecified);
433 *isSpecified = VARIANT_TRUE;
437 static HRESULT WINAPI domelem_get_definition(
438 IXMLDOMElement *iface,
439 IXMLDOMNode** definitionNode)
441 domelem *This = impl_from_IXMLDOMElement( iface );
442 FIXME("(%p)->(%p)\n", This, definitionNode);
446 static inline BYTE hex_to_byte(xmlChar c)
448 if(c <= '9') return c-'0';
449 if(c <= 'F') return c-'A'+10;
453 static inline BYTE base64_to_byte(xmlChar c)
455 if(c == '+') return 62;
456 if(c == '/') return 63;
457 if(c <= '9') return c-'0'+52;
458 if(c <= 'Z') return c-'A';
462 static inline HRESULT variant_from_dt(XDR_DT dt, xmlChar* str, VARIANT* v)
466 BOOL handled = FALSE;
481 V_BSTR(v) = bstr_from_xmlChar(str);
484 return E_OUTOFMEMORY;
502 st.wDayOfWeek = st.wHour = st.wMinute = st.wSecond = st.wMilliseconds = 0;
504 V_VT(&src) = VT_BSTR;
505 V_BSTR(&src) = bstr_from_xmlChar(str);
508 return E_OUTOFMEMORY;
511 e = p + SysStringLen(V_BSTR(&src));
513 if(p+4<e && *(p+4)=='-') /* parse date (yyyy-mm-dd) */
516 st.wMonth = atoiW(p+5);
517 st.wDay = atoiW(p+8);
523 if(p+2<e && *(p+2)==':') /* parse time (hh:mm:ss.?) */
526 st.wMinute = atoiW(p+3);
527 st.wSecond = atoiW(p+6);
533 while(isdigitW(*p)) p++;
537 SystemTimeToVariantTime(&st, &date);
541 if(*p == '+') /* parse timezone offset (+hh:mm) */
542 V_DATE(v) += (DOUBLE)atoiW(p+1)/24 + (DOUBLE)atoiW(p+4)/1440;
543 else if(*p == '-') /* parse timezone offset (-hh:mm) */
544 V_DATE(v) -= (DOUBLE)atoiW(p+1)/24 + (DOUBLE)atoiW(p+4)/1440;
555 len = xmlStrlen(str)/2;
559 V_VT(v) = (VT_ARRAY|VT_UI1);
560 V_ARRAY(v) = SafeArrayCreate(VT_UI1, 1, &sab);
563 return E_OUTOFMEMORY;
566 ((BYTE*)V_ARRAY(v)->pvData)[i] = (hex_to_byte(str[2*i])<<4)
567 + hex_to_byte(str[2*i+1]);
577 /* remove all formatting chars */
582 if ( *c2 == ' ' || *c2 == '\t' ||
583 *c2 == '\n' || *c2 == '\r' )
593 if(str[len-2] == '=') i = 2;
594 else if(str[len-1] == '=') i = 1;
598 sab.cElements = len/4*3-i;
600 V_VT(v) = (VT_ARRAY|VT_UI1);
601 V_ARRAY(v) = SafeArrayCreate(VT_UI1, 1, &sab);
604 return E_OUTOFMEMORY;
606 for(i=0; i<len/4; i++)
608 ((BYTE*)V_ARRAY(v)->pvData)[3*i] = (base64_to_byte(str[4*i])<<2)
609 + (base64_to_byte(str[4*i+1])>>4);
610 if(3*i+1 < sab.cElements)
611 ((BYTE*)V_ARRAY(v)->pvData)[3*i+1] = (base64_to_byte(str[4*i+1])<<4)
612 + (base64_to_byte(str[4*i+2])>>2);
613 if(3*i+2 < sab.cElements)
614 ((BYTE*)V_ARRAY(v)->pvData)[3*i+2] = (base64_to_byte(str[4*i+2])<<6)
615 + base64_to_byte(str[4*i+3]);
666 FIXME("need to handle dt:%s\n", dt_to_str(dt));
668 V_BSTR(v) = bstr_from_xmlChar(str);
670 return E_OUTOFMEMORY;
677 V_VT(&src) = VT_BSTR;
678 V_BSTR(&src) = bstr_from_xmlChar(str);
681 return E_OUTOFMEMORY;
683 hr = VariantChangeTypeEx(v, &src,
684 MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT),0, V_VT(v));
690 static XDR_DT element_get_dt(xmlNodePtr node)
692 XDR_DT dt = DT_INVALID;
694 TRACE("(%p)\n", node);
695 if(node->type != XML_ELEMENT_NODE)
697 FIXME("invalid element node\n");
701 if (node->ns && xmlStrEqual(node->ns->href, DT_nsURI))
703 dt = str_to_dt(node->name, -1);
707 xmlChar* pVal = xmlGetNsProp(node, BAD_CAST "dt", DT_nsURI);
710 dt = str_to_dt(pVal, -1);
715 IXMLDOMDocument3* doc = (IXMLDOMDocument3*)create_domdoc((xmlNodePtr)node->doc);
721 if (IXMLDOMDocument3_get_schemas(doc, &v) == S_OK &&
722 V_VT(&v) == VT_DISPATCH)
724 dt = SchemaCache_get_node_dt((IXMLDOMSchemaCollection2*)V_DISPATCH(&v), node);
727 IXMLDOMDocument3_Release(doc);
732 TRACE("=> dt:%s\n", dt_to_str(dt));
736 static HRESULT WINAPI domelem_get_nodeTypedValue(
737 IXMLDOMElement *iface,
740 domelem *This = impl_from_IXMLDOMElement( iface );
745 TRACE("(%p)->(%p)\n", This, v);
747 if(!v) return E_INVALIDARG;
751 dt = element_get_dt(get_element(This));
752 content = xmlNodeGetContent(get_element(This));
753 hr = variant_from_dt(dt, content, v);
759 static HRESULT WINAPI domelem_put_nodeTypedValue(
760 IXMLDOMElement *iface,
763 domelem *This = impl_from_IXMLDOMElement( iface );
767 TRACE("(%p)->(%s)\n", This, debugstr_variant(&value));
769 dt = element_get_dt(get_element(This));
770 /* for untyped node coerce to BSTR and set */
771 if (dt == DT_INVALID)
773 if (V_VT(&value) != VT_BSTR)
776 VariantInit(&content);
777 hr = VariantChangeType(&content, &value, 0, VT_BSTR);
780 hr = node_set_content(&This->node, V_BSTR(&content));
781 VariantClear(&content);
785 hr = node_set_content(&This->node, V_BSTR(&value));
789 FIXME("not implemented for dt:%s\n", dt_to_str(dt));
796 static HRESULT WINAPI domelem_get_dataType(
797 IXMLDOMElement *iface,
800 domelem *This = impl_from_IXMLDOMElement( iface );
803 TRACE("(%p)->(%p)\n", This, typename);
808 dt = element_get_dt(get_element(This));
837 V_VT(typename) = VT_BSTR;
838 V_BSTR(typename) = SysAllocString(dt_to_bstr(dt));
840 if (!V_BSTR(typename))
841 return E_OUTOFMEMORY;
844 /* Other types (DTD equivalents) do not return anything here,
845 * but the pointer part of the VARIANT is set to NULL */
846 V_VT(typename) = VT_NULL;
847 V_BSTR(typename) = NULL;
850 return (V_VT(typename) != VT_NULL) ? S_OK : S_FALSE;
853 static HRESULT WINAPI domelem_put_dataType(
854 IXMLDOMElement *iface,
857 domelem *This = impl_from_IXMLDOMElement( iface );
862 TRACE("(%p)->(%s)\n", This, debugstr_w(dtName));
867 dt = bstr_to_dt(dtName, -1);
869 /* An example of this is. The Text in the node needs to be a 0 or 1 for a boolean type.
870 This applies to changing types (string->bool) or setting a new one
872 str = xmlNodeGetContent(get_element(This));
873 hr = dt_validate(dt, str);
876 /* Check all supported types. */
911 xmlAttrPtr attr = xmlHasNsProp(get_element(This), DT_prefix, DT_nsURI);
914 attr = xmlSetNsProp(get_element(This), attr->ns, DT_prefix, dt_to_str(dt));
919 xmlNsPtr ns = xmlNewNs(get_element(This), DT_nsURI, DT_prefix);
922 attr = xmlNewNsProp(get_element(This), ns, DT_prefix, dt_to_str(dt));
925 xmlAddChild(get_element(This), (xmlNodePtr)attr);
929 ERR("Failed to create Attribute\n");
932 ERR("Failed to create Namespace\n");
937 FIXME("need to handle dt:%s\n", dt_to_str(dt));
945 static HRESULT WINAPI domelem_get_xml(
946 IXMLDOMElement *iface,
949 domelem *This = impl_from_IXMLDOMElement( iface );
951 TRACE("(%p)->(%p)\n", This, p);
953 return node_get_xml(&This->node, TRUE, FALSE, p);
956 static HRESULT WINAPI domelem_transformNode(
957 IXMLDOMElement *iface,
958 IXMLDOMNode *node, BSTR *p)
960 domelem *This = impl_from_IXMLDOMElement( iface );
961 TRACE("(%p)->(%p %p)\n", This, node, p);
962 return node_transform_node(&This->node, node, p);
965 static HRESULT WINAPI domelem_selectNodes(
966 IXMLDOMElement *iface,
967 BSTR p, IXMLDOMNodeList** outList)
969 domelem *This = impl_from_IXMLDOMElement( iface );
970 TRACE("(%p)->(%s %p)\n", This, debugstr_w(p), outList);
971 return node_select_nodes(&This->node, p, outList);
974 static HRESULT WINAPI domelem_selectSingleNode(
975 IXMLDOMElement *iface,
976 BSTR p, IXMLDOMNode** outNode)
978 domelem *This = impl_from_IXMLDOMElement( iface );
979 TRACE("(%p)->(%s %p)\n", This, debugstr_w(p), outNode);
980 return node_select_singlenode(&This->node, p, outNode);
983 static HRESULT WINAPI domelem_get_parsed(
984 IXMLDOMElement *iface,
985 VARIANT_BOOL* isParsed)
987 domelem *This = impl_from_IXMLDOMElement( iface );
988 FIXME("(%p)->(%p) stub!\n", This, isParsed);
989 *isParsed = VARIANT_TRUE;
993 static HRESULT WINAPI domelem_get_namespaceURI(
994 IXMLDOMElement *iface,
997 domelem *This = impl_from_IXMLDOMElement( iface );
998 TRACE("(%p)->(%p)\n", This, p);
999 return node_get_namespaceURI(&This->node, p);
1002 static HRESULT WINAPI domelem_get_prefix(
1003 IXMLDOMElement *iface,
1006 domelem *This = impl_from_IXMLDOMElement( iface );
1007 TRACE("(%p)->(%p)\n", This, prefix);
1008 return node_get_prefix( &This->node, prefix );
1011 static HRESULT WINAPI domelem_get_baseName(
1012 IXMLDOMElement *iface,
1015 domelem *This = impl_from_IXMLDOMElement( iface );
1016 TRACE("(%p)->(%p)\n", This, name);
1017 return node_get_base_name( &This->node, name );
1020 static HRESULT WINAPI domelem_transformNodeToObject(
1021 IXMLDOMElement *iface,
1022 IXMLDOMNode* domNode, VARIANT var1)
1024 domelem *This = impl_from_IXMLDOMElement( iface );
1025 FIXME("(%p)->(%p %s)\n", This, domNode, debugstr_variant(&var1));
1029 static HRESULT WINAPI domelem_get_tagName(
1030 IXMLDOMElement *iface,
1033 domelem *This = impl_from_IXMLDOMElement( iface );
1035 const xmlChar *prefix;
1038 TRACE("(%p)->(%p)\n", This, p );
1040 if (!p) return E_INVALIDARG;
1042 element = get_element( This );
1046 prefix = element->ns ? element->ns->prefix : NULL;
1047 qname = xmlBuildQName(element->name, prefix, NULL, 0);
1049 *p = bstr_from_xmlChar(qname);
1050 if (qname != element->name) xmlFree(qname);
1052 return *p ? S_OK : E_OUTOFMEMORY;
1055 static HRESULT WINAPI domelem_getAttribute(
1056 IXMLDOMElement *iface,
1057 BSTR name, VARIANT* value)
1059 domelem *This = impl_from_IXMLDOMElement( iface );
1061 xmlChar *xml_name, *xml_value = NULL;
1062 HRESULT hr = S_FALSE;
1064 TRACE("(%p)->(%s %p)\n", This, debugstr_w(name), value);
1067 return E_INVALIDARG;
1069 element = get_element( This );
1073 V_BSTR(value) = NULL;
1074 V_VT(value) = VT_NULL;
1076 xml_name = xmlchar_from_wchar( name );
1078 if(!xmlValidateNameValue(xml_name))
1081 xml_value = xmlGetNsProp(element, xml_name, NULL);
1083 heap_free(xml_name);
1086 V_VT(value) = VT_BSTR;
1087 V_BSTR(value) = bstr_from_xmlChar( xml_value );
1095 static HRESULT WINAPI domelem_setAttribute(
1096 IXMLDOMElement *iface,
1097 BSTR name, VARIANT value)
1099 domelem *This = impl_from_IXMLDOMElement( iface );
1101 xmlChar *xml_name, *xml_value;
1105 TRACE("(%p)->(%s %s)\n", This, debugstr_w(name), debugstr_variant(&value));
1107 element = get_element( This );
1112 hr = VariantChangeType(&var, &value, 0, VT_BSTR);
1115 FIXME("VariantChangeType failed\n");
1119 xml_name = xmlchar_from_wchar( name );
1120 xml_value = xmlchar_from_wchar( V_BSTR(&var) );
1122 if(!xmlSetNsProp(element, NULL, xml_name, xml_value))
1125 heap_free(xml_value);
1126 heap_free(xml_name);
1132 static HRESULT WINAPI domelem_removeAttribute(
1133 IXMLDOMElement *iface,
1136 domelem *This = impl_from_IXMLDOMElement( iface );
1137 IXMLDOMNamedNodeMap *attr;
1140 TRACE("(%p)->(%s)\n", This, debugstr_w(p));
1142 hr = IXMLDOMElement_get_attributes(iface, &attr);
1143 if (hr != S_OK) return hr;
1145 hr = IXMLDOMNamedNodeMap_removeNamedItem(attr, p, NULL);
1146 IXMLDOMNamedNodeMap_Release(attr);
1151 static HRESULT WINAPI domelem_getAttributeNode(
1152 IXMLDOMElement *iface,
1153 BSTR p, IXMLDOMAttribute** attributeNode )
1155 domelem *This = impl_from_IXMLDOMElement( iface );
1160 HRESULT hr = S_FALSE;
1162 TRACE("(%p)->(%s %p)\n", This, debugstr_w(p), attributeNode);
1167 *attributeNode = NULL;
1169 element = get_element( This );
1173 xml_name = xmlchar_from_wchar(p);
1175 if(!xmlValidateNameValue(xml_name))
1177 heap_free(xml_name);
1181 attr = xmlHasProp(element, xml_name);
1183 unk = create_attribute((xmlNodePtr)attr);
1184 hr = IUnknown_QueryInterface(unk, &IID_IXMLDOMAttribute, (void**)attributeNode);
1185 IUnknown_Release(unk);
1188 heap_free(xml_name);
1193 static HRESULT WINAPI domelem_setAttributeNode(
1194 IXMLDOMElement *iface,
1195 IXMLDOMAttribute* attribute,
1196 IXMLDOMAttribute** old)
1198 domelem *This = impl_from_IXMLDOMElement( iface );
1199 static const WCHAR xmlnsW[] = {'x','m','l','n','s',0};
1200 xmlChar *name, *value;
1207 FIXME("(%p)->(%p %p): semi-stub\n", This, attribute, old);
1209 if (!attribute) return E_INVALIDARG;
1211 attr_node = get_node_obj((IXMLDOMNode*)attribute);
1212 if (!attr_node) return E_FAIL;
1214 if (attr_node->parent)
1216 WARN("attempt to add already used attribute\n");
1220 hr = IXMLDOMAttribute_get_nodeName(attribute, &nameW);
1221 if (hr != S_OK) return hr;
1223 /* adding xmlns attribute doesn't change a tree or existing namespace definition */
1224 if (!strcmpW(nameW, xmlnsW))
1226 SysFreeString(nameW);
1227 return DISP_E_UNKNOWNNAME;
1230 hr = IXMLDOMAttribute_get_nodeValue(attribute, &valueW);
1233 SysFreeString(nameW);
1237 if (old) *old = NULL;
1239 TRACE("attribute: %s=%s\n", debugstr_w(nameW), debugstr_w(V_BSTR(&valueW)));
1241 hr = IXMLDOMAttribute_get_prefix(attribute, &prefix);
1244 FIXME("namespaces not supported: %s\n", debugstr_w(prefix));
1245 SysFreeString(prefix);
1248 name = xmlchar_from_wchar(nameW);
1249 value = xmlchar_from_wchar(V_BSTR(&valueW));
1251 if (!name || !value)
1253 SysFreeString(nameW);
1254 VariantClear(&valueW);
1257 return E_OUTOFMEMORY;
1260 attr = xmlSetNsProp(get_element(This), NULL, name, value);
1262 attr_node->parent = (IXMLDOMNode*)iface;
1264 SysFreeString(nameW);
1265 VariantClear(&valueW);
1269 return attr ? S_OK : E_FAIL;
1272 static HRESULT WINAPI domelem_removeAttributeNode(
1273 IXMLDOMElement *iface,
1274 IXMLDOMAttribute* domAttribute,
1275 IXMLDOMAttribute** attributeNode)
1277 domelem *This = impl_from_IXMLDOMElement( iface );
1278 FIXME("(%p)->(%p %p)\n", This, domAttribute, attributeNode);
1282 static HRESULT WINAPI domelem_getElementsByTagName(
1283 IXMLDOMElement *iface,
1284 BSTR tagName, IXMLDOMNodeList** resultList)
1286 domelem *This = impl_from_IXMLDOMElement( iface );
1291 TRACE("(%p)->(%s, %p)\n", This, debugstr_w(tagName), resultList);
1293 if (!tagName || !resultList) return E_INVALIDARG;
1295 XPath = is_xpathmode(get_element(This)->doc);
1296 set_xpathmode(get_element(This)->doc, TRUE);
1297 query = tagName_to_XPath(tagName);
1298 hr = create_selection(get_element(This), query, resultList);
1300 set_xpathmode(get_element(This)->doc, XPath);
1305 static HRESULT WINAPI domelem_normalize(
1306 IXMLDOMElement *iface )
1308 domelem *This = impl_from_IXMLDOMElement( iface );
1309 FIXME("%p\n", This);
1313 static const struct IXMLDOMElementVtbl domelem_vtbl =
1315 domelem_QueryInterface,
1318 domelem_GetTypeInfoCount,
1319 domelem_GetTypeInfo,
1320 domelem_GetIDsOfNames,
1322 domelem_get_nodeName,
1323 domelem_get_nodeValue,
1324 domelem_put_nodeValue,
1325 domelem_get_nodeType,
1326 domelem_get_parentNode,
1327 domelem_get_childNodes,
1328 domelem_get_firstChild,
1329 domelem_get_lastChild,
1330 domelem_get_previousSibling,
1331 domelem_get_nextSibling,
1332 domelem_get_attributes,
1333 domelem_insertBefore,
1334 domelem_replaceChild,
1335 domelem_removeChild,
1336 domelem_appendChild,
1337 domelem_hasChildNodes,
1338 domelem_get_ownerDocument,
1340 domelem_get_nodeTypeString,
1343 domelem_get_specified,
1344 domelem_get_definition,
1345 domelem_get_nodeTypedValue,
1346 domelem_put_nodeTypedValue,
1347 domelem_get_dataType,
1348 domelem_put_dataType,
1350 domelem_transformNode,
1351 domelem_selectNodes,
1352 domelem_selectSingleNode,
1354 domelem_get_namespaceURI,
1356 domelem_get_baseName,
1357 domelem_transformNodeToObject,
1358 domelem_get_tagName,
1359 domelem_getAttribute,
1360 domelem_setAttribute,
1361 domelem_removeAttribute,
1362 domelem_getAttributeNode,
1363 domelem_setAttributeNode,
1364 domelem_removeAttributeNode,
1365 domelem_getElementsByTagName,
1369 static const tid_t domelem_iface_tids[] = {
1374 static dispex_static_data_t domelem_dispex = {
1381 IUnknown* create_element( xmlNodePtr element )
1385 This = heap_alloc( sizeof *This );
1389 This->IXMLDOMElement_iface.lpVtbl = &domelem_vtbl;
1392 init_xmlnode(&This->node, element, (IXMLDOMNode*)&This->IXMLDOMElement_iface, &domelem_dispex);
1394 return (IUnknown*)&This->IXMLDOMElement_iface;