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"
42 WINE_DEFAULT_DEBUG_CHANNEL(msxml
);
46 static const xmlChar xmlns
[] = "xmlns";
48 typedef struct _domattr
51 IXMLDOMAttribute IXMLDOMAttribute_iface
;
55 static const tid_t domattr_se_tids
[] = {
61 static inline domattr
*impl_from_IXMLDOMAttribute( IXMLDOMAttribute
*iface
)
63 return CONTAINING_RECORD(iface
, domattr
, IXMLDOMAttribute_iface
);
66 static HRESULT WINAPI
domattr_QueryInterface(
67 IXMLDOMAttribute
*iface
,
71 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
72 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppvObject
);
74 if ( IsEqualGUID( riid
, &IID_IXMLDOMAttribute
) ||
75 IsEqualGUID( riid
, &IID_IXMLDOMNode
) ||
76 IsEqualGUID( riid
, &IID_IDispatch
) ||
77 IsEqualGUID( riid
, &IID_IUnknown
) )
81 else if(node_query_interface(&This
->node
, riid
, ppvObject
))
83 return *ppvObject
? S_OK
: E_NOINTERFACE
;
85 else if(IsEqualGUID( riid
, &IID_ISupportErrorInfo
))
87 return node_create_supporterrorinfo(domattr_se_tids
, ppvObject
);
91 TRACE("Unsupported interface %s\n", debugstr_guid(riid
));
96 IXMLDOMAttribute_AddRef(iface
);
100 static ULONG WINAPI
domattr_AddRef(
101 IXMLDOMAttribute
*iface
)
103 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
104 ULONG ref
= InterlockedIncrement( &This
->ref
);
105 TRACE("(%p)->(%d)\n", This
, ref
);
109 static ULONG WINAPI
domattr_Release(
110 IXMLDOMAttribute
*iface
)
112 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
113 ULONG ref
= InterlockedDecrement( &This
->ref
);
115 TRACE("(%p)->(%d)\n", This
, ref
);
118 destroy_xmlnode(&This
->node
);
125 static HRESULT WINAPI
domattr_GetTypeInfoCount(
126 IXMLDOMAttribute
*iface
,
129 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
130 return IDispatchEx_GetTypeInfoCount(&This
->node
.dispex
.IDispatchEx_iface
, pctinfo
);
133 static HRESULT WINAPI
domattr_GetTypeInfo(
134 IXMLDOMAttribute
*iface
,
135 UINT iTInfo
, LCID lcid
,
136 ITypeInfo
** ppTInfo
)
138 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
139 return IDispatchEx_GetTypeInfo(&This
->node
.dispex
.IDispatchEx_iface
,
140 iTInfo
, lcid
, ppTInfo
);
143 static HRESULT WINAPI
domattr_GetIDsOfNames(
144 IXMLDOMAttribute
*iface
,
145 REFIID riid
, LPOLESTR
* rgszNames
,
146 UINT cNames
, LCID lcid
, DISPID
* rgDispId
)
148 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
149 return IDispatchEx_GetIDsOfNames(&This
->node
.dispex
.IDispatchEx_iface
,
150 riid
, rgszNames
, cNames
, lcid
, rgDispId
);
153 static HRESULT WINAPI
domattr_Invoke(
154 IXMLDOMAttribute
*iface
,
155 DISPID dispIdMember
, REFIID riid
, LCID lcid
,
156 WORD wFlags
, DISPPARAMS
* pDispParams
, VARIANT
* pVarResult
,
157 EXCEPINFO
* pExcepInfo
, UINT
* puArgErr
)
159 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
160 return IDispatchEx_Invoke(&This
->node
.dispex
.IDispatchEx_iface
,
161 dispIdMember
, riid
, lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
164 static HRESULT WINAPI
domattr_get_nodeName(
165 IXMLDOMAttribute
*iface
,
168 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
170 TRACE("(%p)->(%p)\n", This
, p
);
172 return node_get_nodeName(&This
->node
, p
);
175 static HRESULT WINAPI
domattr_get_nodeValue(
176 IXMLDOMAttribute
*iface
,
179 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
181 TRACE("(%p)->(%p)\n", This
, value
);
183 return node_get_content(&This
->node
, value
);
186 static HRESULT WINAPI
domattr_put_nodeValue(
187 IXMLDOMAttribute
*iface
,
190 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
192 TRACE("(%p)->(%s)\n", This
, debugstr_variant(&value
));
194 return node_put_value_escaped(&This
->node
, &value
);
197 static HRESULT WINAPI
domattr_get_nodeType(
198 IXMLDOMAttribute
*iface
,
199 DOMNodeType
* domNodeType
)
201 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
203 TRACE("(%p)->(%p)\n", This
, domNodeType
);
205 *domNodeType
= NODE_ATTRIBUTE
;
209 static HRESULT WINAPI
domattr_get_parentNode(
210 IXMLDOMAttribute
*iface
,
211 IXMLDOMNode
** parent
)
213 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
214 TRACE("(%p)->(%p)\n", This
, parent
);
215 if (!parent
) return E_INVALIDARG
;
220 static HRESULT WINAPI
domattr_get_childNodes(
221 IXMLDOMAttribute
*iface
,
222 IXMLDOMNodeList
** outList
)
224 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
226 TRACE("(%p)->(%p)\n", This
, outList
);
228 return node_get_child_nodes(&This
->node
, outList
);
231 static HRESULT WINAPI
domattr_get_firstChild(
232 IXMLDOMAttribute
*iface
,
233 IXMLDOMNode
** domNode
)
235 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
237 TRACE("(%p)->(%p)\n", This
, domNode
);
239 return node_get_first_child(&This
->node
, domNode
);
242 static HRESULT WINAPI
domattr_get_lastChild(
243 IXMLDOMAttribute
*iface
,
244 IXMLDOMNode
** domNode
)
246 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
248 TRACE("(%p)->(%p)\n", This
, domNode
);
250 return node_get_last_child(&This
->node
, domNode
);
253 static HRESULT WINAPI
domattr_get_previousSibling(
254 IXMLDOMAttribute
*iface
,
255 IXMLDOMNode
** domNode
)
257 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
259 TRACE("(%p)->(%p)\n", This
, domNode
);
261 return return_null_node(domNode
);
264 static HRESULT WINAPI
domattr_get_nextSibling(
265 IXMLDOMAttribute
*iface
,
266 IXMLDOMNode
** domNode
)
268 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
270 TRACE("(%p)->(%p)\n", This
, domNode
);
272 return return_null_node(domNode
);
275 static HRESULT WINAPI
domattr_get_attributes(
276 IXMLDOMAttribute
*iface
,
277 IXMLDOMNamedNodeMap
** attributeMap
)
279 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
281 TRACE("(%p)->(%p)\n", This
, attributeMap
);
283 return return_null_ptr((void**)attributeMap
);
286 static HRESULT WINAPI
domattr_insertBefore(
287 IXMLDOMAttribute
*iface
,
288 IXMLDOMNode
* newNode
, VARIANT refChild
,
289 IXMLDOMNode
** old_node
)
291 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
295 FIXME("(%p)->(%p %s %p) needs test\n", This
, newNode
, debugstr_variant(&refChild
), old_node
);
297 if (!newNode
) return E_INVALIDARG
;
299 hr
= IXMLDOMNode_get_nodeType(newNode
, &type
);
300 if (hr
!= S_OK
) return hr
;
302 TRACE("new node type %d\n", type
);
306 case NODE_CDATA_SECTION
:
309 case NODE_PROCESSING_INSTRUCTION
:
310 if (old_node
) *old_node
= NULL
;
313 return node_insert_before(&This
->node
, newNode
, &refChild
, old_node
);
317 static HRESULT WINAPI
domattr_replaceChild(
318 IXMLDOMAttribute
*iface
,
319 IXMLDOMNode
* newNode
,
320 IXMLDOMNode
* oldNode
,
321 IXMLDOMNode
** outOldNode
)
323 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
325 FIXME("(%p)->(%p %p %p) needs tests\n", This
, newNode
, oldNode
, outOldNode
);
327 return node_replace_child(&This
->node
, newNode
, oldNode
, outOldNode
);
330 static HRESULT WINAPI
domattr_removeChild(
331 IXMLDOMAttribute
*iface
,
332 IXMLDOMNode
*child
, IXMLDOMNode
**oldChild
)
334 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
335 TRACE("(%p)->(%p %p)\n", This
, child
, oldChild
);
336 return node_remove_child(&This
->node
, child
, oldChild
);
339 static HRESULT WINAPI
domattr_appendChild(
340 IXMLDOMAttribute
*iface
,
341 IXMLDOMNode
*child
, IXMLDOMNode
**outChild
)
343 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
344 TRACE("(%p)->(%p %p)\n", This
, child
, outChild
);
345 return node_append_child(&This
->node
, child
, outChild
);
348 static HRESULT WINAPI
domattr_hasChildNodes(
349 IXMLDOMAttribute
*iface
,
352 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
353 TRACE("(%p)->(%p)\n", This
, ret
);
354 return node_has_childnodes(&This
->node
, ret
);
357 static HRESULT WINAPI
domattr_get_ownerDocument(
358 IXMLDOMAttribute
*iface
,
359 IXMLDOMDocument
**doc
)
361 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
362 TRACE("(%p)->(%p)\n", This
, doc
);
363 return node_get_owner_doc(&This
->node
, doc
);
366 static HRESULT WINAPI
domattr_cloneNode(
367 IXMLDOMAttribute
*iface
,
368 VARIANT_BOOL deep
, IXMLDOMNode
** outNode
)
370 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
371 TRACE("(%p)->(%d %p)\n", This
, deep
, outNode
);
372 return node_clone( &This
->node
, deep
, outNode
);
375 static HRESULT WINAPI
domattr_get_nodeTypeString(
376 IXMLDOMAttribute
*iface
,
379 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
380 static const WCHAR attributeW
[] = {'a','t','t','r','i','b','u','t','e',0};
382 TRACE("(%p)->(%p)\n", This
, p
);
384 return return_bstr(attributeW
, p
);
387 static HRESULT WINAPI
domattr_get_text(
388 IXMLDOMAttribute
*iface
,
391 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
392 TRACE("(%p)->(%p)\n", This
, p
);
393 return node_get_text(&This
->node
, p
);
396 static HRESULT WINAPI
domattr_put_text(
397 IXMLDOMAttribute
*iface
,
400 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
401 TRACE("(%p)->(%s)\n", This
, debugstr_w(p
));
402 return node_put_text( &This
->node
, p
);
405 static HRESULT WINAPI
domattr_get_specified(
406 IXMLDOMAttribute
*iface
,
407 VARIANT_BOOL
* isSpecified
)
409 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
410 FIXME("(%p)->(%p) stub!\n", This
, isSpecified
);
411 *isSpecified
= VARIANT_TRUE
;
415 static HRESULT WINAPI
domattr_get_definition(
416 IXMLDOMAttribute
*iface
,
417 IXMLDOMNode
** definitionNode
)
419 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
420 FIXME("(%p)->(%p)\n", This
, definitionNode
);
424 static HRESULT WINAPI
domattr_get_nodeTypedValue(
425 IXMLDOMAttribute
*iface
,
428 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
429 IXMLDOMDocument
*doc
;
432 TRACE("(%p)->(%p)\n", This
, value
);
434 hr
= IXMLDOMAttribute_get_ownerDocument(iface
, &doc
);
437 IXMLDOMDocument3
*doc3
;
439 hr
= IXMLDOMDocument_QueryInterface(doc
, &IID_IXMLDOMDocument3
, (void**)&doc3
);
440 IXMLDOMDocument_Release(doc
);
446 hr
= IXMLDOMDocument3_get_schemas(doc3
, &schemas
);
447 IXMLDOMDocument3_Release(doc3
);
450 return IXMLDOMAttribute_get_value(iface
, value
);
453 FIXME("need to query schema for attribute type\n");
454 VariantClear(&schemas
);
459 return return_null_var(value
);
462 static HRESULT WINAPI
domattr_put_nodeTypedValue(
463 IXMLDOMAttribute
*iface
,
466 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
467 FIXME("(%p)->(%s)\n", This
, debugstr_variant(&typedValue
));
471 static HRESULT WINAPI
domattr_get_dataType(
472 IXMLDOMAttribute
*iface
,
475 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
476 TRACE("(%p)->(%p)\n", This
, typename
);
477 return return_null_var( typename
);
480 static HRESULT WINAPI
domattr_put_dataType(
481 IXMLDOMAttribute
*iface
,
484 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
486 FIXME("(%p)->(%s)\n", This
, debugstr_w(p
));
494 static HRESULT WINAPI
domattr_get_xml(
495 IXMLDOMAttribute
*iface
,
498 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
500 TRACE("(%p)->(%p)\n", This
, p
);
502 return node_get_xml(&This
->node
, FALSE
, p
);
505 static HRESULT WINAPI
domattr_transformNode(
506 IXMLDOMAttribute
*iface
,
507 IXMLDOMNode
*node
, BSTR
*p
)
509 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
510 TRACE("(%p)->(%p %p)\n", This
, node
, p
);
511 return node_transform_node(&This
->node
, node
, p
);
514 static HRESULT WINAPI
domattr_selectNodes(
515 IXMLDOMAttribute
*iface
,
516 BSTR p
, IXMLDOMNodeList
** outList
)
518 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
519 TRACE("(%p)->(%s %p)\n", This
, debugstr_w(p
), outList
);
520 return node_select_nodes(&This
->node
, p
, outList
);
523 static HRESULT WINAPI
domattr_selectSingleNode(
524 IXMLDOMAttribute
*iface
,
525 BSTR p
, IXMLDOMNode
** outNode
)
527 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
528 TRACE("(%p)->(%s %p)\n", This
, debugstr_w(p
), outNode
);
529 return node_select_singlenode(&This
->node
, p
, outNode
);
532 static HRESULT WINAPI
domattr_get_parsed(
533 IXMLDOMAttribute
*iface
,
534 VARIANT_BOOL
* isParsed
)
536 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
537 FIXME("(%p)->(%p) stub!\n", This
, isParsed
);
538 *isParsed
= VARIANT_TRUE
;
542 static HRESULT WINAPI
domattr_get_namespaceURI(
543 IXMLDOMAttribute
*iface
,
546 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
547 xmlNsPtr ns
= This
->node
.node
->ns
;
549 TRACE("(%p)->(%p)\n", This
, p
);
558 /* special case for default namespace definition */
559 if (xmlStrEqual(This
->node
.node
->name
, xmlns
))
560 *p
= bstr_from_xmlChar(xmlns
);
561 else if (xmlStrEqual(ns
->prefix
, xmlns
))
562 *p
= SysAllocStringLen(NULL
, 0);
564 *p
= bstr_from_xmlChar(ns
->href
);
567 TRACE("uri: %s\n", debugstr_w(*p
));
569 return *p
? S_OK
: S_FALSE
;
572 static HRESULT WINAPI
domattr_get_prefix(
573 IXMLDOMAttribute
*iface
,
576 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
577 xmlNsPtr ns
= This
->node
.node
->ns
;
579 TRACE("(%p)->(%p)\n", This
, prefix
);
581 if (!prefix
) return E_INVALIDARG
;
587 /* special case for default namespace definition */
588 if (xmlStrEqual(This
->node
.node
->name
, xmlns
))
589 *prefix
= bstr_from_xmlChar(xmlns
);
591 *prefix
= bstr_from_xmlChar(ns
->prefix
);
594 TRACE("prefix: %s\n", debugstr_w(*prefix
));
596 return *prefix
? S_OK
: S_FALSE
;
599 static HRESULT WINAPI
domattr_get_baseName(
600 IXMLDOMAttribute
*iface
,
603 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
604 TRACE("(%p)->(%p)\n", This
, name
);
605 return node_get_base_name( &This
->node
, name
);
608 static HRESULT WINAPI
domattr_transformNodeToObject(
609 IXMLDOMAttribute
*iface
,
610 IXMLDOMNode
* domNode
, VARIANT var1
)
612 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
613 FIXME("(%p)->(%p %s)\n", This
, domNode
, debugstr_variant(&var1
));
617 static HRESULT WINAPI
domattr_get_name(
618 IXMLDOMAttribute
*iface
,
621 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
623 TRACE("(%p)->(%p)\n", This
, p
);
625 return node_get_nodeName(&This
->node
, p
);
628 static HRESULT WINAPI
domattr_get_value(
629 IXMLDOMAttribute
*iface
,
632 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
634 TRACE("(%p)->(%p)\n", This
, value
);
636 return node_get_content(&This
->node
, value
);
639 static HRESULT WINAPI
domattr_put_value(
640 IXMLDOMAttribute
*iface
,
643 domattr
*This
= impl_from_IXMLDOMAttribute( iface
);
645 TRACE("(%p)->(%s)\n", This
, debugstr_variant(&value
));
647 return node_put_value_escaped(&This
->node
, &value
);
650 static const struct IXMLDOMAttributeVtbl domattr_vtbl
=
652 domattr_QueryInterface
,
655 domattr_GetTypeInfoCount
,
657 domattr_GetIDsOfNames
,
659 domattr_get_nodeName
,
660 domattr_get_nodeValue
,
661 domattr_put_nodeValue
,
662 domattr_get_nodeType
,
663 domattr_get_parentNode
,
664 domattr_get_childNodes
,
665 domattr_get_firstChild
,
666 domattr_get_lastChild
,
667 domattr_get_previousSibling
,
668 domattr_get_nextSibling
,
669 domattr_get_attributes
,
670 domattr_insertBefore
,
671 domattr_replaceChild
,
674 domattr_hasChildNodes
,
675 domattr_get_ownerDocument
,
677 domattr_get_nodeTypeString
,
680 domattr_get_specified
,
681 domattr_get_definition
,
682 domattr_get_nodeTypedValue
,
683 domattr_put_nodeTypedValue
,
684 domattr_get_dataType
,
685 domattr_put_dataType
,
687 domattr_transformNode
,
689 domattr_selectSingleNode
,
691 domattr_get_namespaceURI
,
693 domattr_get_baseName
,
694 domattr_transformNodeToObject
,
700 static const tid_t domattr_iface_tids
[] = {
701 IXMLDOMAttribute_tid
,
705 static dispex_static_data_t domattr_dispex
= {
707 IXMLDOMAttribute_tid
,
712 IUnknown
* create_attribute( xmlNodePtr attribute
)
716 This
= heap_alloc( sizeof *This
);
720 This
->IXMLDOMAttribute_iface
.lpVtbl
= &domattr_vtbl
;
723 init_xmlnode(&This
->node
, attribute
, (IXMLDOMNode
*)&This
->IXMLDOMAttribute_iface
, &domattr_dispex
);
725 return (IUnknown
*)&This
->IXMLDOMAttribute_iface
;