2 * DOM Attribute implementation
4 * Copyright 2006 Huw Davies
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>
29 # include <libxml/HTMLtree.h>
38 #include "msxml_private.h"
40 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(msxml
);
46 static const xmlChar xmlns
[] = "xmlns";
48 typedef struct _domattr
51 IXMLDOMAttribute IXMLDOMAttribute_iface
;
56 static const tid_t domattr_se_tids
[] = {
62 static inline domattr
*impl_from_IXMLDOMAttribute( IXMLDOMAttribute
*iface
)
64 return CONTAINING_RECORD(iface
, domattr
, IXMLDOMAttribute_iface
);
67 static HRESULT WINAPI
domattr_QueryInterface(
68 IXMLDOMAttribute
*iface
,
72 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
73 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppvObject
);
75 if ( IsEqualGUID( riid
, &IID_IXMLDOMAttribute
) ||
76 IsEqualGUID( riid
, &IID_IXMLDOMNode
) ||
77 IsEqualGUID( riid
, &IID_IDispatch
) ||
78 IsEqualGUID( riid
, &IID_IUnknown
) )
82 else if(node_query_interface(&This
->node
, riid
, ppvObject
))
84 return *ppvObject
? S_OK
: E_NOINTERFACE
;
86 else if(IsEqualGUID( riid
, &IID_ISupportErrorInfo
))
88 return node_create_supporterrorinfo(domattr_se_tids
, ppvObject
);
92 TRACE("Unsupported interface %s\n", debugstr_guid(riid
));
97 IXMLDOMAttribute_AddRef(iface
);
101 static ULONG WINAPI
domattr_AddRef(
102 IXMLDOMAttribute
*iface
)
104 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
105 ULONG ref
= InterlockedIncrement( &This
->ref
);
106 TRACE("(%p)->(%d)\n", This
, ref
);
110 static ULONG WINAPI
domattr_Release(
111 IXMLDOMAttribute
*iface
)
113 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
114 ULONG ref
= InterlockedDecrement( &This
->ref
);
116 TRACE("(%p)->(%d)\n", This
, ref
);
119 destroy_xmlnode(&This
->node
);
120 if ( This
->floating
)
122 xmlFreeNs( This
->node
.node
->ns
);
123 xmlFreeNode( This
->node
.node
);
131 static HRESULT WINAPI
domattr_GetTypeInfoCount(
132 IXMLDOMAttribute
*iface
,
135 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
136 return IDispatchEx_GetTypeInfoCount(&This
->node
.dispex
.IDispatchEx_iface
, pctinfo
);
139 static HRESULT WINAPI
domattr_GetTypeInfo(
140 IXMLDOMAttribute
*iface
,
141 UINT iTInfo
, LCID lcid
,
142 ITypeInfo
** ppTInfo
)
144 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
145 return IDispatchEx_GetTypeInfo(&This
->node
.dispex
.IDispatchEx_iface
,
146 iTInfo
, lcid
, ppTInfo
);
149 static HRESULT WINAPI
domattr_GetIDsOfNames(
150 IXMLDOMAttribute
*iface
,
151 REFIID riid
, LPOLESTR
* rgszNames
,
152 UINT cNames
, LCID lcid
, DISPID
* rgDispId
)
154 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
155 return IDispatchEx_GetIDsOfNames(&This
->node
.dispex
.IDispatchEx_iface
,
156 riid
, rgszNames
, cNames
, lcid
, rgDispId
);
159 static HRESULT WINAPI
domattr_Invoke(
160 IXMLDOMAttribute
*iface
,
161 DISPID dispIdMember
, REFIID riid
, LCID lcid
,
162 WORD wFlags
, DISPPARAMS
* pDispParams
, VARIANT
* pVarResult
,
163 EXCEPINFO
* pExcepInfo
, UINT
* puArgErr
)
165 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
166 return IDispatchEx_Invoke(&This
->node
.dispex
.IDispatchEx_iface
,
167 dispIdMember
, riid
, lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
170 static HRESULT WINAPI
domattr_get_nodeName(
171 IXMLDOMAttribute
*iface
,
174 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
176 TRACE("(%p)->(%p)\n", This
, p
);
178 return node_get_nodeName(&This
->node
, p
);
181 static HRESULT WINAPI
domattr_get_nodeValue(
182 IXMLDOMAttribute
*iface
,
185 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
187 TRACE("(%p)->(%p)\n", This
, value
);
189 return node_get_content(&This
->node
, value
);
192 static HRESULT WINAPI
domattr_put_nodeValue(
193 IXMLDOMAttribute
*iface
,
196 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
198 TRACE("(%p)->(%s)\n", This
, debugstr_variant(&value
));
200 return node_put_value_escaped(&This
->node
, &value
);
203 static HRESULT WINAPI
domattr_get_nodeType(
204 IXMLDOMAttribute
*iface
,
205 DOMNodeType
* domNodeType
)
207 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
209 TRACE("(%p)->(%p)\n", This
, domNodeType
);
211 *domNodeType
= NODE_ATTRIBUTE
;
215 static HRESULT WINAPI
domattr_get_parentNode(
216 IXMLDOMAttribute
*iface
,
217 IXMLDOMNode
** parent
)
219 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
220 TRACE("(%p)->(%p)\n", This
, parent
);
221 if (!parent
) return E_INVALIDARG
;
226 static HRESULT WINAPI
domattr_get_childNodes(
227 IXMLDOMAttribute
*iface
,
228 IXMLDOMNodeList
** outList
)
230 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
232 TRACE("(%p)->(%p)\n", This
, outList
);
234 return node_get_child_nodes(&This
->node
, outList
);
237 static HRESULT WINAPI
domattr_get_firstChild(
238 IXMLDOMAttribute
*iface
,
239 IXMLDOMNode
** domNode
)
241 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
243 TRACE("(%p)->(%p)\n", This
, domNode
);
245 return node_get_first_child(&This
->node
, domNode
);
248 static HRESULT WINAPI
domattr_get_lastChild(
249 IXMLDOMAttribute
*iface
,
250 IXMLDOMNode
** domNode
)
252 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
254 TRACE("(%p)->(%p)\n", This
, domNode
);
256 return node_get_last_child(&This
->node
, domNode
);
259 static HRESULT WINAPI
domattr_get_previousSibling(
260 IXMLDOMAttribute
*iface
,
261 IXMLDOMNode
** domNode
)
263 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
265 TRACE("(%p)->(%p)\n", This
, domNode
);
267 return return_null_node(domNode
);
270 static HRESULT WINAPI
domattr_get_nextSibling(
271 IXMLDOMAttribute
*iface
,
272 IXMLDOMNode
** domNode
)
274 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
276 TRACE("(%p)->(%p)\n", This
, domNode
);
278 return return_null_node(domNode
);
281 static HRESULT WINAPI
domattr_get_attributes(
282 IXMLDOMAttribute
*iface
,
283 IXMLDOMNamedNodeMap
** attributeMap
)
285 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
287 TRACE("(%p)->(%p)\n", This
, attributeMap
);
289 return return_null_ptr((void**)attributeMap
);
292 static HRESULT WINAPI
domattr_insertBefore(
293 IXMLDOMAttribute
*iface
,
294 IXMLDOMNode
* newNode
, VARIANT refChild
,
295 IXMLDOMNode
** old_node
)
297 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
301 FIXME("(%p)->(%p %s %p) needs test\n", This
, newNode
, debugstr_variant(&refChild
), old_node
);
303 if (!newNode
) return E_INVALIDARG
;
305 hr
= IXMLDOMNode_get_nodeType(newNode
, &type
);
306 if (hr
!= S_OK
) return hr
;
308 TRACE("new node type %d\n", type
);
312 case NODE_CDATA_SECTION
:
315 case NODE_PROCESSING_INSTRUCTION
:
316 if (old_node
) *old_node
= NULL
;
319 return node_insert_before(&This
->node
, newNode
, &refChild
, old_node
);
323 static HRESULT WINAPI
domattr_replaceChild(
324 IXMLDOMAttribute
*iface
,
325 IXMLDOMNode
* newNode
,
326 IXMLDOMNode
* oldNode
,
327 IXMLDOMNode
** outOldNode
)
329 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
331 FIXME("(%p)->(%p %p %p) needs tests\n", This
, newNode
, oldNode
, outOldNode
);
333 return node_replace_child(&This
->node
, newNode
, oldNode
, outOldNode
);
336 static HRESULT WINAPI
domattr_removeChild(
337 IXMLDOMAttribute
*iface
,
338 IXMLDOMNode
*child
, IXMLDOMNode
**oldChild
)
340 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
341 TRACE("(%p)->(%p %p)\n", This
, child
, oldChild
);
342 return node_remove_child(&This
->node
, child
, oldChild
);
345 static HRESULT WINAPI
domattr_appendChild(
346 IXMLDOMAttribute
*iface
,
347 IXMLDOMNode
*child
, IXMLDOMNode
**outChild
)
349 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
350 TRACE("(%p)->(%p %p)\n", This
, child
, outChild
);
351 return node_append_child(&This
->node
, child
, outChild
);
354 static HRESULT WINAPI
domattr_hasChildNodes(
355 IXMLDOMAttribute
*iface
,
358 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
359 TRACE("(%p)->(%p)\n", This
, ret
);
360 return node_has_childnodes(&This
->node
, ret
);
363 static HRESULT WINAPI
domattr_get_ownerDocument(
364 IXMLDOMAttribute
*iface
,
365 IXMLDOMDocument
**doc
)
367 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
368 TRACE("(%p)->(%p)\n", This
, doc
);
369 return node_get_owner_doc(&This
->node
, doc
);
372 static HRESULT WINAPI
domattr_cloneNode(
373 IXMLDOMAttribute
*iface
,
374 VARIANT_BOOL deep
, IXMLDOMNode
** outNode
)
376 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
377 TRACE("(%p)->(%d %p)\n", This
, deep
, outNode
);
378 return node_clone( &This
->node
, deep
, outNode
);
381 static HRESULT WINAPI
domattr_get_nodeTypeString(
382 IXMLDOMAttribute
*iface
,
385 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
386 static const WCHAR attributeW
[] = {'a','t','t','r','i','b','u','t','e',0};
388 TRACE("(%p)->(%p)\n", This
, p
);
390 return return_bstr(attributeW
, p
);
393 static HRESULT WINAPI
domattr_get_text(
394 IXMLDOMAttribute
*iface
,
397 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
398 TRACE("(%p)->(%p)\n", This
, p
);
399 return node_get_text(&This
->node
, p
);
402 static HRESULT WINAPI
domattr_put_text(
403 IXMLDOMAttribute
*iface
,
406 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
407 TRACE("(%p)->(%s)\n", This
, debugstr_w(p
));
408 return node_put_text( &This
->node
, p
);
411 static HRESULT WINAPI
domattr_get_specified(
412 IXMLDOMAttribute
*iface
,
413 VARIANT_BOOL
* isSpecified
)
415 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
416 FIXME("(%p)->(%p) stub!\n", This
, isSpecified
);
417 *isSpecified
= VARIANT_TRUE
;
421 static HRESULT WINAPI
domattr_get_definition(
422 IXMLDOMAttribute
*iface
,
423 IXMLDOMNode
** definitionNode
)
425 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
426 FIXME("(%p)->(%p)\n", This
, definitionNode
);
430 static HRESULT WINAPI
domattr_get_nodeTypedValue(
431 IXMLDOMAttribute
*iface
,
434 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
435 IXMLDOMDocument
*doc
;
438 TRACE("(%p)->(%p)\n", This
, value
);
440 hr
= IXMLDOMAttribute_get_ownerDocument(iface
, &doc
);
443 IXMLDOMDocument3
*doc3
;
445 hr
= IXMLDOMDocument_QueryInterface(doc
, &IID_IXMLDOMDocument3
, (void**)&doc3
);
446 IXMLDOMDocument_Release(doc
);
452 hr
= IXMLDOMDocument3_get_schemas(doc3
, &schemas
);
453 IXMLDOMDocument3_Release(doc3
);
456 return IXMLDOMAttribute_get_value(iface
, value
);
459 FIXME("need to query schema for attribute type\n");
460 VariantClear(&schemas
);
465 return return_null_var(value
);
468 static HRESULT WINAPI
domattr_put_nodeTypedValue(
469 IXMLDOMAttribute
*iface
,
472 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
473 FIXME("(%p)->(%s)\n", This
, debugstr_variant(&typedValue
));
477 static HRESULT WINAPI
domattr_get_dataType(
478 IXMLDOMAttribute
*iface
,
481 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
482 TRACE("(%p)->(%p)\n", This
, typename
);
483 return return_null_var( typename
);
486 static HRESULT WINAPI
domattr_put_dataType(
487 IXMLDOMAttribute
*iface
,
490 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
492 FIXME("(%p)->(%s)\n", This
, debugstr_w(p
));
500 static HRESULT WINAPI
domattr_get_xml(
501 IXMLDOMAttribute
*iface
,
504 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
506 TRACE("(%p)->(%p)\n", This
, p
);
508 return node_get_xml(&This
->node
, FALSE
, p
);
511 static HRESULT WINAPI
domattr_transformNode(
512 IXMLDOMAttribute
*iface
,
513 IXMLDOMNode
*node
, BSTR
*p
)
515 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
516 TRACE("(%p)->(%p %p)\n", This
, node
, p
);
517 return node_transform_node(&This
->node
, node
, p
);
520 static HRESULT WINAPI
domattr_selectNodes(
521 IXMLDOMAttribute
*iface
,
522 BSTR p
, IXMLDOMNodeList
** outList
)
524 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
525 TRACE("(%p)->(%s %p)\n", This
, debugstr_w(p
), outList
);
526 return node_select_nodes(&This
->node
, p
, outList
);
529 static HRESULT WINAPI
domattr_selectSingleNode(
530 IXMLDOMAttribute
*iface
,
531 BSTR p
, IXMLDOMNode
** outNode
)
533 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
534 TRACE("(%p)->(%s %p)\n", This
, debugstr_w(p
), outNode
);
535 return node_select_singlenode(&This
->node
, p
, outNode
);
538 static HRESULT WINAPI
domattr_get_parsed(
539 IXMLDOMAttribute
*iface
,
540 VARIANT_BOOL
* isParsed
)
542 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
543 FIXME("(%p)->(%p) stub!\n", This
, isParsed
);
544 *isParsed
= VARIANT_TRUE
;
548 static HRESULT WINAPI
domattr_get_namespaceURI(
549 IXMLDOMAttribute
*iface
,
552 static const WCHAR w3xmlns
[] = { 'h','t','t','p',':','/','/', 'w','w','w','.','w','3','.',
553 'o','r','g','/','2','0','0','0','/','x','m','l','n','s','/',0 };
554 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
555 xmlNsPtr ns
= This
->node
.node
->ns
;
557 TRACE("(%p)->(%p)\n", This
, p
);
566 /* special case for default namespace definition */
567 if (xmlStrEqual(This
->node
.node
->name
, xmlns
))
568 *p
= bstr_from_xmlChar(xmlns
);
569 else if (xmlStrEqual(ns
->prefix
, xmlns
))
571 if (xmldoc_version(This
->node
.node
->doc
) == MSXML6
)
572 *p
= SysAllocString(w3xmlns
);
574 *p
= SysAllocStringLen(NULL
, 0);
577 *p
= bstr_from_xmlChar(ns
->href
);
580 TRACE("uri: %s\n", debugstr_w(*p
));
582 return *p
? S_OK
: S_FALSE
;
585 static HRESULT WINAPI
domattr_get_prefix(
586 IXMLDOMAttribute
*iface
,
589 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
590 xmlNsPtr ns
= This
->node
.node
->ns
;
592 TRACE("(%p)->(%p)\n", This
, prefix
);
594 if (!prefix
) return E_INVALIDARG
;
600 /* special case for default namespace definition */
601 if (xmlStrEqual(This
->node
.node
->name
, xmlns
))
602 *prefix
= bstr_from_xmlChar(xmlns
);
604 *prefix
= bstr_from_xmlChar(ns
->prefix
);
607 TRACE("prefix: %s\n", debugstr_w(*prefix
));
609 return *prefix
? S_OK
: S_FALSE
;
612 static HRESULT WINAPI
domattr_get_baseName(
613 IXMLDOMAttribute
*iface
,
616 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
617 TRACE("(%p)->(%p)\n", This
, name
);
618 return node_get_base_name( &This
->node
, name
);
621 static HRESULT WINAPI
domattr_transformNodeToObject(
622 IXMLDOMAttribute
*iface
,
623 IXMLDOMNode
* domNode
, VARIANT var1
)
625 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
626 FIXME("(%p)->(%p %s)\n", This
, domNode
, debugstr_variant(&var1
));
630 static HRESULT WINAPI
domattr_get_name(
631 IXMLDOMAttribute
*iface
,
634 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
636 TRACE("(%p)->(%p)\n", This
, p
);
638 return node_get_nodeName(&This
->node
, p
);
641 static HRESULT WINAPI
domattr_get_value(
642 IXMLDOMAttribute
*iface
,
645 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
647 TRACE("(%p)->(%p)\n", This
, value
);
649 return node_get_content(&This
->node
, value
);
652 static HRESULT WINAPI
domattr_put_value(
653 IXMLDOMAttribute
*iface
,
656 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
658 TRACE("(%p)->(%s)\n", This
, debugstr_variant(&value
));
660 return node_put_value_escaped(&This
->node
, &value
);
663 static const struct IXMLDOMAttributeVtbl domattr_vtbl
=
665 domattr_QueryInterface
,
668 domattr_GetTypeInfoCount
,
670 domattr_GetIDsOfNames
,
672 domattr_get_nodeName
,
673 domattr_get_nodeValue
,
674 domattr_put_nodeValue
,
675 domattr_get_nodeType
,
676 domattr_get_parentNode
,
677 domattr_get_childNodes
,
678 domattr_get_firstChild
,
679 domattr_get_lastChild
,
680 domattr_get_previousSibling
,
681 domattr_get_nextSibling
,
682 domattr_get_attributes
,
683 domattr_insertBefore
,
684 domattr_replaceChild
,
687 domattr_hasChildNodes
,
688 domattr_get_ownerDocument
,
690 domattr_get_nodeTypeString
,
693 domattr_get_specified
,
694 domattr_get_definition
,
695 domattr_get_nodeTypedValue
,
696 domattr_put_nodeTypedValue
,
697 domattr_get_dataType
,
698 domattr_put_dataType
,
700 domattr_transformNode
,
702 domattr_selectSingleNode
,
704 domattr_get_namespaceURI
,
706 domattr_get_baseName
,
707 domattr_transformNodeToObject
,
713 static const tid_t domattr_iface_tids
[] = {
714 IXMLDOMAttribute_tid
,
718 static dispex_static_data_t domattr_dispex
= {
720 IXMLDOMAttribute_tid
,
725 IUnknown
* create_attribute( xmlNodePtr attribute
, BOOL floating
)
729 This
= heap_alloc( sizeof *This
);
733 This
->IXMLDOMAttribute_iface
.lpVtbl
= &domattr_vtbl
;
735 This
->floating
= floating
;
737 init_xmlnode(&This
->node
, attribute
, (IXMLDOMNode
*)&This
->IXMLDOMAttribute_iface
, &domattr_dispex
);
739 return (IUnknown
*)&This
->IXMLDOMAttribute_iface
;