shell32: Use S_OK as successful return code name.
[wine/multimedia.git] / dlls / msxml3 / element.c
blob2d920cd795f2a50508714c4f25d4e7cebc7937ee
1 /*
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
21 #define COBJMACROS
23 #include "config.h"
25 #include <stdarg.h>
26 #ifdef HAVE_LIBXML2
27 # include <libxml/parser.h>
28 # include <libxml/xmlerror.h>
29 #endif
31 #include "windef.h"
32 #include "winbase.h"
33 #include "winuser.h"
34 #include "winnls.h"
35 #include "ole2.h"
36 #include "msxml6.h"
38 #include "msxml_private.h"
40 #include "wine/debug.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
44 #ifdef HAVE_LIBXML2
46 static const xmlChar DT_prefix[] = "dt";
47 static const xmlChar DT_nsURI[] = "urn:schemas-microsoft-com:datatypes";
49 typedef struct _domelem
51 xmlnode node;
52 IXMLDOMElement IXMLDOMElement_iface;
53 LONG ref;
54 } domelem;
56 static const struct nodemap_funcs domelem_attr_map;
58 static const tid_t domelem_se_tids[] = {
59 IXMLDOMNode_tid,
60 IXMLDOMElement_tid,
64 static inline domelem *impl_from_IXMLDOMElement( IXMLDOMElement *iface )
66 return CONTAINING_RECORD(iface, domelem, IXMLDOMElement_iface);
69 static inline xmlNodePtr get_element( const domelem *This )
71 return This->node.node;
74 static HRESULT WINAPI domelem_QueryInterface(
75 IXMLDOMElement *iface,
76 REFIID riid,
77 void** ppvObject )
79 domelem *This = impl_from_IXMLDOMElement( iface );
81 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
83 if ( IsEqualGUID( riid, &IID_IXMLDOMElement ) ||
84 IsEqualGUID( riid, &IID_IXMLDOMNode ) ||
85 IsEqualGUID( riid, &IID_IDispatch ) ||
86 IsEqualGUID( riid, &IID_IUnknown ) )
88 *ppvObject = &This->IXMLDOMElement_iface;
90 else if(node_query_interface(&This->node, riid, ppvObject))
92 return *ppvObject ? S_OK : E_NOINTERFACE;
94 else if(IsEqualGUID( riid, &IID_ISupportErrorInfo ))
96 return node_create_supporterrorinfo(domelem_se_tids, ppvObject);
98 else
100 TRACE("interface %s not implemented\n", debugstr_guid(riid));
101 *ppvObject = NULL;
102 return E_NOINTERFACE;
105 IUnknown_AddRef( (IUnknown*)*ppvObject );
106 return S_OK;
109 static ULONG WINAPI domelem_AddRef(
110 IXMLDOMElement *iface )
112 domelem *This = impl_from_IXMLDOMElement( iface );
113 LONG ref = InterlockedIncrement(&This->ref);
115 TRACE("(%p)->(%d)\n", This, ref);
117 return ref;
120 static ULONG WINAPI domelem_Release(
121 IXMLDOMElement *iface )
123 domelem *This = impl_from_IXMLDOMElement( iface );
124 ULONG ref = InterlockedDecrement(&This->ref);
126 TRACE("(%p)->(%d)\n", This, ref);
128 if(!ref) {
129 destroy_xmlnode(&This->node);
130 heap_free(This);
133 return ref;
136 static HRESULT WINAPI domelem_GetTypeInfoCount(
137 IXMLDOMElement *iface,
138 UINT* pctinfo )
140 domelem *This = impl_from_IXMLDOMElement( iface );
141 return IDispatchEx_GetTypeInfoCount(&This->node.dispex.IDispatchEx_iface, pctinfo);
144 static HRESULT WINAPI domelem_GetTypeInfo(
145 IXMLDOMElement *iface,
146 UINT iTInfo, LCID lcid,
147 ITypeInfo** ppTInfo )
149 domelem *This = impl_from_IXMLDOMElement( iface );
150 return IDispatchEx_GetTypeInfo(&This->node.dispex.IDispatchEx_iface,
151 iTInfo, lcid, ppTInfo);
154 static HRESULT WINAPI domelem_GetIDsOfNames(
155 IXMLDOMElement *iface,
156 REFIID riid, LPOLESTR* rgszNames,
157 UINT cNames, LCID lcid, DISPID* rgDispId )
159 domelem *This = impl_from_IXMLDOMElement( iface );
160 return IDispatchEx_GetIDsOfNames(&This->node.dispex.IDispatchEx_iface,
161 riid, rgszNames, cNames, lcid, rgDispId);
164 static HRESULT WINAPI domelem_Invoke(
165 IXMLDOMElement *iface,
166 DISPID dispIdMember, REFIID riid, LCID lcid,
167 WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
168 EXCEPINFO* pExcepInfo, UINT* puArgErr )
170 domelem *This = impl_from_IXMLDOMElement( iface );
171 return IDispatchEx_Invoke(&This->node.dispex.IDispatchEx_iface,
172 dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
175 static HRESULT WINAPI domelem_get_nodeName(
176 IXMLDOMElement *iface,
177 BSTR* p )
179 domelem *This = impl_from_IXMLDOMElement( iface );
181 TRACE("(%p)->(%p)\n", This, p);
183 return node_get_nodeName(&This->node, p);
186 static HRESULT WINAPI domelem_get_nodeValue(
187 IXMLDOMElement *iface,
188 VARIANT* value)
190 domelem *This = impl_from_IXMLDOMElement( iface );
192 TRACE("(%p)->(%p)\n", This, value);
194 if(!value)
195 return E_INVALIDARG;
197 V_VT(value) = VT_NULL;
198 V_BSTR(value) = NULL; /* tests show that we should do this */
199 return S_FALSE;
202 static HRESULT WINAPI domelem_put_nodeValue(
203 IXMLDOMElement *iface,
204 VARIANT value)
206 domelem *This = impl_from_IXMLDOMElement( iface );
207 TRACE("(%p)->(%s)\n", This, debugstr_variant(&value));
208 return E_FAIL;
211 static HRESULT WINAPI domelem_get_nodeType(
212 IXMLDOMElement *iface,
213 DOMNodeType* domNodeType )
215 domelem *This = impl_from_IXMLDOMElement( iface );
217 TRACE("(%p)->(%p)\n", This, domNodeType);
219 *domNodeType = NODE_ELEMENT;
220 return S_OK;
223 static HRESULT WINAPI domelem_get_parentNode(
224 IXMLDOMElement *iface,
225 IXMLDOMNode** parent )
227 domelem *This = impl_from_IXMLDOMElement( iface );
229 TRACE("(%p)->(%p)\n", This, parent);
231 return node_get_parent(&This->node, parent);
234 static HRESULT WINAPI domelem_get_childNodes(
235 IXMLDOMElement *iface,
236 IXMLDOMNodeList** outList)
238 domelem *This = impl_from_IXMLDOMElement( iface );
240 TRACE("(%p)->(%p)\n", This, outList);
242 return node_get_child_nodes(&This->node, outList);
245 static HRESULT WINAPI domelem_get_firstChild(
246 IXMLDOMElement *iface,
247 IXMLDOMNode** domNode)
249 domelem *This = impl_from_IXMLDOMElement( iface );
251 TRACE("(%p)->(%p)\n", This, domNode);
253 return node_get_first_child(&This->node, domNode);
256 static HRESULT WINAPI domelem_get_lastChild(
257 IXMLDOMElement *iface,
258 IXMLDOMNode** domNode)
260 domelem *This = impl_from_IXMLDOMElement( iface );
262 TRACE("(%p)->(%p)\n", This, domNode);
264 return node_get_last_child(&This->node, domNode);
267 static HRESULT WINAPI domelem_get_previousSibling(
268 IXMLDOMElement *iface,
269 IXMLDOMNode** domNode)
271 domelem *This = impl_from_IXMLDOMElement( iface );
273 TRACE("(%p)->(%p)\n", This, domNode);
275 return node_get_previous_sibling(&This->node, domNode);
278 static HRESULT WINAPI domelem_get_nextSibling(
279 IXMLDOMElement *iface,
280 IXMLDOMNode** domNode)
282 domelem *This = impl_from_IXMLDOMElement( iface );
284 TRACE("(%p)->(%p)\n", This, domNode);
286 return node_get_next_sibling(&This->node, domNode);
289 static HRESULT WINAPI domelem_get_attributes(
290 IXMLDOMElement *iface,
291 IXMLDOMNamedNodeMap** map)
293 domelem *This = impl_from_IXMLDOMElement( iface );
295 TRACE("(%p)->(%p)\n", This, map);
297 *map = create_nodemap(This->node.node, &domelem_attr_map);
298 return S_OK;
301 static HRESULT WINAPI domelem_insertBefore(
302 IXMLDOMElement *iface,
303 IXMLDOMNode* newNode, VARIANT refChild,
304 IXMLDOMNode** outOldNode)
306 domelem *This = impl_from_IXMLDOMElement( iface );
308 TRACE("(%p)->(%p %s %p)\n", This, newNode, debugstr_variant(&refChild), outOldNode);
310 return node_insert_before(&This->node, newNode, &refChild, outOldNode);
313 static HRESULT WINAPI domelem_replaceChild(
314 IXMLDOMElement *iface,
315 IXMLDOMNode* newNode,
316 IXMLDOMNode* oldNode,
317 IXMLDOMNode** outOldNode)
319 domelem *This = impl_from_IXMLDOMElement( iface );
321 TRACE("(%p)->(%p %p %p)\n", This, newNode, oldNode, outOldNode);
323 return node_replace_child(&This->node, newNode, oldNode, outOldNode);
326 static HRESULT WINAPI domelem_removeChild(
327 IXMLDOMElement *iface,
328 IXMLDOMNode *child, IXMLDOMNode **oldChild)
330 domelem *This = impl_from_IXMLDOMElement( iface );
331 TRACE("(%p)->(%p %p)\n", This, child, oldChild);
332 return node_remove_child(&This->node, child, oldChild);
335 static HRESULT WINAPI domelem_appendChild(
336 IXMLDOMElement *iface,
337 IXMLDOMNode *child, IXMLDOMNode **outChild)
339 domelem *This = impl_from_IXMLDOMElement( iface );
340 TRACE("(%p)->(%p %p)\n", This, child, outChild);
341 return node_append_child(&This->node, child, outChild);
344 static HRESULT WINAPI domelem_hasChildNodes(
345 IXMLDOMElement *iface,
346 VARIANT_BOOL *ret)
348 domelem *This = impl_from_IXMLDOMElement( iface );
349 TRACE("(%p)->(%p)\n", This, ret);
350 return node_has_childnodes(&This->node, ret);
353 static HRESULT WINAPI domelem_get_ownerDocument(
354 IXMLDOMElement *iface,
355 IXMLDOMDocument **doc)
357 domelem *This = impl_from_IXMLDOMElement( iface );
358 TRACE("(%p)->(%p)\n", This, doc);
359 return node_get_owner_doc(&This->node, doc);
362 static HRESULT WINAPI domelem_cloneNode(
363 IXMLDOMElement *iface,
364 VARIANT_BOOL deep, IXMLDOMNode** outNode)
366 domelem *This = impl_from_IXMLDOMElement( iface );
367 TRACE("(%p)->(%d %p)\n", This, deep, outNode);
368 return node_clone( &This->node, deep, outNode );
371 static HRESULT WINAPI domelem_get_nodeTypeString(
372 IXMLDOMElement *iface,
373 BSTR* p)
375 domelem *This = impl_from_IXMLDOMElement( iface );
376 static const WCHAR elementW[] = {'e','l','e','m','e','n','t',0};
378 TRACE("(%p)->(%p)\n", This, p);
380 return return_bstr(elementW, p);
383 static HRESULT WINAPI domelem_get_text(
384 IXMLDOMElement *iface,
385 BSTR* p)
387 domelem *This = impl_from_IXMLDOMElement( iface );
388 TRACE("(%p)->(%p)\n", This, p);
389 return node_get_text(&This->node, p);
392 static HRESULT WINAPI domelem_put_text(
393 IXMLDOMElement *iface,
394 BSTR p)
396 domelem *This = impl_from_IXMLDOMElement( iface );
397 TRACE("(%p)->(%s)\n", This, debugstr_w(p));
398 return node_put_text( &This->node, p );
401 static HRESULT WINAPI domelem_get_specified(
402 IXMLDOMElement *iface,
403 VARIANT_BOOL* isSpecified)
405 domelem *This = impl_from_IXMLDOMElement( iface );
406 FIXME("(%p)->(%p) stub!\n", This, isSpecified);
407 *isSpecified = VARIANT_TRUE;
408 return S_OK;
411 static HRESULT WINAPI domelem_get_definition(
412 IXMLDOMElement *iface,
413 IXMLDOMNode** definitionNode)
415 domelem *This = impl_from_IXMLDOMElement( iface );
416 FIXME("(%p)->(%p)\n", This, definitionNode);
417 return E_NOTIMPL;
420 static inline BYTE hex_to_byte(xmlChar c)
422 if(c <= '9') return c-'0';
423 if(c <= 'F') return c-'A'+10;
424 return c-'a'+10;
427 static inline BYTE base64_to_byte(xmlChar c)
429 if(c == '+') return 62;
430 if(c == '/') return 63;
431 if(c <= '9') return c-'0'+52;
432 if(c <= 'Z') return c-'A';
433 return c-'a'+26;
436 static inline HRESULT variant_from_dt(XDR_DT dt, xmlChar* str, VARIANT* v)
438 VARIANT src;
439 HRESULT hr = S_OK;
440 BOOL handled = FALSE;
442 VariantInit(&src);
444 switch (dt)
446 case DT_INVALID:
447 case DT_STRING:
448 case DT_NMTOKEN:
449 case DT_NMTOKENS:
450 case DT_NUMBER:
451 case DT_URI:
452 case DT_UUID:
454 V_VT(v) = VT_BSTR;
455 V_BSTR(v) = bstr_from_xmlChar(str);
457 if(!V_BSTR(v))
458 return E_OUTOFMEMORY;
459 handled = TRUE;
461 break;
462 case DT_DATE:
463 case DT_DATE_TZ:
464 case DT_DATETIME:
465 case DT_DATETIME_TZ:
466 case DT_TIME:
467 case DT_TIME_TZ:
469 WCHAR *p, *e;
470 SYSTEMTIME st;
471 DOUBLE date = 0.0;
473 st.wYear = 1899;
474 st.wMonth = 12;
475 st.wDay = 30;
476 st.wDayOfWeek = st.wHour = st.wMinute = st.wSecond = st.wMilliseconds = 0;
478 V_VT(&src) = VT_BSTR;
479 V_BSTR(&src) = bstr_from_xmlChar(str);
481 if(!V_BSTR(&src))
482 return E_OUTOFMEMORY;
484 p = V_BSTR(&src);
485 e = p + SysStringLen(V_BSTR(&src));
487 if(p+4<e && *(p+4)=='-') /* parse date (yyyy-mm-dd) */
489 st.wYear = atoiW(p);
490 st.wMonth = atoiW(p+5);
491 st.wDay = atoiW(p+8);
492 p += 10;
494 if(*p == 'T') p++;
497 if(p+2<e && *(p+2)==':') /* parse time (hh:mm:ss.?) */
499 st.wHour = atoiW(p);
500 st.wMinute = atoiW(p+3);
501 st.wSecond = atoiW(p+6);
502 p += 8;
504 if(*p == '.')
506 p++;
507 while(isdigitW(*p)) p++;
511 SystemTimeToVariantTime(&st, &date);
512 V_VT(v) = VT_DATE;
513 V_DATE(v) = date;
515 if(*p == '+') /* parse timezone offset (+hh:mm) */
516 V_DATE(v) += (DOUBLE)atoiW(p+1)/24 + (DOUBLE)atoiW(p+4)/1440;
517 else if(*p == '-') /* parse timezone offset (-hh:mm) */
518 V_DATE(v) -= (DOUBLE)atoiW(p+1)/24 + (DOUBLE)atoiW(p+4)/1440;
520 VariantClear(&src);
521 handled = TRUE;
523 break;
524 case DT_BIN_HEX:
526 SAFEARRAYBOUND sab;
527 int i, len;
529 len = xmlStrlen(str)/2;
530 sab.lLbound = 0;
531 sab.cElements = len;
533 V_VT(v) = (VT_ARRAY|VT_UI1);
534 V_ARRAY(v) = SafeArrayCreate(VT_UI1, 1, &sab);
536 if(!V_ARRAY(v))
537 return E_OUTOFMEMORY;
539 for(i=0; i<len; i++)
540 ((BYTE*)V_ARRAY(v)->pvData)[i] = (hex_to_byte(str[2*i])<<4)
541 + hex_to_byte(str[2*i+1]);
542 handled = TRUE;
544 break;
545 case DT_BIN_BASE64:
547 SAFEARRAYBOUND sab;
548 xmlChar *c1, *c2;
549 int i, len;
551 /* remove all formatting chars */
552 c1 = c2 = str;
553 len = 0;
554 while (*c2)
556 if ( *c2 == ' ' || *c2 == '\t' ||
557 *c2 == '\n' || *c2 == '\r' )
559 c2++;
560 continue;
562 *c1++ = *c2++;
563 len++;
566 /* skip padding */
567 if(str[len-2] == '=') i = 2;
568 else if(str[len-1] == '=') i = 1;
569 else i = 0;
571 sab.lLbound = 0;
572 sab.cElements = len/4*3-i;
574 V_VT(v) = (VT_ARRAY|VT_UI1);
575 V_ARRAY(v) = SafeArrayCreate(VT_UI1, 1, &sab);
577 if(!V_ARRAY(v))
578 return E_OUTOFMEMORY;
580 for(i=0; i<len/4; i++)
582 ((BYTE*)V_ARRAY(v)->pvData)[3*i] = (base64_to_byte(str[4*i])<<2)
583 + (base64_to_byte(str[4*i+1])>>4);
584 if(3*i+1 < sab.cElements)
585 ((BYTE*)V_ARRAY(v)->pvData)[3*i+1] = (base64_to_byte(str[4*i+1])<<4)
586 + (base64_to_byte(str[4*i+2])>>2);
587 if(3*i+2 < sab.cElements)
588 ((BYTE*)V_ARRAY(v)->pvData)[3*i+2] = (base64_to_byte(str[4*i+2])<<6)
589 + base64_to_byte(str[4*i+3]);
591 handled = TRUE;
593 break;
594 case DT_BOOLEAN:
595 V_VT(v) = VT_BOOL;
596 break;
597 case DT_FIXED_14_4:
598 V_VT(v) = VT_CY;
599 break;
600 case DT_I1:
601 V_VT(v) = VT_I1;
602 break;
603 case DT_I2:
604 V_VT(v) = VT_I2;
605 break;
606 case DT_I4:
607 case DT_INT:
608 V_VT(v) = VT_I4;
609 break;
610 case DT_I8:
611 V_VT(v) = VT_I8;
612 break;
613 case DT_R4:
614 V_VT(v) = VT_R4;
615 break;
616 case DT_FLOAT:
617 case DT_R8:
618 V_VT(v) = VT_R8;
619 break;
620 case DT_UI1:
621 V_VT(v) = VT_UI1;
622 break;
623 case DT_UI2:
624 V_VT(v) = VT_UI2;
625 break;
626 case DT_UI4:
627 V_VT(v) = VT_UI4;
628 break;
629 case DT_UI8:
630 V_VT(v) = VT_UI8;
631 break;
632 case DT_CHAR:
633 case DT_ENTITY:
634 case DT_ENTITIES:
635 case DT_ENUMERATION:
636 case DT_ID:
637 case DT_IDREF:
638 case DT_IDREFS:
639 case DT_NOTATION:
640 FIXME("need to handle dt:%s\n", debugstr_dt(dt));
641 V_VT(v) = VT_BSTR;
642 V_BSTR(v) = bstr_from_xmlChar(str);
643 if (!V_BSTR(v))
644 return E_OUTOFMEMORY;
645 handled = TRUE;
646 break;
649 if (!handled)
651 V_VT(&src) = VT_BSTR;
652 V_BSTR(&src) = bstr_from_xmlChar(str);
654 if(!V_BSTR(&src))
655 return E_OUTOFMEMORY;
657 hr = VariantChangeTypeEx(v, &src,
658 MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT),0, V_VT(v));
659 VariantClear(&src);
661 return hr;
664 static XDR_DT element_get_dt(xmlNodePtr node)
666 XDR_DT dt = DT_INVALID;
668 TRACE("(%p)\n", node);
669 if(node->type != XML_ELEMENT_NODE)
671 FIXME("invalid element node\n");
672 return dt;
675 if (node->ns && xmlStrEqual(node->ns->href, DT_nsURI))
677 dt = str_to_dt(node->name, -1);
679 else
681 xmlChar* pVal = xmlGetNsProp(node, BAD_CAST "dt", DT_nsURI);
682 if (pVal)
684 dt = str_to_dt(pVal, -1);
685 xmlFree(pVal);
687 else if (node->doc)
689 IXMLDOMDocument3* doc = (IXMLDOMDocument3*)create_domdoc((xmlNodePtr)node->doc);
690 if (doc)
692 VARIANT v;
693 VariantInit(&v);
695 if (IXMLDOMDocument3_get_schemas(doc, &v) == S_OK &&
696 V_VT(&v) == VT_DISPATCH)
698 dt = SchemaCache_get_node_dt((IXMLDOMSchemaCollection2*)V_DISPATCH(&v), node);
700 VariantClear(&v);
701 IXMLDOMDocument3_Release(doc);
706 TRACE("=> dt:%s\n", debugstr_dt(dt));
707 return dt;
710 static HRESULT WINAPI domelem_get_nodeTypedValue(
711 IXMLDOMElement *iface,
712 VARIANT* v)
714 domelem *This = impl_from_IXMLDOMElement( iface );
715 XDR_DT dt;
716 xmlChar* content;
717 HRESULT hr;
719 TRACE("(%p)->(%p)\n", This, v);
721 if(!v) return E_INVALIDARG;
723 V_VT(v) = VT_NULL;
725 dt = element_get_dt(get_element(This));
726 content = xmlNodeGetContent(get_element(This));
727 hr = variant_from_dt(dt, content, v);
728 xmlFree(content);
730 return hr;
733 static HRESULT WINAPI domelem_put_nodeTypedValue(
734 IXMLDOMElement *iface,
735 VARIANT value)
737 domelem *This = impl_from_IXMLDOMElement( iface );
738 XDR_DT dt;
739 HRESULT hr;
741 TRACE("(%p)->(%s)\n", This, debugstr_variant(&value));
743 dt = element_get_dt(get_element(This));
744 /* for untyped node coerce to BSTR and set */
745 if (dt == DT_INVALID)
747 if (V_VT(&value) != VT_BSTR)
749 VARIANT content;
750 VariantInit(&content);
751 hr = VariantChangeType(&content, &value, 0, VT_BSTR);
752 if (hr == S_OK)
754 hr = node_set_content(&This->node, V_BSTR(&content));
755 VariantClear(&content);
758 else
759 hr = node_set_content(&This->node, V_BSTR(&value));
761 else
763 FIXME("not implemented for dt:%s\n", debugstr_dt(dt));
764 return E_NOTIMPL;
767 return hr;
770 static HRESULT WINAPI domelem_get_dataType(
771 IXMLDOMElement *iface,
772 VARIANT* typename)
774 domelem *This = impl_from_IXMLDOMElement( iface );
775 XDR_DT dt;
777 TRACE("(%p)->(%p)\n", This, typename);
779 if (!typename)
780 return E_INVALIDARG;
782 dt = element_get_dt(get_element(This));
783 switch (dt)
785 case DT_BIN_BASE64:
786 case DT_BIN_HEX:
787 case DT_BOOLEAN:
788 case DT_CHAR:
789 case DT_DATE:
790 case DT_DATE_TZ:
791 case DT_DATETIME:
792 case DT_DATETIME_TZ:
793 case DT_FIXED_14_4:
794 case DT_FLOAT:
795 case DT_I1:
796 case DT_I2:
797 case DT_I4:
798 case DT_I8:
799 case DT_INT:
800 case DT_NUMBER:
801 case DT_R4:
802 case DT_R8:
803 case DT_TIME:
804 case DT_TIME_TZ:
805 case DT_UI1:
806 case DT_UI2:
807 case DT_UI4:
808 case DT_UI8:
809 case DT_URI:
810 case DT_UUID:
811 V_VT(typename) = VT_BSTR;
812 V_BSTR(typename) = SysAllocString(dt_to_bstr(dt));
814 if (!V_BSTR(typename))
815 return E_OUTOFMEMORY;
816 break;
817 default:
818 /* Other types (DTD equivalents) do not return anything here,
819 * but the pointer part of the VARIANT is set to NULL */
820 V_VT(typename) = VT_NULL;
821 V_BSTR(typename) = NULL;
822 break;
824 return (V_VT(typename) != VT_NULL) ? S_OK : S_FALSE;
827 static HRESULT WINAPI domelem_put_dataType(
828 IXMLDOMElement *iface,
829 BSTR dtName)
831 domelem *This = impl_from_IXMLDOMElement( iface );
832 HRESULT hr = E_FAIL;
833 xmlChar *str;
834 XDR_DT dt;
836 TRACE("(%p)->(%s)\n", This, debugstr_w(dtName));
838 if(dtName == NULL)
839 return E_INVALIDARG;
841 dt = bstr_to_dt(dtName, -1);
843 /* An example of this is. The Text in the node needs to be a 0 or 1 for a boolean type.
844 This applies to changing types (string->bool) or setting a new one
846 str = xmlNodeGetContent(get_element(This));
847 hr = dt_validate(dt, str);
848 xmlFree(str);
850 /* Check all supported types. */
851 if (hr == S_OK)
853 switch (dt)
855 case DT_BIN_BASE64:
856 case DT_BIN_HEX:
857 case DT_BOOLEAN:
858 case DT_CHAR:
859 case DT_DATE:
860 case DT_DATE_TZ:
861 case DT_DATETIME:
862 case DT_DATETIME_TZ:
863 case DT_FIXED_14_4:
864 case DT_FLOAT:
865 case DT_I1:
866 case DT_I2:
867 case DT_I4:
868 case DT_I8:
869 case DT_INT:
870 case DT_NMTOKEN:
871 case DT_NMTOKENS:
872 case DT_NUMBER:
873 case DT_R4:
874 case DT_R8:
875 case DT_STRING:
876 case DT_TIME:
877 case DT_TIME_TZ:
878 case DT_UI1:
879 case DT_UI2:
880 case DT_UI4:
881 case DT_UI8:
882 case DT_URI:
883 case DT_UUID:
885 xmlAttrPtr attr = xmlHasNsProp(get_element(This), DT_prefix, DT_nsURI);
886 if (attr)
888 attr = xmlSetNsProp(get_element(This), attr->ns, DT_prefix, dt_to_str(dt));
889 hr = S_OK;
891 else
893 xmlNsPtr ns = xmlNewNs(get_element(This), DT_nsURI, DT_prefix);
894 if (ns)
896 attr = xmlNewNsProp(get_element(This), ns, DT_prefix, dt_to_str(dt));
897 if (attr)
899 xmlAddChild(get_element(This), (xmlNodePtr)attr);
900 hr = S_OK;
902 else
903 ERR("Failed to create Attribute\n");
905 else
906 ERR("Failed to create Namespace\n");
909 break;
910 default:
911 FIXME("need to handle dt:%s\n", debugstr_dt(dt));
912 break;
916 return hr;
919 static HRESULT WINAPI domelem_get_xml(
920 IXMLDOMElement *iface,
921 BSTR* p)
923 domelem *This = impl_from_IXMLDOMElement( iface );
925 TRACE("(%p)->(%p)\n", This, p);
927 return node_get_xml(&This->node, TRUE, FALSE, p);
930 static HRESULT WINAPI domelem_transformNode(
931 IXMLDOMElement *iface,
932 IXMLDOMNode *node, BSTR *p)
934 domelem *This = impl_from_IXMLDOMElement( iface );
935 TRACE("(%p)->(%p %p)\n", This, node, p);
936 return node_transform_node(&This->node, node, p);
939 static HRESULT WINAPI domelem_selectNodes(
940 IXMLDOMElement *iface,
941 BSTR p, IXMLDOMNodeList** outList)
943 domelem *This = impl_from_IXMLDOMElement( iface );
944 TRACE("(%p)->(%s %p)\n", This, debugstr_w(p), outList);
945 return node_select_nodes(&This->node, p, outList);
948 static HRESULT WINAPI domelem_selectSingleNode(
949 IXMLDOMElement *iface,
950 BSTR p, IXMLDOMNode** outNode)
952 domelem *This = impl_from_IXMLDOMElement( iface );
953 TRACE("(%p)->(%s %p)\n", This, debugstr_w(p), outNode);
954 return node_select_singlenode(&This->node, p, outNode);
957 static HRESULT WINAPI domelem_get_parsed(
958 IXMLDOMElement *iface,
959 VARIANT_BOOL* isParsed)
961 domelem *This = impl_from_IXMLDOMElement( iface );
962 FIXME("(%p)->(%p) stub!\n", This, isParsed);
963 *isParsed = VARIANT_TRUE;
964 return S_OK;
967 static HRESULT WINAPI domelem_get_namespaceURI(
968 IXMLDOMElement *iface,
969 BSTR* p)
971 domelem *This = impl_from_IXMLDOMElement( iface );
972 TRACE("(%p)->(%p)\n", This, p);
973 return node_get_namespaceURI(&This->node, p);
976 static HRESULT WINAPI domelem_get_prefix(
977 IXMLDOMElement *iface,
978 BSTR* prefix)
980 domelem *This = impl_from_IXMLDOMElement( iface );
981 TRACE("(%p)->(%p)\n", This, prefix);
982 return node_get_prefix( &This->node, prefix );
985 static HRESULT WINAPI domelem_get_baseName(
986 IXMLDOMElement *iface,
987 BSTR* name)
989 domelem *This = impl_from_IXMLDOMElement( iface );
990 TRACE("(%p)->(%p)\n", This, name);
991 return node_get_base_name( &This->node, name );
994 static HRESULT WINAPI domelem_transformNodeToObject(
995 IXMLDOMElement *iface,
996 IXMLDOMNode* domNode, VARIANT var1)
998 domelem *This = impl_from_IXMLDOMElement( iface );
999 FIXME("(%p)->(%p %s)\n", This, domNode, debugstr_variant(&var1));
1000 return E_NOTIMPL;
1003 static HRESULT WINAPI domelem_get_tagName(
1004 IXMLDOMElement *iface,
1005 BSTR* p)
1007 domelem *This = impl_from_IXMLDOMElement( iface );
1008 xmlNodePtr element;
1009 const xmlChar *prefix;
1010 xmlChar *qname;
1012 TRACE("(%p)->(%p)\n", This, p );
1014 if (!p) return E_INVALIDARG;
1016 element = get_element( This );
1017 if ( !element )
1018 return E_FAIL;
1020 prefix = element->ns ? element->ns->prefix : NULL;
1021 qname = xmlBuildQName(element->name, prefix, NULL, 0);
1023 *p = bstr_from_xmlChar(qname);
1024 if (qname != element->name) xmlFree(qname);
1026 return *p ? S_OK : E_OUTOFMEMORY;
1029 static HRESULT WINAPI domelem_getAttribute(
1030 IXMLDOMElement *iface,
1031 BSTR name, VARIANT* value)
1033 domelem *This = impl_from_IXMLDOMElement( iface );
1034 xmlNodePtr element;
1035 xmlChar *xml_name, *xml_value = NULL;
1036 HRESULT hr = S_FALSE;
1038 TRACE("(%p)->(%s %p)\n", This, debugstr_w(name), value);
1040 if(!value || !name)
1041 return E_INVALIDARG;
1043 element = get_element( This );
1044 if ( !element )
1045 return E_FAIL;
1047 V_BSTR(value) = NULL;
1048 V_VT(value) = VT_NULL;
1050 xml_name = xmlchar_from_wchar( name );
1052 if(!xmlValidateNameValue(xml_name))
1053 hr = E_FAIL;
1054 else
1055 xml_value = xmlGetNsProp(element, xml_name, NULL);
1057 heap_free(xml_name);
1058 if(xml_value)
1060 V_VT(value) = VT_BSTR;
1061 V_BSTR(value) = bstr_from_xmlChar( xml_value );
1062 xmlFree(xml_value);
1063 hr = S_OK;
1066 return hr;
1069 static HRESULT WINAPI domelem_setAttribute(
1070 IXMLDOMElement *iface,
1071 BSTR name, VARIANT value)
1073 domelem *This = impl_from_IXMLDOMElement( iface );
1074 xmlChar *xml_name, *xml_value, *local, *prefix;
1075 xmlNodePtr element;
1076 HRESULT hr;
1077 VARIANT var;
1079 TRACE("(%p)->(%s %s)\n", This, debugstr_w(name), debugstr_variant(&value));
1081 element = get_element( This );
1082 if ( !element )
1083 return E_FAIL;
1085 VariantInit(&var);
1086 hr = VariantChangeType(&var, &value, 0, VT_BSTR);
1087 if(hr != S_OK)
1089 FIXME("VariantChangeType failed\n");
1090 return hr;
1093 xml_name = xmlchar_from_wchar( name );
1094 xml_value = xmlchar_from_wchar( V_BSTR(&var) );
1096 if ((local = xmlSplitQName2(xml_name, &prefix)))
1098 static const xmlChar* xmlnsA = (const xmlChar*)"xmlns";
1099 xmlNsPtr ns = NULL;
1101 /* it's not allowed to modify existing namespace definition */
1102 if (xmlStrEqual(prefix, xmlnsA))
1103 ns = xmlSearchNs(element->doc, element, local);
1105 xmlFree(prefix);
1106 xmlFree(local);
1108 if (ns)
1109 return xmlStrEqual(ns->href, xml_value) ? S_OK : E_INVALIDARG;
1112 if (!xmlSetNsProp(element, NULL, xml_name, xml_value))
1113 hr = E_FAIL;
1115 heap_free(xml_value);
1116 heap_free(xml_name);
1117 VariantClear(&var);
1119 return hr;
1122 static HRESULT WINAPI domelem_removeAttribute(
1123 IXMLDOMElement *iface,
1124 BSTR p)
1126 domelem *This = impl_from_IXMLDOMElement( iface );
1127 IXMLDOMNamedNodeMap *attr;
1128 HRESULT hr;
1130 TRACE("(%p)->(%s)\n", This, debugstr_w(p));
1132 hr = IXMLDOMElement_get_attributes(iface, &attr);
1133 if (hr != S_OK) return hr;
1135 hr = IXMLDOMNamedNodeMap_removeNamedItem(attr, p, NULL);
1136 IXMLDOMNamedNodeMap_Release(attr);
1138 return hr;
1141 static HRESULT WINAPI domelem_getAttributeNode(
1142 IXMLDOMElement *iface,
1143 BSTR p, IXMLDOMAttribute** attributeNode )
1145 domelem *This = impl_from_IXMLDOMElement( iface );
1146 xmlChar *local, *prefix, *nameA;
1147 HRESULT hr = S_FALSE;
1148 xmlNodePtr element;
1149 xmlAttrPtr attr;
1151 TRACE("(%p)->(%s %p)\n", This, debugstr_w(p), attributeNode);
1153 element = get_element( This );
1154 if (!element) return E_FAIL;
1156 if (attributeNode) *attributeNode = NULL;
1158 nameA = xmlchar_from_wchar(p);
1159 if (!xmlValidateNameValue(nameA))
1161 heap_free(nameA);
1162 return E_FAIL;
1165 if (!attributeNode)
1167 heap_free(nameA);
1168 return S_FALSE;
1171 *attributeNode = NULL;
1173 local = xmlSplitQName2(nameA, &prefix);
1175 if (local)
1177 /* try to get namespace for supplied qualified name */
1178 xmlNsPtr ns = xmlSearchNs(element->doc, element, prefix);
1179 xmlFree(prefix);
1181 attr = xmlHasNsProp(element, local, ns ? ns->href : NULL);
1182 xmlFree(local);
1184 else
1186 attr = xmlHasProp(element, nameA);
1187 /* attribute has attached namespace and we requested non-qualified
1188 name - it's a failure case */
1189 if (attr && attr->ns) attr = NULL;
1192 heap_free(nameA);
1194 if (attr)
1196 IUnknown *unk = create_attribute((xmlNodePtr)attr);
1197 hr = IUnknown_QueryInterface(unk, &IID_IXMLDOMAttribute, (void**)attributeNode);
1198 IUnknown_Release(unk);
1201 return hr;
1204 static HRESULT WINAPI domelem_setAttributeNode(
1205 IXMLDOMElement *iface,
1206 IXMLDOMAttribute* attribute,
1207 IXMLDOMAttribute** old)
1209 domelem *This = impl_from_IXMLDOMElement( iface );
1210 static const WCHAR xmlnsW[] = {'x','m','l','n','s',0};
1211 xmlChar *name, *value;
1212 BSTR nameW, prefix;
1213 xmlnode *attr_node;
1214 xmlAttrPtr attr;
1215 VARIANT valueW;
1216 HRESULT hr;
1218 FIXME("(%p)->(%p %p): semi-stub\n", This, attribute, old);
1220 if (!attribute) return E_INVALIDARG;
1222 attr_node = get_node_obj((IXMLDOMNode*)attribute);
1223 if (!attr_node) return E_FAIL;
1225 if (attr_node->parent)
1227 WARN("attempt to add already used attribute\n");
1228 return E_FAIL;
1231 hr = IXMLDOMAttribute_get_nodeName(attribute, &nameW);
1232 if (hr != S_OK) return hr;
1234 /* adding xmlns attribute doesn't change a tree or existing namespace definition */
1235 if (!strcmpW(nameW, xmlnsW))
1237 SysFreeString(nameW);
1238 return DISP_E_UNKNOWNNAME;
1241 hr = IXMLDOMAttribute_get_nodeValue(attribute, &valueW);
1242 if (hr != S_OK)
1244 SysFreeString(nameW);
1245 return hr;
1248 if (old) *old = NULL;
1250 TRACE("attribute: %s=%s\n", debugstr_w(nameW), debugstr_w(V_BSTR(&valueW)));
1252 hr = IXMLDOMAttribute_get_prefix(attribute, &prefix);
1253 if (hr == S_OK)
1255 FIXME("namespaces not supported: %s\n", debugstr_w(prefix));
1256 SysFreeString(prefix);
1259 name = xmlchar_from_wchar(nameW);
1260 value = xmlchar_from_wchar(V_BSTR(&valueW));
1262 if (!name || !value)
1264 SysFreeString(nameW);
1265 VariantClear(&valueW);
1266 heap_free(name);
1267 heap_free(value);
1268 return E_OUTOFMEMORY;
1271 attr = xmlSetNsProp(get_element(This), NULL, name, value);
1272 if (attr)
1273 attr_node->parent = (IXMLDOMNode*)iface;
1275 SysFreeString(nameW);
1276 VariantClear(&valueW);
1277 heap_free(name);
1278 heap_free(value);
1280 return attr ? S_OK : E_FAIL;
1283 static HRESULT WINAPI domelem_removeAttributeNode(
1284 IXMLDOMElement *iface,
1285 IXMLDOMAttribute* domAttribute,
1286 IXMLDOMAttribute** attributeNode)
1288 domelem *This = impl_from_IXMLDOMElement( iface );
1289 FIXME("(%p)->(%p %p)\n", This, domAttribute, attributeNode);
1290 return E_NOTIMPL;
1293 static HRESULT WINAPI domelem_getElementsByTagName(
1294 IXMLDOMElement *iface,
1295 BSTR tagName, IXMLDOMNodeList** resultList)
1297 domelem *This = impl_from_IXMLDOMElement( iface );
1298 xmlChar *query;
1299 HRESULT hr;
1300 BOOL XPath;
1302 TRACE("(%p)->(%s, %p)\n", This, debugstr_w(tagName), resultList);
1304 if (!tagName || !resultList) return E_INVALIDARG;
1306 XPath = is_xpathmode(get_element(This)->doc);
1307 set_xpathmode(get_element(This)->doc, TRUE);
1308 query = tagName_to_XPath(tagName);
1309 hr = create_selection(get_element(This), query, resultList);
1310 xmlFree(query);
1311 set_xpathmode(get_element(This)->doc, XPath);
1313 return hr;
1316 static HRESULT WINAPI domelem_normalize(
1317 IXMLDOMElement *iface )
1319 domelem *This = impl_from_IXMLDOMElement( iface );
1320 FIXME("%p\n", This);
1321 return E_NOTIMPL;
1324 static const struct IXMLDOMElementVtbl domelem_vtbl =
1326 domelem_QueryInterface,
1327 domelem_AddRef,
1328 domelem_Release,
1329 domelem_GetTypeInfoCount,
1330 domelem_GetTypeInfo,
1331 domelem_GetIDsOfNames,
1332 domelem_Invoke,
1333 domelem_get_nodeName,
1334 domelem_get_nodeValue,
1335 domelem_put_nodeValue,
1336 domelem_get_nodeType,
1337 domelem_get_parentNode,
1338 domelem_get_childNodes,
1339 domelem_get_firstChild,
1340 domelem_get_lastChild,
1341 domelem_get_previousSibling,
1342 domelem_get_nextSibling,
1343 domelem_get_attributes,
1344 domelem_insertBefore,
1345 domelem_replaceChild,
1346 domelem_removeChild,
1347 domelem_appendChild,
1348 domelem_hasChildNodes,
1349 domelem_get_ownerDocument,
1350 domelem_cloneNode,
1351 domelem_get_nodeTypeString,
1352 domelem_get_text,
1353 domelem_put_text,
1354 domelem_get_specified,
1355 domelem_get_definition,
1356 domelem_get_nodeTypedValue,
1357 domelem_put_nodeTypedValue,
1358 domelem_get_dataType,
1359 domelem_put_dataType,
1360 domelem_get_xml,
1361 domelem_transformNode,
1362 domelem_selectNodes,
1363 domelem_selectSingleNode,
1364 domelem_get_parsed,
1365 domelem_get_namespaceURI,
1366 domelem_get_prefix,
1367 domelem_get_baseName,
1368 domelem_transformNodeToObject,
1369 domelem_get_tagName,
1370 domelem_getAttribute,
1371 domelem_setAttribute,
1372 domelem_removeAttribute,
1373 domelem_getAttributeNode,
1374 domelem_setAttributeNode,
1375 domelem_removeAttributeNode,
1376 domelem_getElementsByTagName,
1377 domelem_normalize,
1380 static HRESULT domelem_get_qualified_item(const xmlNodePtr node, BSTR name, BSTR uri,
1381 IXMLDOMNode **item)
1383 xmlAttrPtr attr;
1384 xmlChar *nameA;
1385 xmlChar *href;
1387 TRACE("(%p)->(%s %s %p)\n", node, debugstr_w(name), debugstr_w(uri), item);
1389 if (!name || !item) return E_INVALIDARG;
1391 if (uri && *uri)
1393 href = xmlchar_from_wchar(uri);
1394 if (!href) return E_OUTOFMEMORY;
1396 else
1397 href = NULL;
1399 nameA = xmlchar_from_wchar(name);
1400 if (!nameA)
1402 heap_free(href);
1403 return E_OUTOFMEMORY;
1406 attr = xmlHasNsProp(node, nameA, href);
1408 heap_free(nameA);
1409 heap_free(href);
1411 if (!attr)
1413 *item = NULL;
1414 return S_FALSE;
1417 *item = create_node((xmlNodePtr)attr);
1419 return S_OK;
1422 static HRESULT domelem_get_named_item(const xmlNodePtr node, BSTR name, IXMLDOMNode **item)
1424 xmlChar *nameA, *local, *prefix;
1425 BSTR uriW, localW;
1426 xmlNsPtr ns;
1427 HRESULT hr;
1429 TRACE("(%p)->(%s %p)\n", node, debugstr_w(name), item );
1431 nameA = xmlchar_from_wchar(name);
1432 local = xmlSplitQName2(nameA, &prefix);
1433 heap_free(nameA);
1435 if (!local)
1436 return domelem_get_qualified_item(node, name, NULL, item);
1438 /* try to get namespace uri for supplied qualified name */
1439 ns = xmlSearchNs(node->doc, node, prefix);
1441 xmlFree(prefix);
1443 if (!ns)
1445 xmlFree(local);
1446 if (item) *item = NULL;
1447 return item ? S_FALSE : E_INVALIDARG;
1450 uriW = bstr_from_xmlChar(ns->href);
1451 localW = bstr_from_xmlChar(local);
1452 xmlFree(local);
1454 TRACE("got qualified node %s, uri=%s\n", debugstr_w(localW), debugstr_w(uriW));
1456 hr = domelem_get_qualified_item(node, localW, uriW, item);
1458 SysFreeString(localW);
1459 SysFreeString(uriW);
1461 return hr;
1464 static HRESULT domelem_set_named_item(xmlNodePtr node, IXMLDOMNode *newItem, IXMLDOMNode **namedItem)
1466 xmlNodePtr nodeNew;
1467 xmlnode *ThisNew;
1469 TRACE("(%p)->(%p %p)\n", node, newItem, namedItem );
1471 if(!newItem)
1472 return E_INVALIDARG;
1474 if(namedItem) *namedItem = NULL;
1476 /* Must be an Attribute */
1477 ThisNew = get_node_obj( newItem );
1478 if(!ThisNew) return E_FAIL;
1480 if(ThisNew->node->type != XML_ATTRIBUTE_NODE)
1481 return E_FAIL;
1483 if(!ThisNew->node->parent)
1484 if(xmldoc_remove_orphan(ThisNew->node->doc, ThisNew->node) != S_OK)
1485 WARN("%p is not an orphan of %p\n", ThisNew->node, ThisNew->node->doc);
1487 nodeNew = xmlAddChild(node, ThisNew->node);
1489 if(namedItem)
1490 *namedItem = create_node( nodeNew );
1491 return S_OK;
1494 static HRESULT domelem_remove_qualified_item(xmlNodePtr node, BSTR name, BSTR uri, IXMLDOMNode **item)
1496 xmlChar *nameA, *href;
1497 xmlAttrPtr attr;
1499 TRACE("(%p)->(%s %s %p)\n", node, debugstr_w(name), debugstr_w(uri), item);
1501 if (!name) return E_INVALIDARG;
1503 if (uri && *uri)
1505 href = xmlchar_from_wchar(uri);
1506 if (!href) return E_OUTOFMEMORY;
1508 else
1509 href = NULL;
1511 nameA = xmlchar_from_wchar(name);
1512 if (!nameA)
1514 heap_free(href);
1515 return E_OUTOFMEMORY;
1518 attr = xmlHasNsProp(node, nameA, href);
1520 heap_free(nameA);
1521 heap_free(href);
1523 if (!attr)
1525 if (item) *item = NULL;
1526 return S_FALSE;
1529 if (item)
1531 xmlUnlinkNode( (xmlNodePtr) attr );
1532 xmldoc_add_orphan( attr->doc, (xmlNodePtr) attr );
1533 *item = create_node( (xmlNodePtr) attr );
1535 else
1537 if (xmlRemoveProp(attr) == -1)
1538 ERR("xmlRemoveProp failed\n");
1541 return S_OK;
1544 static HRESULT domelem_remove_named_item(xmlNodePtr node, BSTR name, IXMLDOMNode **item)
1546 TRACE("(%p)->(%s %p)\n", node, debugstr_w(name), item);
1547 return domelem_remove_qualified_item(node, name, NULL, item);
1550 static HRESULT domelem_get_item(const xmlNodePtr node, LONG index, IXMLDOMNode **item)
1552 xmlAttrPtr curr;
1553 LONG attrIndex;
1555 TRACE("(%p)->(%d %p)\n", node, index, item);
1557 *item = NULL;
1559 if (index < 0)
1560 return S_FALSE;
1562 curr = node->properties;
1564 for (attrIndex = 0; attrIndex < index; attrIndex++) {
1565 if (curr->next == NULL)
1566 return S_FALSE;
1567 else
1568 curr = curr->next;
1571 *item = create_node( (xmlNodePtr) curr );
1573 return S_OK;
1576 static HRESULT domelem_get_length(const xmlNodePtr node, LONG *length)
1578 xmlAttrPtr first;
1579 xmlAttrPtr curr;
1580 LONG attrCount;
1582 TRACE("(%p)->(%p)\n", node, length);
1584 if( !length )
1585 return E_INVALIDARG;
1587 first = node->properties;
1588 if (first == NULL) {
1589 *length = 0;
1590 return S_OK;
1593 curr = first;
1594 attrCount = 1;
1595 while (curr->next) {
1596 attrCount++;
1597 curr = curr->next;
1599 *length = attrCount;
1601 return S_OK;
1604 static HRESULT domelem_next_node(const xmlNodePtr node, LONG *iter, IXMLDOMNode **nextNode)
1606 xmlAttrPtr curr;
1607 LONG i;
1609 TRACE("(%p)->(%d: %p)\n", node, *iter, nextNode);
1611 *nextNode = NULL;
1613 curr = node->properties;
1615 for (i = 0; i < *iter; i++) {
1616 if (curr->next == NULL)
1617 return S_FALSE;
1618 else
1619 curr = curr->next;
1622 (*iter)++;
1623 *nextNode = create_node((xmlNodePtr)curr);
1625 return S_OK;
1628 static const struct nodemap_funcs domelem_attr_map = {
1629 domelem_get_named_item,
1630 domelem_set_named_item,
1631 domelem_remove_named_item,
1632 domelem_get_item,
1633 domelem_get_length,
1634 domelem_get_qualified_item,
1635 domelem_remove_qualified_item,
1636 domelem_next_node
1639 static const tid_t domelem_iface_tids[] = {
1640 IXMLDOMElement_tid,
1644 static dispex_static_data_t domelem_dispex = {
1645 NULL,
1646 IXMLDOMElement_tid,
1647 NULL,
1648 domelem_iface_tids
1651 IUnknown* create_element( xmlNodePtr element )
1653 domelem *This;
1655 This = heap_alloc( sizeof *This );
1656 if ( !This )
1657 return NULL;
1659 This->IXMLDOMElement_iface.lpVtbl = &domelem_vtbl;
1660 This->ref = 1;
1662 init_xmlnode(&This->node, element, (IXMLDOMNode*)&This->IXMLDOMElement_iface, &domelem_dispex);
1664 return (IUnknown*)&This->IXMLDOMElement_iface;
1667 #endif