xref: /reactos/dll/win32/msxml3/attribute.c (revision 9f0f6adf)
1 /*
2  *    DOM Attribute implementation
3  *
4  * Copyright 2006 Huw Davies
5  *
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.
10  *
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.
15  *
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
19  */
20 
21 #define COBJMACROS
22 
23 #include "config.h"
24 
25 #include <stdarg.h>
26 #ifdef HAVE_LIBXML2
27 # include <libxml/parser.h>
28 # include <libxml/xmlerror.h>
29 # include <libxml/HTMLtree.h>
30 #endif
31 
32 #include "windef.h"
33 #include "winbase.h"
34 #include "winuser.h"
35 #include "ole2.h"
36 #include "msxml6.h"
37 
38 #include "msxml_private.h"
39 
40 #include "wine/debug.h"
41 
42 #ifdef HAVE_LIBXML2
43 
44 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
45 
46 static const xmlChar xmlns[] = "xmlns";
47 
48 typedef struct _domattr
49 {
50     xmlnode node;
51     IXMLDOMAttribute IXMLDOMAttribute_iface;
52     LONG ref;
53     BOOL floating;
54 } domattr;
55 
56 static const tid_t domattr_se_tids[] = {
57     IXMLDOMNode_tid,
58     IXMLDOMAttribute_tid,
59     NULL_tid
60 };
61 
impl_from_IXMLDOMAttribute(IXMLDOMAttribute * iface)62 static inline domattr *impl_from_IXMLDOMAttribute( IXMLDOMAttribute *iface )
63 {
64     return CONTAINING_RECORD(iface, domattr, IXMLDOMAttribute_iface);
65 }
66 
domattr_QueryInterface(IXMLDOMAttribute * iface,REFIID riid,void ** ppvObject)67 static HRESULT WINAPI domattr_QueryInterface(
68     IXMLDOMAttribute *iface,
69     REFIID riid,
70     void** ppvObject )
71 {
72     domattr *This = impl_from_IXMLDOMAttribute( iface );
73     TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
74 
75     if ( IsEqualGUID( riid, &IID_IXMLDOMAttribute ) ||
76          IsEqualGUID( riid, &IID_IXMLDOMNode ) ||
77          IsEqualGUID( riid, &IID_IDispatch ) ||
78          IsEqualGUID( riid, &IID_IUnknown ) )
79     {
80         *ppvObject = iface;
81     }
82     else if(node_query_interface(&This->node, riid, ppvObject))
83     {
84         return *ppvObject ? S_OK : E_NOINTERFACE;
85     }
86     else if(IsEqualGUID( riid, &IID_ISupportErrorInfo ))
87     {
88         return node_create_supporterrorinfo(domattr_se_tids, ppvObject);
89     }
90     else
91     {
92         TRACE("Unsupported interface %s\n", debugstr_guid(riid));
93         *ppvObject = NULL;
94         return E_NOINTERFACE;
95     }
96 
97     IXMLDOMAttribute_AddRef(iface);
98     return S_OK;
99 }
100 
domattr_AddRef(IXMLDOMAttribute * iface)101 static ULONG WINAPI domattr_AddRef(
102     IXMLDOMAttribute *iface )
103 {
104     domattr *This = impl_from_IXMLDOMAttribute( iface );
105     ULONG ref = InterlockedIncrement( &This->ref );
106     TRACE("(%p)->(%d)\n", This, ref);
107     return ref;
108 }
109 
domattr_Release(IXMLDOMAttribute * iface)110 static ULONG WINAPI domattr_Release(
111     IXMLDOMAttribute *iface )
112 {
113     domattr *This = impl_from_IXMLDOMAttribute( iface );
114     ULONG ref = InterlockedDecrement( &This->ref );
115 
116     TRACE("(%p)->(%d)\n", This, ref);
117     if ( ref == 0 )
118     {
119         destroy_xmlnode(&This->node);
120         if ( This->floating )
121         {
122             xmlFreeNs( This->node.node->ns );
123             xmlFreeNode( This->node.node );
124         }
125         heap_free( This );
126     }
127 
128     return ref;
129 }
130 
domattr_GetTypeInfoCount(IXMLDOMAttribute * iface,UINT * pctinfo)131 static HRESULT WINAPI domattr_GetTypeInfoCount(
132     IXMLDOMAttribute *iface,
133     UINT* pctinfo )
134 {
135     domattr *This = impl_from_IXMLDOMAttribute( iface );
136     return IDispatchEx_GetTypeInfoCount(&This->node.dispex.IDispatchEx_iface, pctinfo);
137 }
138 
domattr_GetTypeInfo(IXMLDOMAttribute * iface,UINT iTInfo,LCID lcid,ITypeInfo ** ppTInfo)139 static HRESULT WINAPI domattr_GetTypeInfo(
140     IXMLDOMAttribute *iface,
141     UINT iTInfo, LCID lcid,
142     ITypeInfo** ppTInfo )
143 {
144     domattr *This = impl_from_IXMLDOMAttribute( iface );
145     return IDispatchEx_GetTypeInfo(&This->node.dispex.IDispatchEx_iface,
146         iTInfo, lcid, ppTInfo);
147 }
148 
domattr_GetIDsOfNames(IXMLDOMAttribute * iface,REFIID riid,LPOLESTR * rgszNames,UINT cNames,LCID lcid,DISPID * rgDispId)149 static HRESULT WINAPI domattr_GetIDsOfNames(
150     IXMLDOMAttribute *iface,
151     REFIID riid, LPOLESTR* rgszNames,
152     UINT cNames, LCID lcid, DISPID* rgDispId )
153 {
154     domattr *This = impl_from_IXMLDOMAttribute( iface );
155     return IDispatchEx_GetIDsOfNames(&This->node.dispex.IDispatchEx_iface,
156         riid, rgszNames, cNames, lcid, rgDispId);
157 }
158 
domattr_Invoke(IXMLDOMAttribute * iface,DISPID dispIdMember,REFIID riid,LCID lcid,WORD wFlags,DISPPARAMS * pDispParams,VARIANT * pVarResult,EXCEPINFO * pExcepInfo,UINT * puArgErr)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 )
164 {
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);
168 }
169 
domattr_get_nodeName(IXMLDOMAttribute * iface,BSTR * p)170 static HRESULT WINAPI domattr_get_nodeName(
171     IXMLDOMAttribute *iface,
172     BSTR* p )
173 {
174     domattr *This = impl_from_IXMLDOMAttribute( iface );
175 
176     TRACE("(%p)->(%p)\n", This, p);
177 
178     return node_get_nodeName(&This->node, p);
179 }
180 
domattr_get_nodeValue(IXMLDOMAttribute * iface,VARIANT * value)181 static HRESULT WINAPI domattr_get_nodeValue(
182     IXMLDOMAttribute *iface,
183     VARIANT* value)
184 {
185     domattr *This = impl_from_IXMLDOMAttribute( iface );
186 
187     TRACE("(%p)->(%p)\n", This, value);
188 
189     return node_get_content(&This->node, value);
190 }
191 
domattr_put_nodeValue(IXMLDOMAttribute * iface,VARIANT value)192 static HRESULT WINAPI domattr_put_nodeValue(
193     IXMLDOMAttribute *iface,
194     VARIANT value)
195 {
196     domattr *This = impl_from_IXMLDOMAttribute( iface );
197 
198     TRACE("(%p)->(%s)\n", This, debugstr_variant(&value));
199 
200     return node_put_value_escaped(&This->node, &value);
201 }
202 
domattr_get_nodeType(IXMLDOMAttribute * iface,DOMNodeType * domNodeType)203 static HRESULT WINAPI domattr_get_nodeType(
204     IXMLDOMAttribute *iface,
205     DOMNodeType* domNodeType )
206 {
207     domattr *This = impl_from_IXMLDOMAttribute( iface );
208 
209     TRACE("(%p)->(%p)\n", This, domNodeType);
210 
211     *domNodeType = NODE_ATTRIBUTE;
212     return S_OK;
213 }
214 
domattr_get_parentNode(IXMLDOMAttribute * iface,IXMLDOMNode ** parent)215 static HRESULT WINAPI domattr_get_parentNode(
216     IXMLDOMAttribute *iface,
217     IXMLDOMNode** parent )
218 {
219     domattr *This = impl_from_IXMLDOMAttribute( iface );
220     TRACE("(%p)->(%p)\n", This, parent);
221     if (!parent) return E_INVALIDARG;
222     *parent = NULL;
223     return S_FALSE;
224 }
225 
domattr_get_childNodes(IXMLDOMAttribute * iface,IXMLDOMNodeList ** outList)226 static HRESULT WINAPI domattr_get_childNodes(
227     IXMLDOMAttribute *iface,
228     IXMLDOMNodeList** outList)
229 {
230     domattr *This = impl_from_IXMLDOMAttribute( iface );
231 
232     TRACE("(%p)->(%p)\n", This, outList);
233 
234     return node_get_child_nodes(&This->node, outList);
235 }
236 
domattr_get_firstChild(IXMLDOMAttribute * iface,IXMLDOMNode ** domNode)237 static HRESULT WINAPI domattr_get_firstChild(
238     IXMLDOMAttribute *iface,
239     IXMLDOMNode** domNode)
240 {
241     domattr *This = impl_from_IXMLDOMAttribute( iface );
242 
243     TRACE("(%p)->(%p)\n", This, domNode);
244 
245     return node_get_first_child(&This->node, domNode);
246 }
247 
domattr_get_lastChild(IXMLDOMAttribute * iface,IXMLDOMNode ** domNode)248 static HRESULT WINAPI domattr_get_lastChild(
249     IXMLDOMAttribute *iface,
250     IXMLDOMNode** domNode)
251 {
252     domattr *This = impl_from_IXMLDOMAttribute( iface );
253 
254     TRACE("(%p)->(%p)\n", This, domNode);
255 
256     return node_get_last_child(&This->node, domNode);
257 }
258 
domattr_get_previousSibling(IXMLDOMAttribute * iface,IXMLDOMNode ** domNode)259 static HRESULT WINAPI domattr_get_previousSibling(
260     IXMLDOMAttribute *iface,
261     IXMLDOMNode** domNode)
262 {
263     domattr *This = impl_from_IXMLDOMAttribute( iface );
264 
265     TRACE("(%p)->(%p)\n", This, domNode);
266 
267     return return_null_node(domNode);
268 }
269 
domattr_get_nextSibling(IXMLDOMAttribute * iface,IXMLDOMNode ** domNode)270 static HRESULT WINAPI domattr_get_nextSibling(
271     IXMLDOMAttribute *iface,
272     IXMLDOMNode** domNode)
273 {
274     domattr *This = impl_from_IXMLDOMAttribute( iface );
275 
276     TRACE("(%p)->(%p)\n", This, domNode);
277 
278     return return_null_node(domNode);
279 }
280 
domattr_get_attributes(IXMLDOMAttribute * iface,IXMLDOMNamedNodeMap ** attributeMap)281 static HRESULT WINAPI domattr_get_attributes(
282     IXMLDOMAttribute *iface,
283     IXMLDOMNamedNodeMap** attributeMap)
284 {
285     domattr *This = impl_from_IXMLDOMAttribute( iface );
286 
287     TRACE("(%p)->(%p)\n", This, attributeMap);
288 
289     return return_null_ptr((void**)attributeMap);
290 }
291 
domattr_insertBefore(IXMLDOMAttribute * iface,IXMLDOMNode * newNode,VARIANT refChild,IXMLDOMNode ** old_node)292 static HRESULT WINAPI domattr_insertBefore(
293     IXMLDOMAttribute *iface,
294     IXMLDOMNode* newNode, VARIANT refChild,
295     IXMLDOMNode** old_node)
296 {
297     domattr *This = impl_from_IXMLDOMAttribute( iface );
298     DOMNodeType type;
299     HRESULT hr;
300 
301     FIXME("(%p)->(%p %s %p) needs test\n", This, newNode, debugstr_variant(&refChild), old_node);
302 
303     if (!newNode) return E_INVALIDARG;
304 
305     hr = IXMLDOMNode_get_nodeType(newNode, &type);
306     if (hr != S_OK) return hr;
307 
308     TRACE("new node type %d\n", type);
309     switch (type)
310     {
311         case NODE_ATTRIBUTE:
312         case NODE_CDATA_SECTION:
313         case NODE_COMMENT:
314         case NODE_ELEMENT:
315         case NODE_PROCESSING_INSTRUCTION:
316             if (old_node) *old_node = NULL;
317             return E_FAIL;
318         default:
319             return node_insert_before(&This->node, newNode, &refChild, old_node);
320     }
321 }
322 
domattr_replaceChild(IXMLDOMAttribute * iface,IXMLDOMNode * newNode,IXMLDOMNode * oldNode,IXMLDOMNode ** outOldNode)323 static HRESULT WINAPI domattr_replaceChild(
324     IXMLDOMAttribute *iface,
325     IXMLDOMNode* newNode,
326     IXMLDOMNode* oldNode,
327     IXMLDOMNode** outOldNode)
328 {
329     domattr *This = impl_from_IXMLDOMAttribute( iface );
330 
331     FIXME("(%p)->(%p %p %p) needs tests\n", This, newNode, oldNode, outOldNode);
332 
333     return node_replace_child(&This->node, newNode, oldNode, outOldNode);
334 }
335 
domattr_removeChild(IXMLDOMAttribute * iface,IXMLDOMNode * child,IXMLDOMNode ** oldChild)336 static HRESULT WINAPI domattr_removeChild(
337     IXMLDOMAttribute *iface,
338     IXMLDOMNode *child, IXMLDOMNode **oldChild)
339 {
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);
343 }
344 
domattr_appendChild(IXMLDOMAttribute * iface,IXMLDOMNode * child,IXMLDOMNode ** outChild)345 static HRESULT WINAPI domattr_appendChild(
346     IXMLDOMAttribute *iface,
347     IXMLDOMNode *child, IXMLDOMNode **outChild)
348 {
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);
352 }
353 
domattr_hasChildNodes(IXMLDOMAttribute * iface,VARIANT_BOOL * ret)354 static HRESULT WINAPI domattr_hasChildNodes(
355     IXMLDOMAttribute *iface,
356     VARIANT_BOOL *ret)
357 {
358     domattr *This = impl_from_IXMLDOMAttribute( iface );
359     TRACE("(%p)->(%p)\n", This, ret);
360     return node_has_childnodes(&This->node, ret);
361 }
362 
domattr_get_ownerDocument(IXMLDOMAttribute * iface,IXMLDOMDocument ** doc)363 static HRESULT WINAPI domattr_get_ownerDocument(
364     IXMLDOMAttribute *iface,
365     IXMLDOMDocument **doc)
366 {
367     domattr *This = impl_from_IXMLDOMAttribute( iface );
368     TRACE("(%p)->(%p)\n", This, doc);
369     return node_get_owner_doc(&This->node, doc);
370 }
371 
domattr_cloneNode(IXMLDOMAttribute * iface,VARIANT_BOOL deep,IXMLDOMNode ** outNode)372 static HRESULT WINAPI domattr_cloneNode(
373     IXMLDOMAttribute *iface,
374     VARIANT_BOOL deep, IXMLDOMNode** outNode)
375 {
376     domattr *This = impl_from_IXMLDOMAttribute( iface );
377     TRACE("(%p)->(%d %p)\n", This, deep, outNode);
378     return node_clone( &This->node, deep, outNode );
379 }
380 
domattr_get_nodeTypeString(IXMLDOMAttribute * iface,BSTR * p)381 static HRESULT WINAPI domattr_get_nodeTypeString(
382     IXMLDOMAttribute *iface,
383     BSTR* p)
384 {
385     domattr *This = impl_from_IXMLDOMAttribute( iface );
386     static const WCHAR attributeW[] = {'a','t','t','r','i','b','u','t','e',0};
387 
388     TRACE("(%p)->(%p)\n", This, p);
389 
390     return return_bstr(attributeW, p);
391 }
392 
domattr_get_text(IXMLDOMAttribute * iface,BSTR * p)393 static HRESULT WINAPI domattr_get_text(
394     IXMLDOMAttribute *iface,
395     BSTR* p)
396 {
397     domattr *This = impl_from_IXMLDOMAttribute( iface );
398     TRACE("(%p)->(%p)\n", This, p);
399     return node_get_text(&This->node, p);
400 }
401 
domattr_put_text(IXMLDOMAttribute * iface,BSTR p)402 static HRESULT WINAPI domattr_put_text(
403     IXMLDOMAttribute *iface,
404     BSTR p)
405 {
406     domattr *This = impl_from_IXMLDOMAttribute( iface );
407     TRACE("(%p)->(%s)\n", This, debugstr_w(p));
408     return node_put_text( &This->node, p );
409 }
410 
domattr_get_specified(IXMLDOMAttribute * iface,VARIANT_BOOL * isSpecified)411 static HRESULT WINAPI domattr_get_specified(
412     IXMLDOMAttribute *iface,
413     VARIANT_BOOL* isSpecified)
414 {
415     domattr *This = impl_from_IXMLDOMAttribute( iface );
416     FIXME("(%p)->(%p) stub!\n", This, isSpecified);
417     *isSpecified = VARIANT_TRUE;
418     return S_OK;
419 }
420 
domattr_get_definition(IXMLDOMAttribute * iface,IXMLDOMNode ** definitionNode)421 static HRESULT WINAPI domattr_get_definition(
422     IXMLDOMAttribute *iface,
423     IXMLDOMNode** definitionNode)
424 {
425     domattr *This = impl_from_IXMLDOMAttribute( iface );
426     FIXME("(%p)->(%p)\n", This, definitionNode);
427     return E_NOTIMPL;
428 }
429 
domattr_get_nodeTypedValue(IXMLDOMAttribute * iface,VARIANT * value)430 static HRESULT WINAPI domattr_get_nodeTypedValue(
431     IXMLDOMAttribute *iface,
432     VARIANT* value)
433 {
434     domattr *This = impl_from_IXMLDOMAttribute( iface );
435     IXMLDOMDocument *doc;
436     HRESULT hr;
437 
438     TRACE("(%p)->(%p)\n", This, value);
439 
440     hr = IXMLDOMAttribute_get_ownerDocument(iface, &doc);
441     if (hr == S_OK)
442     {
443         IXMLDOMDocument3 *doc3;
444 
445         hr = IXMLDOMDocument_QueryInterface(doc, &IID_IXMLDOMDocument3, (void**)&doc3);
446         IXMLDOMDocument_Release(doc);
447 
448         if (hr == S_OK)
449         {
450             VARIANT schemas;
451 
452             hr = IXMLDOMDocument3_get_schemas(doc3, &schemas);
453             IXMLDOMDocument3_Release(doc3);
454 
455             if (hr != S_OK)
456                 return IXMLDOMAttribute_get_value(iface, value);
457             else
458             {
459                 FIXME("need to query schema for attribute type\n");
460                 VariantClear(&schemas);
461             }
462         }
463     }
464 
465     return return_null_var(value);
466 }
467 
domattr_put_nodeTypedValue(IXMLDOMAttribute * iface,VARIANT typedValue)468 static HRESULT WINAPI domattr_put_nodeTypedValue(
469     IXMLDOMAttribute *iface,
470     VARIANT typedValue)
471 {
472     domattr *This = impl_from_IXMLDOMAttribute( iface );
473     FIXME("(%p)->(%s)\n", This, debugstr_variant(&typedValue));
474     return E_NOTIMPL;
475 }
476 
domattr_get_dataType(IXMLDOMAttribute * iface,VARIANT * typename)477 static HRESULT WINAPI domattr_get_dataType(
478     IXMLDOMAttribute *iface,
479     VARIANT* typename)
480 {
481     domattr *This = impl_from_IXMLDOMAttribute( iface );
482     TRACE("(%p)->(%p)\n", This, typename);
483     return return_null_var( typename );
484 }
485 
domattr_put_dataType(IXMLDOMAttribute * iface,BSTR p)486 static HRESULT WINAPI domattr_put_dataType(
487     IXMLDOMAttribute *iface,
488     BSTR p)
489 {
490     domattr *This = impl_from_IXMLDOMAttribute( iface );
491 
492     FIXME("(%p)->(%s)\n", This, debugstr_w(p));
493 
494     if(!p)
495         return E_INVALIDARG;
496 
497     return E_FAIL;
498 }
499 
domattr_get_xml(IXMLDOMAttribute * iface,BSTR * p)500 static HRESULT WINAPI domattr_get_xml(
501     IXMLDOMAttribute *iface,
502     BSTR* p)
503 {
504     domattr *This = impl_from_IXMLDOMAttribute( iface );
505 
506     TRACE("(%p)->(%p)\n", This, p);
507 
508     return node_get_xml(&This->node, FALSE, p);
509 }
510 
domattr_transformNode(IXMLDOMAttribute * iface,IXMLDOMNode * node,BSTR * p)511 static HRESULT WINAPI domattr_transformNode(
512     IXMLDOMAttribute *iface,
513     IXMLDOMNode *node, BSTR *p)
514 {
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);
518 }
519 
domattr_selectNodes(IXMLDOMAttribute * iface,BSTR p,IXMLDOMNodeList ** outList)520 static HRESULT WINAPI domattr_selectNodes(
521     IXMLDOMAttribute *iface,
522     BSTR p, IXMLDOMNodeList** outList)
523 {
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);
527 }
528 
domattr_selectSingleNode(IXMLDOMAttribute * iface,BSTR p,IXMLDOMNode ** outNode)529 static HRESULT WINAPI domattr_selectSingleNode(
530     IXMLDOMAttribute *iface,
531     BSTR p, IXMLDOMNode** outNode)
532 {
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);
536 }
537 
domattr_get_parsed(IXMLDOMAttribute * iface,VARIANT_BOOL * isParsed)538 static HRESULT WINAPI domattr_get_parsed(
539     IXMLDOMAttribute *iface,
540     VARIANT_BOOL* isParsed)
541 {
542     domattr *This = impl_from_IXMLDOMAttribute( iface );
543     FIXME("(%p)->(%p) stub!\n", This, isParsed);
544     *isParsed = VARIANT_TRUE;
545     return S_OK;
546 }
547 
domattr_get_namespaceURI(IXMLDOMAttribute * iface,BSTR * p)548 static HRESULT WINAPI domattr_get_namespaceURI(
549     IXMLDOMAttribute *iface,
550     BSTR* p)
551 {
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;
556 
557     TRACE("(%p)->(%p)\n", This, p);
558 
559     if (!p)
560         return E_INVALIDARG;
561 
562     *p = NULL;
563 
564     if (ns)
565     {
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))
570         {
571             if (xmldoc_version(This->node.node->doc) == MSXML6)
572                 *p = SysAllocString(w3xmlns);
573             else
574                 *p = SysAllocStringLen(NULL, 0);
575         }
576         else if (ns->href)
577             *p = bstr_from_xmlChar(ns->href);
578     }
579 
580     TRACE("uri: %s\n", debugstr_w(*p));
581 
582     return *p ? S_OK : S_FALSE;
583 }
584 
domattr_get_prefix(IXMLDOMAttribute * iface,BSTR * prefix)585 static HRESULT WINAPI domattr_get_prefix(
586     IXMLDOMAttribute *iface,
587     BSTR* prefix)
588 {
589     domattr *This = impl_from_IXMLDOMAttribute( iface );
590     xmlNsPtr ns = This->node.node->ns;
591 
592     TRACE("(%p)->(%p)\n", This, prefix);
593 
594     if (!prefix) return E_INVALIDARG;
595 
596     *prefix = NULL;
597 
598     if (ns)
599     {
600         /* special case for default namespace definition */
601         if (xmlStrEqual(This->node.node->name, xmlns))
602             *prefix = bstr_from_xmlChar(xmlns);
603         else if (ns->prefix)
604             *prefix = bstr_from_xmlChar(ns->prefix);
605     }
606 
607     TRACE("prefix: %s\n", debugstr_w(*prefix));
608 
609     return *prefix ? S_OK : S_FALSE;
610 }
611 
domattr_get_baseName(IXMLDOMAttribute * iface,BSTR * name)612 static HRESULT WINAPI domattr_get_baseName(
613     IXMLDOMAttribute *iface,
614     BSTR* name)
615 {
616     domattr *This = impl_from_IXMLDOMAttribute( iface );
617     TRACE("(%p)->(%p)\n", This, name);
618     return node_get_base_name( &This->node, name );
619 }
620 
domattr_transformNodeToObject(IXMLDOMAttribute * iface,IXMLDOMNode * domNode,VARIANT var1)621 static HRESULT WINAPI domattr_transformNodeToObject(
622     IXMLDOMAttribute *iface,
623     IXMLDOMNode* domNode, VARIANT var1)
624 {
625     domattr *This = impl_from_IXMLDOMAttribute( iface );
626     FIXME("(%p)->(%p %s)\n", This, domNode, debugstr_variant(&var1));
627     return E_NOTIMPL;
628 }
629 
domattr_get_name(IXMLDOMAttribute * iface,BSTR * p)630 static HRESULT WINAPI domattr_get_name(
631     IXMLDOMAttribute *iface,
632     BSTR *p)
633 {
634     domattr *This = impl_from_IXMLDOMAttribute( iface );
635 
636     TRACE("(%p)->(%p)\n", This, p);
637 
638     return node_get_nodeName(&This->node, p);
639 }
640 
domattr_get_value(IXMLDOMAttribute * iface,VARIANT * value)641 static HRESULT WINAPI domattr_get_value(
642     IXMLDOMAttribute *iface,
643     VARIANT *value)
644 {
645     domattr *This = impl_from_IXMLDOMAttribute( iface );
646 
647     TRACE("(%p)->(%p)\n", This, value);
648 
649     return node_get_content(&This->node, value);
650 }
651 
domattr_put_value(IXMLDOMAttribute * iface,VARIANT value)652 static HRESULT WINAPI domattr_put_value(
653     IXMLDOMAttribute *iface,
654     VARIANT value)
655 {
656     domattr *This = impl_from_IXMLDOMAttribute( iface );
657 
658     TRACE("(%p)->(%s)\n", This, debugstr_variant(&value));
659 
660     return node_put_value_escaped(&This->node, &value);
661 }
662 
663 static const struct IXMLDOMAttributeVtbl domattr_vtbl =
664 {
665     domattr_QueryInterface,
666     domattr_AddRef,
667     domattr_Release,
668     domattr_GetTypeInfoCount,
669     domattr_GetTypeInfo,
670     domattr_GetIDsOfNames,
671     domattr_Invoke,
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,
685     domattr_removeChild,
686     domattr_appendChild,
687     domattr_hasChildNodes,
688     domattr_get_ownerDocument,
689     domattr_cloneNode,
690     domattr_get_nodeTypeString,
691     domattr_get_text,
692     domattr_put_text,
693     domattr_get_specified,
694     domattr_get_definition,
695     domattr_get_nodeTypedValue,
696     domattr_put_nodeTypedValue,
697     domattr_get_dataType,
698     domattr_put_dataType,
699     domattr_get_xml,
700     domattr_transformNode,
701     domattr_selectNodes,
702     domattr_selectSingleNode,
703     domattr_get_parsed,
704     domattr_get_namespaceURI,
705     domattr_get_prefix,
706     domattr_get_baseName,
707     domattr_transformNodeToObject,
708     domattr_get_name,
709     domattr_get_value,
710     domattr_put_value
711 };
712 
713 static const tid_t domattr_iface_tids[] = {
714     IXMLDOMAttribute_tid,
715     0
716 };
717 
718 static dispex_static_data_t domattr_dispex = {
719     NULL,
720     IXMLDOMAttribute_tid,
721     NULL,
722     domattr_iface_tids
723 };
724 
create_attribute(xmlNodePtr attribute,BOOL floating)725 IUnknown* create_attribute( xmlNodePtr attribute, BOOL floating )
726 {
727     domattr *This;
728 
729     This = heap_alloc( sizeof *This );
730     if ( !This )
731         return NULL;
732 
733     This->IXMLDOMAttribute_iface.lpVtbl = &domattr_vtbl;
734     This->ref = 1;
735     This->floating = floating;
736 
737     init_xmlnode(&This->node, attribute, (IXMLDOMNode*)&This->IXMLDOMAttribute_iface, &domattr_dispex);
738 
739     return (IUnknown*)&This->IXMLDOMAttribute_iface;
740 }
741 
742 #endif
743