hhctrl.ocx: Add a missing Release call.
[wine/multimedia.git] / dlls / msxml3 / element.c
blobe760c8493e1cef4ac3e7814e68b4ba3bf9a69b07
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;
647 default:
648 WARN("unknown type %d\n", dt);
651 if (!handled)
653 V_VT(&src) = VT_BSTR;
654 V_BSTR(&src) = bstr_from_xmlChar(str);
656 if(!V_BSTR(&src))
657 return E_OUTOFMEMORY;
659 hr = VariantChangeTypeEx(v, &src,
660 MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT),0, V_VT(v));
661 VariantClear(&src);
663 return hr;
666 static XDR_DT element_get_dt(xmlNodePtr node)
668 XDR_DT dt = DT_INVALID;
670 TRACE("(%p)\n", node);
671 if(node->type != XML_ELEMENT_NODE)
673 FIXME("invalid element node\n");
674 return dt;
677 if (node->ns && xmlStrEqual(node->ns->href, DT_nsURI))
679 dt = str_to_dt(node->name, -1);
681 else
683 xmlChar* pVal = xmlGetNsProp(node, BAD_CAST "dt", DT_nsURI);
684 if (pVal)
686 dt = str_to_dt(pVal, -1);
687 xmlFree(pVal);
689 else if (node->doc)
691 IXMLDOMDocument3* doc = (IXMLDOMDocument3*)create_domdoc((xmlNodePtr)node->doc);
692 if (doc)
694 VARIANT v;
695 VariantInit(&v);
697 if (IXMLDOMDocument3_get_schemas(doc, &v) == S_OK &&
698 V_VT(&v) == VT_DISPATCH)
700 dt = SchemaCache_get_node_dt((IXMLDOMSchemaCollection2*)V_DISPATCH(&v), node);
702 VariantClear(&v);
703 IXMLDOMDocument3_Release(doc);
708 TRACE("=> dt:%s\n", debugstr_dt(dt));
709 return dt;
712 static HRESULT WINAPI domelem_get_nodeTypedValue(
713 IXMLDOMElement *iface,
714 VARIANT* v)
716 domelem *This = impl_from_IXMLDOMElement( iface );
717 XDR_DT dt;
718 xmlChar* content;
719 HRESULT hr;
721 TRACE("(%p)->(%p)\n", This, v);
723 if(!v) return E_INVALIDARG;
725 V_VT(v) = VT_NULL;
727 dt = element_get_dt(get_element(This));
728 content = xmlNodeGetContent(get_element(This));
729 hr = variant_from_dt(dt, content, v);
730 xmlFree(content);
732 return hr;
735 static HRESULT WINAPI domelem_put_nodeTypedValue(
736 IXMLDOMElement *iface,
737 VARIANT value)
739 domelem *This = impl_from_IXMLDOMElement( iface );
740 XDR_DT dt;
741 HRESULT hr;
743 TRACE("(%p)->(%s)\n", This, debugstr_variant(&value));
745 dt = element_get_dt(get_element(This));
746 /* for untyped node coerce to BSTR and set */
747 if (dt == DT_INVALID)
749 if (V_VT(&value) != VT_BSTR)
751 VARIANT content;
752 VariantInit(&content);
753 hr = VariantChangeType(&content, &value, 0, VT_BSTR);
754 if (hr == S_OK)
756 hr = node_set_content(&This->node, V_BSTR(&content));
757 VariantClear(&content);
760 else
761 hr = node_set_content(&This->node, V_BSTR(&value));
763 else
765 FIXME("not implemented for dt:%s\n", debugstr_dt(dt));
766 return E_NOTIMPL;
769 return hr;
772 static HRESULT WINAPI domelem_get_dataType(
773 IXMLDOMElement *iface,
774 VARIANT* typename)
776 domelem *This = impl_from_IXMLDOMElement( iface );
777 XDR_DT dt;
779 TRACE("(%p)->(%p)\n", This, typename);
781 if (!typename)
782 return E_INVALIDARG;
784 dt = element_get_dt(get_element(This));
785 switch (dt)
787 case DT_BIN_BASE64:
788 case DT_BIN_HEX:
789 case DT_BOOLEAN:
790 case DT_CHAR:
791 case DT_DATE:
792 case DT_DATE_TZ:
793 case DT_DATETIME:
794 case DT_DATETIME_TZ:
795 case DT_FIXED_14_4:
796 case DT_FLOAT:
797 case DT_I1:
798 case DT_I2:
799 case DT_I4:
800 case DT_I8:
801 case DT_INT:
802 case DT_NUMBER:
803 case DT_R4:
804 case DT_R8:
805 case DT_TIME:
806 case DT_TIME_TZ:
807 case DT_UI1:
808 case DT_UI2:
809 case DT_UI4:
810 case DT_UI8:
811 case DT_URI:
812 case DT_UUID:
813 V_VT(typename) = VT_BSTR;
814 V_BSTR(typename) = SysAllocString(dt_to_bstr(dt));
816 if (!V_BSTR(typename))
817 return E_OUTOFMEMORY;
818 break;
819 default:
820 /* Other types (DTD equivalents) do not return anything here,
821 * but the pointer part of the VARIANT is set to NULL */
822 V_VT(typename) = VT_NULL;
823 V_BSTR(typename) = NULL;
824 break;
826 return (V_VT(typename) != VT_NULL) ? S_OK : S_FALSE;
829 static HRESULT WINAPI domelem_put_dataType(
830 IXMLDOMElement *iface,
831 BSTR dtName)
833 domelem *This = impl_from_IXMLDOMElement( iface );
834 HRESULT hr = E_FAIL;
835 xmlChar *str;
836 XDR_DT dt;
838 TRACE("(%p)->(%s)\n", This, debugstr_w(dtName));
840 if(dtName == NULL)
841 return E_INVALIDARG;
843 dt = bstr_to_dt(dtName, -1);
845 /* An example of this is. The Text in the node needs to be a 0 or 1 for a boolean type.
846 This applies to changing types (string->bool) or setting a new one
848 str = xmlNodeGetContent(get_element(This));
849 hr = dt_validate(dt, str);
850 xmlFree(str);
852 /* Check all supported types. */
853 if (hr == S_OK)
855 switch (dt)
857 case DT_BIN_BASE64:
858 case DT_BIN_HEX:
859 case DT_BOOLEAN:
860 case DT_CHAR:
861 case DT_DATE:
862 case DT_DATE_TZ:
863 case DT_DATETIME:
864 case DT_DATETIME_TZ:
865 case DT_FIXED_14_4:
866 case DT_FLOAT:
867 case DT_I1:
868 case DT_I2:
869 case DT_I4:
870 case DT_I8:
871 case DT_INT:
872 case DT_NMTOKEN:
873 case DT_NMTOKENS:
874 case DT_NUMBER:
875 case DT_R4:
876 case DT_R8:
877 case DT_STRING:
878 case DT_TIME:
879 case DT_TIME_TZ:
880 case DT_UI1:
881 case DT_UI2:
882 case DT_UI4:
883 case DT_UI8:
884 case DT_URI:
885 case DT_UUID:
887 xmlAttrPtr attr = xmlHasNsProp(get_element(This), DT_prefix, DT_nsURI);
888 if (attr)
890 attr = xmlSetNsProp(get_element(This), attr->ns, DT_prefix, dt_to_str(dt));
891 hr = S_OK;
893 else
895 xmlNsPtr ns = xmlNewNs(get_element(This), DT_nsURI, DT_prefix);
896 if (ns)
898 attr = xmlNewNsProp(get_element(This), ns, DT_prefix, dt_to_str(dt));
899 if (attr)
901 xmlAddChild(get_element(This), (xmlNodePtr)attr);
902 hr = S_OK;
904 else
905 ERR("Failed to create Attribute\n");
907 else
908 ERR("Failed to create Namespace\n");
911 break;
912 default:
913 FIXME("need to handle dt:%s\n", debugstr_dt(dt));
914 break;
918 return hr;
921 static HRESULT WINAPI domelem_get_xml(
922 IXMLDOMElement *iface,
923 BSTR* p)
925 domelem *This = impl_from_IXMLDOMElement( iface );
927 TRACE("(%p)->(%p)\n", This, p);
929 return node_get_xml(&This->node, TRUE, FALSE, p);
932 static HRESULT WINAPI domelem_transformNode(
933 IXMLDOMElement *iface,
934 IXMLDOMNode *node, BSTR *p)
936 domelem *This = impl_from_IXMLDOMElement( iface );
937 TRACE("(%p)->(%p %p)\n", This, node, p);
938 return node_transform_node(&This->node, node, p);
941 static HRESULT WINAPI domelem_selectNodes(
942 IXMLDOMElement *iface,
943 BSTR p, IXMLDOMNodeList** outList)
945 domelem *This = impl_from_IXMLDOMElement( iface );
946 TRACE("(%p)->(%s %p)\n", This, debugstr_w(p), outList);
947 return node_select_nodes(&This->node, p, outList);
950 static HRESULT WINAPI domelem_selectSingleNode(
951 IXMLDOMElement *iface,
952 BSTR p, IXMLDOMNode** outNode)
954 domelem *This = impl_from_IXMLDOMElement( iface );
955 TRACE("(%p)->(%s %p)\n", This, debugstr_w(p), outNode);
956 return node_select_singlenode(&This->node, p, outNode);
959 static HRESULT WINAPI domelem_get_parsed(
960 IXMLDOMElement *iface,
961 VARIANT_BOOL* isParsed)
963 domelem *This = impl_from_IXMLDOMElement( iface );
964 FIXME("(%p)->(%p) stub!\n", This, isParsed);
965 *isParsed = VARIANT_TRUE;
966 return S_OK;
969 static HRESULT WINAPI domelem_get_namespaceURI(
970 IXMLDOMElement *iface,
971 BSTR* p)
973 domelem *This = impl_from_IXMLDOMElement( iface );
974 TRACE("(%p)->(%p)\n", This, p);
975 return node_get_namespaceURI(&This->node, p);
978 static HRESULT WINAPI domelem_get_prefix(
979 IXMLDOMElement *iface,
980 BSTR* prefix)
982 domelem *This = impl_from_IXMLDOMElement( iface );
983 TRACE("(%p)->(%p)\n", This, prefix);
984 return node_get_prefix( &This->node, prefix );
987 static HRESULT WINAPI domelem_get_baseName(
988 IXMLDOMElement *iface,
989 BSTR* name)
991 domelem *This = impl_from_IXMLDOMElement( iface );
992 TRACE("(%p)->(%p)\n", This, name);
993 return node_get_base_name( &This->node, name );
996 static HRESULT WINAPI domelem_transformNodeToObject(
997 IXMLDOMElement *iface,
998 IXMLDOMNode* domNode, VARIANT var1)
1000 domelem *This = impl_from_IXMLDOMElement( iface );
1001 FIXME("(%p)->(%p %s)\n", This, domNode, debugstr_variant(&var1));
1002 return E_NOTIMPL;
1005 static HRESULT WINAPI domelem_get_tagName(
1006 IXMLDOMElement *iface,
1007 BSTR* p)
1009 domelem *This = impl_from_IXMLDOMElement( iface );
1010 xmlNodePtr element;
1011 const xmlChar *prefix;
1012 xmlChar *qname;
1014 TRACE("(%p)->(%p)\n", This, p );
1016 if (!p) return E_INVALIDARG;
1018 element = get_element( This );
1019 if ( !element )
1020 return E_FAIL;
1022 prefix = element->ns ? element->ns->prefix : NULL;
1023 qname = xmlBuildQName(element->name, prefix, NULL, 0);
1025 *p = bstr_from_xmlChar(qname);
1026 if (qname != element->name) xmlFree(qname);
1028 return *p ? S_OK : E_OUTOFMEMORY;
1031 static HRESULT WINAPI domelem_getAttribute(
1032 IXMLDOMElement *iface,
1033 BSTR name, VARIANT* value)
1035 domelem *This = impl_from_IXMLDOMElement( iface );
1036 xmlNodePtr element;
1037 xmlChar *xml_name, *xml_value = NULL;
1038 HRESULT hr = S_FALSE;
1040 TRACE("(%p)->(%s %p)\n", This, debugstr_w(name), value);
1042 if(!value || !name)
1043 return E_INVALIDARG;
1045 element = get_element( This );
1046 if ( !element )
1047 return E_FAIL;
1049 V_BSTR(value) = NULL;
1050 V_VT(value) = VT_NULL;
1052 xml_name = xmlchar_from_wchar( name );
1054 if(!xmlValidateNameValue(xml_name))
1055 hr = E_FAIL;
1056 else
1057 xml_value = xmlGetNsProp(element, xml_name, NULL);
1059 heap_free(xml_name);
1060 if(xml_value)
1062 V_VT(value) = VT_BSTR;
1063 V_BSTR(value) = bstr_from_xmlChar( xml_value );
1064 xmlFree(xml_value);
1065 hr = S_OK;
1068 return hr;
1071 static HRESULT WINAPI domelem_setAttribute(
1072 IXMLDOMElement *iface,
1073 BSTR name, VARIANT value)
1075 domelem *This = impl_from_IXMLDOMElement( iface );
1076 xmlChar *xml_name, *xml_value, *local, *prefix;
1077 xmlNodePtr element;
1078 HRESULT hr;
1079 VARIANT var;
1081 TRACE("(%p)->(%s %s)\n", This, debugstr_w(name), debugstr_variant(&value));
1083 element = get_element( This );
1084 if ( !element )
1085 return E_FAIL;
1087 VariantInit(&var);
1088 hr = VariantChangeType(&var, &value, 0, VT_BSTR);
1089 if(hr != S_OK)
1091 FIXME("VariantChangeType failed\n");
1092 return hr;
1095 xml_name = xmlchar_from_wchar( name );
1096 xml_value = xmlchar_from_wchar( V_BSTR(&var) );
1098 if ((local = xmlSplitQName2(xml_name, &prefix)))
1100 static const xmlChar* xmlnsA = (const xmlChar*)"xmlns";
1101 xmlNsPtr ns = NULL;
1103 /* it's not allowed to modify existing namespace definition */
1104 if (xmlStrEqual(prefix, xmlnsA))
1105 ns = xmlSearchNs(element->doc, element, local);
1107 xmlFree(prefix);
1108 xmlFree(local);
1110 if (ns)
1111 return xmlStrEqual(ns->href, xml_value) ? S_OK : E_INVALIDARG;
1114 if (!xmlSetNsProp(element, NULL, xml_name, xml_value))
1115 hr = E_FAIL;
1117 heap_free(xml_value);
1118 heap_free(xml_name);
1119 VariantClear(&var);
1121 return hr;
1124 static HRESULT WINAPI domelem_removeAttribute(
1125 IXMLDOMElement *iface,
1126 BSTR p)
1128 domelem *This = impl_from_IXMLDOMElement( iface );
1129 IXMLDOMNamedNodeMap *attr;
1130 HRESULT hr;
1132 TRACE("(%p)->(%s)\n", This, debugstr_w(p));
1134 hr = IXMLDOMElement_get_attributes(iface, &attr);
1135 if (hr != S_OK) return hr;
1137 hr = IXMLDOMNamedNodeMap_removeNamedItem(attr, p, NULL);
1138 IXMLDOMNamedNodeMap_Release(attr);
1140 return hr;
1143 static HRESULT WINAPI domelem_getAttributeNode(
1144 IXMLDOMElement *iface,
1145 BSTR p, IXMLDOMAttribute** attributeNode )
1147 domelem *This = impl_from_IXMLDOMElement( iface );
1148 xmlChar *local, *prefix, *nameA;
1149 HRESULT hr = S_FALSE;
1150 xmlNodePtr element;
1151 xmlAttrPtr attr;
1153 TRACE("(%p)->(%s %p)\n", This, debugstr_w(p), attributeNode);
1155 element = get_element( This );
1156 if (!element) return E_FAIL;
1158 if (attributeNode) *attributeNode = NULL;
1160 nameA = xmlchar_from_wchar(p);
1161 if (!xmlValidateNameValue(nameA))
1163 heap_free(nameA);
1164 return E_FAIL;
1167 if (!attributeNode)
1169 heap_free(nameA);
1170 return S_FALSE;
1173 *attributeNode = NULL;
1175 local = xmlSplitQName2(nameA, &prefix);
1177 if (local)
1179 /* try to get namespace for supplied qualified name */
1180 xmlNsPtr ns = xmlSearchNs(element->doc, element, prefix);
1181 xmlFree(prefix);
1183 attr = xmlHasNsProp(element, local, ns ? ns->href : NULL);
1184 xmlFree(local);
1186 else
1188 attr = xmlHasProp(element, nameA);
1189 /* attribute has attached namespace and we requested non-qualified
1190 name - it's a failure case */
1191 if (attr && attr->ns) attr = NULL;
1194 heap_free(nameA);
1196 if (attr)
1198 IUnknown *unk = create_attribute((xmlNodePtr)attr);
1199 hr = IUnknown_QueryInterface(unk, &IID_IXMLDOMAttribute, (void**)attributeNode);
1200 IUnknown_Release(unk);
1203 return hr;
1206 static HRESULT WINAPI domelem_setAttributeNode(
1207 IXMLDOMElement *iface,
1208 IXMLDOMAttribute* attribute,
1209 IXMLDOMAttribute** old)
1211 domelem *This = impl_from_IXMLDOMElement( iface );
1212 static const WCHAR xmlnsW[] = {'x','m','l','n','s',0};
1213 xmlChar *name, *value;
1214 BSTR nameW, prefix;
1215 xmlnode *attr_node;
1216 xmlAttrPtr attr;
1217 VARIANT valueW;
1218 HRESULT hr;
1220 FIXME("(%p)->(%p %p): semi-stub\n", This, attribute, old);
1222 if (!attribute) return E_INVALIDARG;
1224 attr_node = get_node_obj((IXMLDOMNode*)attribute);
1225 if (!attr_node) return E_FAIL;
1227 if (attr_node->parent)
1229 WARN("attempt to add already used attribute\n");
1230 return E_FAIL;
1233 hr = IXMLDOMAttribute_get_nodeName(attribute, &nameW);
1234 if (hr != S_OK) return hr;
1236 /* adding xmlns attribute doesn't change a tree or existing namespace definition */
1237 if (!strcmpW(nameW, xmlnsW))
1239 SysFreeString(nameW);
1240 return DISP_E_UNKNOWNNAME;
1243 hr = IXMLDOMAttribute_get_nodeValue(attribute, &valueW);
1244 if (hr != S_OK)
1246 SysFreeString(nameW);
1247 return hr;
1250 if (old) *old = NULL;
1252 TRACE("attribute: %s=%s\n", debugstr_w(nameW), debugstr_w(V_BSTR(&valueW)));
1254 hr = IXMLDOMAttribute_get_prefix(attribute, &prefix);
1255 if (hr == S_OK)
1257 FIXME("namespaces not supported: %s\n", debugstr_w(prefix));
1258 SysFreeString(prefix);
1261 name = xmlchar_from_wchar(nameW);
1262 value = xmlchar_from_wchar(V_BSTR(&valueW));
1264 if (!name || !value)
1266 SysFreeString(nameW);
1267 VariantClear(&valueW);
1268 heap_free(name);
1269 heap_free(value);
1270 return E_OUTOFMEMORY;
1273 attr = xmlSetNsProp(get_element(This), NULL, name, value);
1274 if (attr)
1275 attr_node->parent = (IXMLDOMNode*)iface;
1277 SysFreeString(nameW);
1278 VariantClear(&valueW);
1279 heap_free(name);
1280 heap_free(value);
1282 return attr ? S_OK : E_FAIL;
1285 static HRESULT WINAPI domelem_removeAttributeNode(
1286 IXMLDOMElement *iface,
1287 IXMLDOMAttribute* domAttribute,
1288 IXMLDOMAttribute** attributeNode)
1290 domelem *This = impl_from_IXMLDOMElement( iface );
1291 FIXME("(%p)->(%p %p)\n", This, domAttribute, attributeNode);
1292 return E_NOTIMPL;
1295 static HRESULT WINAPI domelem_getElementsByTagName(
1296 IXMLDOMElement *iface,
1297 BSTR tagName, IXMLDOMNodeList** resultList)
1299 domelem *This = impl_from_IXMLDOMElement( iface );
1300 xmlChar *query;
1301 HRESULT hr;
1302 BOOL XPath;
1304 TRACE("(%p)->(%s, %p)\n", This, debugstr_w(tagName), resultList);
1306 if (!tagName || !resultList) return E_INVALIDARG;
1308 XPath = is_xpathmode(get_element(This)->doc);
1309 set_xpathmode(get_element(This)->doc, TRUE);
1310 query = tagName_to_XPath(tagName);
1311 hr = create_selection(get_element(This), query, resultList);
1312 xmlFree(query);
1313 set_xpathmode(get_element(This)->doc, XPath);
1315 return hr;
1318 static HRESULT WINAPI domelem_normalize(
1319 IXMLDOMElement *iface )
1321 domelem *This = impl_from_IXMLDOMElement( iface );
1322 FIXME("%p\n", This);
1323 return E_NOTIMPL;
1326 static const struct IXMLDOMElementVtbl domelem_vtbl =
1328 domelem_QueryInterface,
1329 domelem_AddRef,
1330 domelem_Release,
1331 domelem_GetTypeInfoCount,
1332 domelem_GetTypeInfo,
1333 domelem_GetIDsOfNames,
1334 domelem_Invoke,
1335 domelem_get_nodeName,
1336 domelem_get_nodeValue,
1337 domelem_put_nodeValue,
1338 domelem_get_nodeType,
1339 domelem_get_parentNode,
1340 domelem_get_childNodes,
1341 domelem_get_firstChild,
1342 domelem_get_lastChild,
1343 domelem_get_previousSibling,
1344 domelem_get_nextSibling,
1345 domelem_get_attributes,
1346 domelem_insertBefore,
1347 domelem_replaceChild,
1348 domelem_removeChild,
1349 domelem_appendChild,
1350 domelem_hasChildNodes,
1351 domelem_get_ownerDocument,
1352 domelem_cloneNode,
1353 domelem_get_nodeTypeString,
1354 domelem_get_text,
1355 domelem_put_text,
1356 domelem_get_specified,
1357 domelem_get_definition,
1358 domelem_get_nodeTypedValue,
1359 domelem_put_nodeTypedValue,
1360 domelem_get_dataType,
1361 domelem_put_dataType,
1362 domelem_get_xml,
1363 domelem_transformNode,
1364 domelem_selectNodes,
1365 domelem_selectSingleNode,
1366 domelem_get_parsed,
1367 domelem_get_namespaceURI,
1368 domelem_get_prefix,
1369 domelem_get_baseName,
1370 domelem_transformNodeToObject,
1371 domelem_get_tagName,
1372 domelem_getAttribute,
1373 domelem_setAttribute,
1374 domelem_removeAttribute,
1375 domelem_getAttributeNode,
1376 domelem_setAttributeNode,
1377 domelem_removeAttributeNode,
1378 domelem_getElementsByTagName,
1379 domelem_normalize,
1382 static HRESULT domelem_get_qualified_item(const xmlNodePtr node, BSTR name, BSTR uri,
1383 IXMLDOMNode **item)
1385 xmlAttrPtr attr;
1386 xmlChar *nameA;
1387 xmlChar *href;
1389 TRACE("(%p)->(%s %s %p)\n", node, debugstr_w(name), debugstr_w(uri), item);
1391 if (!name || !item) return E_INVALIDARG;
1393 if (uri && *uri)
1395 href = xmlchar_from_wchar(uri);
1396 if (!href) return E_OUTOFMEMORY;
1398 else
1399 href = NULL;
1401 nameA = xmlchar_from_wchar(name);
1402 if (!nameA)
1404 heap_free(href);
1405 return E_OUTOFMEMORY;
1408 attr = xmlHasNsProp(node, nameA, href);
1410 heap_free(nameA);
1411 heap_free(href);
1413 if (!attr)
1415 *item = NULL;
1416 return S_FALSE;
1419 *item = create_node((xmlNodePtr)attr);
1421 return S_OK;
1424 static HRESULT domelem_get_named_item(const xmlNodePtr node, BSTR name, IXMLDOMNode **item)
1426 xmlChar *nameA, *local, *prefix;
1427 BSTR uriW, localW;
1428 xmlNsPtr ns;
1429 HRESULT hr;
1431 TRACE("(%p)->(%s %p)\n", node, debugstr_w(name), item );
1433 nameA = xmlchar_from_wchar(name);
1434 local = xmlSplitQName2(nameA, &prefix);
1435 heap_free(nameA);
1437 if (!local)
1438 return domelem_get_qualified_item(node, name, NULL, item);
1440 /* try to get namespace uri for supplied qualified name */
1441 ns = xmlSearchNs(node->doc, node, prefix);
1443 xmlFree(prefix);
1445 if (!ns)
1447 xmlFree(local);
1448 if (item) *item = NULL;
1449 return item ? S_FALSE : E_INVALIDARG;
1452 uriW = bstr_from_xmlChar(ns->href);
1453 localW = bstr_from_xmlChar(local);
1454 xmlFree(local);
1456 TRACE("got qualified node %s, uri=%s\n", debugstr_w(localW), debugstr_w(uriW));
1458 hr = domelem_get_qualified_item(node, localW, uriW, item);
1460 SysFreeString(localW);
1461 SysFreeString(uriW);
1463 return hr;
1466 static HRESULT domelem_set_named_item(xmlNodePtr node, IXMLDOMNode *newItem, IXMLDOMNode **namedItem)
1468 xmlNodePtr nodeNew;
1469 xmlnode *ThisNew;
1471 TRACE("(%p)->(%p %p)\n", node, newItem, namedItem );
1473 if(!newItem)
1474 return E_INVALIDARG;
1476 if(namedItem) *namedItem = NULL;
1478 /* Must be an Attribute */
1479 ThisNew = get_node_obj( newItem );
1480 if(!ThisNew) return E_FAIL;
1482 if(ThisNew->node->type != XML_ATTRIBUTE_NODE)
1483 return E_FAIL;
1485 if(!ThisNew->node->parent)
1486 if(xmldoc_remove_orphan(ThisNew->node->doc, ThisNew->node) != S_OK)
1487 WARN("%p is not an orphan of %p\n", ThisNew->node, ThisNew->node->doc);
1489 nodeNew = xmlAddChild(node, ThisNew->node);
1491 if(namedItem)
1492 *namedItem = create_node( nodeNew );
1493 return S_OK;
1496 static HRESULT domelem_remove_qualified_item(xmlNodePtr node, BSTR name, BSTR uri, IXMLDOMNode **item)
1498 xmlChar *nameA, *href;
1499 xmlAttrPtr attr;
1501 TRACE("(%p)->(%s %s %p)\n", node, debugstr_w(name), debugstr_w(uri), item);
1503 if (!name) return E_INVALIDARG;
1505 if (uri && *uri)
1507 href = xmlchar_from_wchar(uri);
1508 if (!href) return E_OUTOFMEMORY;
1510 else
1511 href = NULL;
1513 nameA = xmlchar_from_wchar(name);
1514 if (!nameA)
1516 heap_free(href);
1517 return E_OUTOFMEMORY;
1520 attr = xmlHasNsProp(node, nameA, href);
1522 heap_free(nameA);
1523 heap_free(href);
1525 if (!attr)
1527 if (item) *item = NULL;
1528 return S_FALSE;
1531 if (item)
1533 xmlUnlinkNode( (xmlNodePtr) attr );
1534 xmldoc_add_orphan( attr->doc, (xmlNodePtr) attr );
1535 *item = create_node( (xmlNodePtr) attr );
1537 else
1539 if (xmlRemoveProp(attr) == -1)
1540 ERR("xmlRemoveProp failed\n");
1543 return S_OK;
1546 static HRESULT domelem_remove_named_item(xmlNodePtr node, BSTR name, IXMLDOMNode **item)
1548 TRACE("(%p)->(%s %p)\n", node, debugstr_w(name), item);
1549 return domelem_remove_qualified_item(node, name, NULL, item);
1552 static HRESULT domelem_get_item(const xmlNodePtr node, LONG index, IXMLDOMNode **item)
1554 xmlAttrPtr curr;
1555 LONG attrIndex;
1557 TRACE("(%p)->(%d %p)\n", node, index, item);
1559 *item = NULL;
1561 if (index < 0)
1562 return S_FALSE;
1564 curr = node->properties;
1566 for (attrIndex = 0; attrIndex < index; attrIndex++) {
1567 if (curr->next == NULL)
1568 return S_FALSE;
1569 else
1570 curr = curr->next;
1573 *item = create_node( (xmlNodePtr) curr );
1575 return S_OK;
1578 static HRESULT domelem_get_length(const xmlNodePtr node, LONG *length)
1580 xmlAttrPtr first;
1581 xmlAttrPtr curr;
1582 LONG attrCount;
1584 TRACE("(%p)->(%p)\n", node, length);
1586 if( !length )
1587 return E_INVALIDARG;
1589 first = node->properties;
1590 if (first == NULL) {
1591 *length = 0;
1592 return S_OK;
1595 curr = first;
1596 attrCount = 1;
1597 while (curr->next) {
1598 attrCount++;
1599 curr = curr->next;
1601 *length = attrCount;
1603 return S_OK;
1606 static HRESULT domelem_next_node(const xmlNodePtr node, LONG *iter, IXMLDOMNode **nextNode)
1608 xmlAttrPtr curr;
1609 LONG i;
1611 TRACE("(%p)->(%d: %p)\n", node, *iter, nextNode);
1613 *nextNode = NULL;
1615 curr = node->properties;
1617 for (i = 0; i < *iter; i++) {
1618 if (curr->next == NULL)
1619 return S_FALSE;
1620 else
1621 curr = curr->next;
1624 (*iter)++;
1625 *nextNode = create_node((xmlNodePtr)curr);
1627 return S_OK;
1630 static const struct nodemap_funcs domelem_attr_map = {
1631 domelem_get_named_item,
1632 domelem_set_named_item,
1633 domelem_remove_named_item,
1634 domelem_get_item,
1635 domelem_get_length,
1636 domelem_get_qualified_item,
1637 domelem_remove_qualified_item,
1638 domelem_next_node
1641 static const tid_t domelem_iface_tids[] = {
1642 IXMLDOMElement_tid,
1646 static dispex_static_data_t domelem_dispex = {
1647 NULL,
1648 IXMLDOMElement_tid,
1649 NULL,
1650 domelem_iface_tids
1653 IUnknown* create_element( xmlNodePtr element )
1655 domelem *This;
1657 This = heap_alloc( sizeof *This );
1658 if ( !This )
1659 return NULL;
1661 This->IXMLDOMElement_iface.lpVtbl = &domelem_vtbl;
1662 This->ref = 1;
1664 init_xmlnode(&This->node, element, (IXMLDOMNode*)&This->IXMLDOMElement_iface, &domelem_dispex);
1666 return (IUnknown*)&This->IXMLDOMElement_iface;
1669 #endif