Commit | Line | Data |
---|---|---|
65293d8e MM |
1 | /* |
2 | * Node implementation | |
3 | * | |
4 | * Copyright 2005 Mike McCormack | |
5 | * | |
d1b21b5c | 6 | * This library is free software; you can redistribute it and/or |
65293d8e MM |
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 | * | |
d1b21b5c | 11 | * This library is distributed in the hope that it will be useful, |
65293d8e MM |
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 | |
360a3f91 | 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA |
65293d8e MM |
19 | */ |
20 | ||
21 | #include "config.h" | |
22 | ||
23 | #define COBJMACROS | |
24 | ||
25 | #include <stdarg.h> | |
23f192d2 | 26 | #include <assert.h> |
65293d8e MM |
27 | #include "windef.h" |
28 | #include "winbase.h" | |
29 | #include "winuser.h" | |
30 | #include "winnls.h" | |
31 | #include "ole2.h" | |
5b8be5dc | 32 | #include "msxml2.h" |
65293d8e MM |
33 | |
34 | #include "msxml_private.h" | |
35 | ||
42db8b43 ALH |
36 | #ifdef HAVE_LIBXML2 |
37 | # include <libxml/HTMLtree.h> | |
38 | #endif | |
39 | ||
65293d8e MM |
40 | #include "wine/debug.h" |
41 | ||
42 | WINE_DEFAULT_DEBUG_CHANNEL(msxml); | |
43 | ||
44 | #ifdef HAVE_LIBXML2 | |
45 | ||
3c4cc5fb ALH |
46 | static const WCHAR szBinBase64[] = {'b','i','n','.','b','a','s','e','6','4',0}; |
47 | static const WCHAR szString[] = {'s','t','r','i','n','g',0}; | |
48 | static const WCHAR szNumber[] = {'n','u','m','b','e','r',0}; | |
49 | static const WCHAR szInt[] = {'I','n','t',0}; | |
50 | static const WCHAR szFixed[] = {'F','i','x','e','d','.','1','4','.','4',0}; | |
51 | static const WCHAR szBoolean[] = {'B','o','o','l','e','a','n',0}; | |
52 | static const WCHAR szDateTime[] = {'d','a','t','e','T','i','m','e',0}; | |
53 | static const WCHAR szDateTimeTZ[] = {'d','a','t','e','T','i','m','e','.','t','z',0}; | |
54 | static const WCHAR szDate[] = {'D','a','t','e',0}; | |
55 | static const WCHAR szTime[] = {'T','i','m','e',0}; | |
56 | static const WCHAR szTimeTZ[] = {'T','i','m','e','.','t','z',0}; | |
57 | static const WCHAR szI1[] = {'i','1',0}; | |
3c4cc5fb ALH |
58 | static const WCHAR szI2[] = {'i','2',0}; |
59 | static const WCHAR szI4[] = {'i','4',0}; | |
60 | static const WCHAR szIU1[] = {'u','i','1',0}; | |
61 | static const WCHAR szIU2[] = {'u','i','2',0}; | |
62 | static const WCHAR szIU4[] = {'u','i','4',0}; | |
63 | static const WCHAR szR4[] = {'r','4',0}; | |
64 | static const WCHAR szR8[] = {'r','8',0}; | |
65 | static const WCHAR szFloat[] = {'f','l','o','a','t',0}; | |
66 | static const WCHAR szUUID[] = {'u','u','i','d',0}; | |
67 | static const WCHAR szBinHex[] = {'b','i','n','.','h','e','x',0}; | |
68 | ||
23f192d2 | 69 | xmlNodePtr xmlNodePtr_from_domnode( IXMLDOMNode *iface, xmlElementType type ) |
65293d8e MM |
70 | { |
71 | xmlnode *This; | |
72 | ||
73 | if ( !iface ) | |
74 | return NULL; | |
65293d8e | 75 | This = impl_from_IXMLDOMNode( iface ); |
23f192d2 | 76 | if ( !This->node ) |
65293d8e | 77 | return NULL; |
23f192d2 | 78 | if ( type && This->node->type != type ) |
65293d8e | 79 | return NULL; |
23f192d2 | 80 | return This->node; |
65293d8e MM |
81 | } |
82 | ||
83 | static HRESULT WINAPI xmlnode_QueryInterface( | |
84 | IXMLDOMNode *iface, | |
85 | REFIID riid, | |
86 | void** ppvObject ) | |
87 | { | |
3f6bb98f | 88 | xmlnode *This = impl_from_IXMLDOMNode( iface ); |
83e91274 | 89 | |
3f6bb98f | 90 | TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject); |
65293d8e | 91 | |
83e91274 JC |
92 | if(This->pUnkOuter) |
93 | return IUnknown_QueryInterface(This->pUnkOuter, riid, ppvObject); | |
94 | ||
95 | if (IsEqualGUID(riid, &IID_IUnknown)) { | |
96 | *ppvObject = iface; | |
97 | }else if (IsEqualGUID( riid, &IID_IDispatch) || | |
98 | IsEqualGUID( riid, &IID_IXMLDOMNode)) { | |
99 | *ppvObject = &This->lpVtbl; | |
100 | }else { | |
101 | FIXME("interface %s not implemented\n", debugstr_guid(riid)); | |
102 | *ppvObject = NULL; | |
103 | return E_NOINTERFACE; | |
104 | } | |
105 | ||
106 | IUnknown_AddRef( (IUnknown*)*ppvObject ); | |
107 | return S_OK; | |
65293d8e MM |
108 | } |
109 | ||
110 | static ULONG WINAPI xmlnode_AddRef( | |
111 | IXMLDOMNode *iface ) | |
112 | { | |
113 | xmlnode *This = impl_from_IXMLDOMNode( iface ); | |
83e91274 JC |
114 | |
115 | if(This->pUnkOuter) | |
116 | return IUnknown_AddRef(This->pUnkOuter); | |
117 | ||
118 | return InterlockedIncrement(&This->ref); | |
65293d8e MM |
119 | } |
120 | ||
121 | static ULONG WINAPI xmlnode_Release( | |
122 | IXMLDOMNode *iface ) | |
123 | { | |
124 | xmlnode *This = impl_from_IXMLDOMNode( iface ); | |
83e91274 JC |
125 | LONG ref; |
126 | ||
127 | if(This->pUnkOuter) | |
128 | return IUnknown_Release(This->pUnkOuter); | |
129 | ||
130 | ref = InterlockedDecrement( &This->ref ); | |
04eff32b | 131 | if(!ref) { |
83e91274 | 132 | destroy_xmlnode(This); |
04eff32b JC |
133 | HeapFree( GetProcessHeap(), 0, This ); |
134 | } | |
83e91274 JC |
135 | |
136 | return ref; | |
65293d8e MM |
137 | } |
138 | ||
139 | static HRESULT WINAPI xmlnode_GetTypeInfoCount( | |
140 | IXMLDOMNode *iface, | |
141 | UINT* pctinfo ) | |
142 | { | |
af80b06f ALH |
143 | xmlnode *This = impl_from_IXMLDOMNode( iface ); |
144 | ||
145 | TRACE("(%p)->(%p)\n", This, pctinfo); | |
146 | ||
147 | *pctinfo = 1; | |
148 | ||
149 | return S_OK; | |
65293d8e MM |
150 | } |
151 | ||
152 | static HRESULT WINAPI xmlnode_GetTypeInfo( | |
153 | IXMLDOMNode *iface, | |
154 | UINT iTInfo, | |
155 | LCID lcid, | |
156 | ITypeInfo** ppTInfo ) | |
157 | { | |
af80b06f ALH |
158 | xmlnode *This = impl_from_IXMLDOMNode( iface ); |
159 | HRESULT hr; | |
160 | ||
161 | TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo); | |
162 | ||
163 | hr = get_typeinfo(IXMLDOMNode_tid, ppTInfo); | |
164 | ||
165 | return hr; | |
65293d8e MM |
166 | } |
167 | ||
168 | static HRESULT WINAPI xmlnode_GetIDsOfNames( | |
169 | IXMLDOMNode *iface, | |
170 | REFIID riid, | |
171 | LPOLESTR* rgszNames, | |
172 | UINT cNames, | |
173 | LCID lcid, | |
174 | DISPID* rgDispId ) | |
175 | { | |
af80b06f ALH |
176 | xmlnode *This = impl_from_IXMLDOMNode( iface ); |
177 | ||
178 | ITypeInfo *typeinfo; | |
179 | HRESULT hr; | |
180 | ||
181 | TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames, | |
182 | lcid, rgDispId); | |
183 | ||
184 | if(!rgszNames || cNames == 0 || !rgDispId) | |
185 | return E_INVALIDARG; | |
186 | ||
187 | hr = get_typeinfo(IXMLDOMNode_tid, &typeinfo); | |
188 | if(SUCCEEDED(hr)) | |
189 | { | |
190 | hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId); | |
191 | ITypeInfo_Release(typeinfo); | |
192 | } | |
193 | ||
194 | return hr; | |
65293d8e MM |
195 | } |
196 | ||
197 | static HRESULT WINAPI xmlnode_Invoke( | |
198 | IXMLDOMNode *iface, | |
199 | DISPID dispIdMember, | |
200 | REFIID riid, | |
201 | LCID lcid, | |
202 | WORD wFlags, | |
203 | DISPPARAMS* pDispParams, | |
204 | VARIANT* pVarResult, | |
205 | EXCEPINFO* pExcepInfo, | |
206 | UINT* puArgErr ) | |
207 | { | |
af80b06f ALH |
208 | xmlnode *This = impl_from_IXMLDOMNode( iface ); |
209 | ITypeInfo *typeinfo; | |
210 | HRESULT hr; | |
211 | ||
212 | TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid), | |
213 | lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr); | |
214 | ||
215 | hr = get_typeinfo(IXMLDOMNode_tid, &typeinfo); | |
216 | if(SUCCEEDED(hr)) | |
217 | { | |
218 | hr = ITypeInfo_Invoke(typeinfo, &(This->lpVtbl), dispIdMember, wFlags, pDispParams, | |
219 | pVarResult, pExcepInfo, puArgErr); | |
220 | ITypeInfo_Release(typeinfo); | |
221 | } | |
222 | ||
223 | return hr; | |
65293d8e MM |
224 | } |
225 | ||
2b7ae268 | 226 | static HRESULT WINAPI xmlnode_get_nodeName( |
65293d8e MM |
227 | IXMLDOMNode *iface, |
228 | BSTR* name) | |
229 | { | |
a182e093 MM |
230 | xmlnode *This = impl_from_IXMLDOMNode( iface ); |
231 | const xmlChar *str; | |
232 | ||
233 | TRACE("%p\n", This ); | |
234 | ||
d148ca4e SH |
235 | if (!name) |
236 | return E_INVALIDARG; | |
237 | ||
a182e093 MM |
238 | if ( !This->node ) |
239 | return E_FAIL; | |
240 | ||
241 | switch( This->node->type ) | |
242 | { | |
0a80e7c0 ALH |
243 | case XML_CDATA_SECTION_NODE: |
244 | str = (const xmlChar*) "#cdata-section"; | |
245 | break; | |
246 | case XML_COMMENT_NODE: | |
247 | str = (const xmlChar*) "#comment"; | |
a182e093 | 248 | break; |
0a80e7c0 ALH |
249 | case XML_DOCUMENT_FRAG_NODE: |
250 | str = (const xmlChar*) "#document-fragment"; | |
251 | break; | |
252 | case XML_TEXT_NODE: | |
253 | str = (const xmlChar*) "#text"; | |
254 | break; | |
d148ca4e | 255 | case XML_DOCUMENT_NODE: |
0a80e7c0 ALH |
256 | str = (const xmlChar*) "#document"; |
257 | break; | |
258 | case XML_ATTRIBUTE_NODE: | |
259 | case XML_ELEMENT_NODE: | |
6dee6819 ALH |
260 | case XML_PI_NODE: |
261 | str = This->node->name; | |
0a80e7c0 | 262 | break; |
a182e093 | 263 | default: |
0a80e7c0 | 264 | FIXME("nodeName not mapped correctly (%d)\n", This->node->type); |
a182e093 MM |
265 | str = This->node->name; |
266 | break; | |
267 | } | |
268 | ||
269 | *name = bstr_from_xmlChar( str ); | |
270 | if (!*name) | |
271 | return S_FALSE; | |
272 | ||
273 | return S_OK; | |
65293d8e MM |
274 | } |
275 | ||
2b7ae268 | 276 | static HRESULT WINAPI xmlnode_get_nodeValue( |
65293d8e MM |
277 | IXMLDOMNode *iface, |
278 | VARIANT* value) | |
279 | { | |
280 | xmlnode *This = impl_from_IXMLDOMNode( iface ); | |
23f192d2 | 281 | HRESULT r = S_FALSE; |
65293d8e MM |
282 | |
283 | TRACE("%p %p\n", This, value); | |
284 | ||
7c1a7491 ALH |
285 | if(!value) |
286 | return E_INVALIDARG; | |
287 | ||
23f192d2 MM |
288 | V_BSTR(value) = NULL; |
289 | V_VT(value) = VT_NULL; | |
290 | ||
291 | switch ( This->node->type ) | |
65293d8e | 292 | { |
c43b0706 | 293 | case XML_CDATA_SECTION_NODE: |
a1f5fef8 | 294 | case XML_COMMENT_NODE: |
a2debce7 | 295 | case XML_PI_NODE: |
65293d8e | 296 | case XML_ATTRIBUTE_NODE: |
e7187ff3 HD |
297 | { |
298 | xmlChar *content = xmlNodeGetContent(This->node); | |
65293d8e | 299 | V_VT(value) = VT_BSTR; |
e7187ff3 HD |
300 | V_BSTR(value) = bstr_from_xmlChar( content ); |
301 | xmlFree(content); | |
23f192d2 | 302 | r = S_OK; |
65293d8e | 303 | break; |
e7187ff3 | 304 | } |
23f192d2 MM |
305 | case XML_TEXT_NODE: |
306 | V_VT(value) = VT_BSTR; | |
307 | V_BSTR(value) = bstr_from_xmlChar( This->node->content ); | |
308 | r = S_OK; | |
65293d8e MM |
309 | break; |
310 | case XML_ELEMENT_NODE: | |
311 | case XML_DOCUMENT_NODE: | |
23f192d2 | 312 | /* these seem to return NULL */ |
65293d8e | 313 | break; |
a2debce7 | 314 | |
23f192d2 MM |
315 | default: |
316 | FIXME("node %p type %d\n", This, This->node->type); | |
65293d8e MM |
317 | } |
318 | ||
319 | TRACE("%p returned %s\n", This, debugstr_w( V_BSTR(value) ) ); | |
320 | ||
23f192d2 | 321 | return r; |
65293d8e MM |
322 | } |
323 | ||
2b7ae268 | 324 | static HRESULT WINAPI xmlnode_put_nodeValue( |
65293d8e MM |
325 | IXMLDOMNode *iface, |
326 | VARIANT value) | |
327 | { | |
75a8444a | 328 | xmlnode *This = impl_from_IXMLDOMNode( iface ); |
b7ac3bde | 329 | HRESULT hr; |
75a8444a | 330 | xmlChar *str = NULL; |
b7ac3bde | 331 | VARIANT string_value; |
75a8444a | 332 | |
39844efc | 333 | TRACE("%p type(%d)\n", This, This->node->type); |
75a8444a | 334 | |
b7ac3bde MK |
335 | VariantInit(&string_value); |
336 | hr = VariantChangeType(&string_value, &value, 0, VT_BSTR); | |
337 | if(FAILED(hr)) | |
338 | { | |
339 | VariantClear(&string_value); | |
340 | WARN("Couldn't convert to VT_BSTR\n"); | |
341 | return hr; | |
342 | } | |
343 | ||
344 | hr = S_FALSE; | |
75a8444a | 345 | /* Document, Document Fragment, Document Type, Element, |
304b4152 | 346 | Entity, Entity Reference, Notation aren't supported. */ |
75a8444a ALH |
347 | switch ( This->node->type ) |
348 | { | |
349 | case XML_ATTRIBUTE_NODE: | |
350 | case XML_CDATA_SECTION_NODE: | |
351 | case XML_COMMENT_NODE: | |
352 | case XML_PI_NODE: | |
353 | case XML_TEXT_NODE: | |
354 | { | |
6a5dda71 | 355 | str = xmlChar_from_wchar(V_BSTR(&string_value)); |
75a8444a | 356 | xmlNodeSetContent(This->node, str); |
ae2017a9 | 357 | HeapFree(GetProcessHeap(),0,str); |
75a8444a ALH |
358 | hr = S_OK; |
359 | break; | |
360 | } | |
361 | default: | |
362 | /* Do nothing for unsupported types. */ | |
363 | break; | |
364 | } | |
365 | ||
b7ac3bde MK |
366 | VariantClear(&string_value); |
367 | ||
75a8444a | 368 | return hr; |
65293d8e MM |
369 | } |
370 | ||
2b7ae268 | 371 | static HRESULT WINAPI xmlnode_get_nodeType( |
65293d8e MM |
372 | IXMLDOMNode *iface, |
373 | DOMNodeType* type) | |
374 | { | |
23f192d2 MM |
375 | xmlnode *This = impl_from_IXMLDOMNode( iface ); |
376 | ||
377 | TRACE("%p %p\n", This, type); | |
378 | ||
875f0c24 GP |
379 | assert( (int)NODE_ELEMENT == (int)XML_ELEMENT_NODE ); |
380 | assert( (int)NODE_NOTATION == (int)XML_NOTATION_NODE ); | |
23f192d2 MM |
381 | |
382 | *type = This->node->type; | |
383 | ||
384 | return S_OK; | |
65293d8e MM |
385 | } |
386 | ||
dc2e14d9 MM |
387 | static HRESULT get_node( |
388 | xmlnode *This, | |
389 | const char *name, | |
390 | xmlNodePtr node, | |
391 | IXMLDOMNode **out ) | |
392 | { | |
393 | TRACE("%p->%s %p\n", This, name, node ); | |
394 | ||
395 | if ( !out ) | |
396 | return E_INVALIDARG; | |
17db41c3 | 397 | |
5ef48192 | 398 | /* if we don't have a doc, use our parent. */ |
17db41c3 ALH |
399 | if(node && !node->doc && node->parent) |
400 | node->doc = node->parent->doc; | |
401 | ||
dc2e14d9 MM |
402 | *out = create_node( node ); |
403 | if (!*out) | |
404 | return S_FALSE; | |
405 | return S_OK; | |
406 | } | |
407 | ||
65293d8e MM |
408 | static HRESULT WINAPI xmlnode_get_parentNode( |
409 | IXMLDOMNode *iface, | |
410 | IXMLDOMNode** parent) | |
411 | { | |
dc2e14d9 MM |
412 | xmlnode *This = impl_from_IXMLDOMNode( iface ); |
413 | return get_node( This, "parent", This->node->parent, parent ); | |
65293d8e MM |
414 | } |
415 | ||
416 | static HRESULT WINAPI xmlnode_get_childNodes( | |
417 | IXMLDOMNode *iface, | |
418 | IXMLDOMNodeList** childList) | |
419 | { | |
420 | xmlnode *This = impl_from_IXMLDOMNode( iface ); | |
23f192d2 MM |
421 | |
422 | TRACE("%p %p\n", This, childList ); | |
423 | ||
424 | if ( !childList ) | |
425 | return E_INVALIDARG; | |
3d0c6627 | 426 | |
e1cbec75 MZ |
427 | *childList = create_children_nodelist(This->node); |
428 | if (*childList == NULL) | |
429 | return E_OUTOFMEMORY; | |
3d0c6627 | 430 | |
23f192d2 | 431 | return S_OK; |
65293d8e MM |
432 | } |
433 | ||
434 | static HRESULT WINAPI xmlnode_get_firstChild( | |
435 | IXMLDOMNode *iface, | |
436 | IXMLDOMNode** firstChild) | |
437 | { | |
dc2e14d9 MM |
438 | xmlnode *This = impl_from_IXMLDOMNode( iface ); |
439 | return get_node( This, "firstChild", This->node->children, firstChild ); | |
65293d8e MM |
440 | } |
441 | ||
442 | static HRESULT WINAPI xmlnode_get_lastChild( | |
443 | IXMLDOMNode *iface, | |
444 | IXMLDOMNode** lastChild) | |
445 | { | |
dc2e14d9 | 446 | xmlnode *This = impl_from_IXMLDOMNode( iface ); |
91ad27ea ALH |
447 | |
448 | TRACE("%p\n", This ); | |
449 | ||
450 | if (!lastChild) | |
451 | return E_INVALIDARG; | |
452 | ||
453 | switch( This->node->type ) | |
454 | { | |
455 | /* CDATASection, Comment, PI and Text Nodes do not support lastChild */ | |
456 | case XML_TEXT_NODE: | |
457 | case XML_CDATA_SECTION_NODE: | |
458 | case XML_PI_NODE: | |
459 | case XML_COMMENT_NODE: | |
460 | *lastChild = NULL; | |
461 | return S_FALSE; | |
462 | default: | |
463 | return get_node( This, "lastChild", This->node->last, lastChild ); | |
464 | } | |
65293d8e MM |
465 | } |
466 | ||
467 | static HRESULT WINAPI xmlnode_get_previousSibling( | |
468 | IXMLDOMNode *iface, | |
469 | IXMLDOMNode** previousSibling) | |
470 | { | |
dc2e14d9 | 471 | xmlnode *This = impl_from_IXMLDOMNode( iface ); |
2896c462 ALH |
472 | |
473 | TRACE("%p\n", This ); | |
474 | ||
475 | if (!previousSibling) | |
476 | return E_INVALIDARG; | |
477 | ||
478 | switch( This->node->type ) | |
479 | { | |
480 | /* Attribute, Document and Document Fragment Nodes do not support previousSibling */ | |
481 | case XML_DOCUMENT_NODE: | |
482 | case XML_DOCUMENT_FRAG_NODE: | |
483 | case XML_ATTRIBUTE_NODE: | |
484 | *previousSibling = NULL; | |
485 | return S_FALSE; | |
486 | default: | |
487 | return get_node( This, "previous", This->node->prev, previousSibling ); | |
488 | } | |
65293d8e MM |
489 | } |
490 | ||
491 | static HRESULT WINAPI xmlnode_get_nextSibling( | |
492 | IXMLDOMNode *iface, | |
493 | IXMLDOMNode** nextSibling) | |
494 | { | |
dc2e14d9 | 495 | xmlnode *This = impl_from_IXMLDOMNode( iface ); |
4e908f65 ALH |
496 | |
497 | TRACE("%p\n", This ); | |
498 | ||
499 | if (!nextSibling) | |
500 | return E_INVALIDARG; | |
501 | ||
502 | switch( This->node->type ) | |
503 | { | |
504 | /* Attribute, Document and Document Fragment Nodes do not support nextSibling */ | |
505 | case XML_DOCUMENT_NODE: | |
506 | case XML_DOCUMENT_FRAG_NODE: | |
507 | case XML_ATTRIBUTE_NODE: | |
508 | *nextSibling = NULL; | |
509 | return S_FALSE; | |
510 | default: | |
511 | return get_node( This, "next", This->node->next, nextSibling ); | |
512 | } | |
65293d8e MM |
513 | } |
514 | ||
515 | static HRESULT WINAPI xmlnode_get_attributes( | |
516 | IXMLDOMNode *iface, | |
517 | IXMLDOMNamedNodeMap** attributeMap) | |
518 | { | |
519 | xmlnode *This = impl_from_IXMLDOMNode( iface ); | |
23f192d2 | 520 | TRACE("%p\n", This); |
e906b136 ALH |
521 | |
522 | if (!attributeMap) | |
523 | return E_INVALIDARG; | |
524 | ||
525 | switch( This->node->type ) | |
526 | { | |
527 | /* Attribute, CDataSection, Comment, Documents, Documents Fragments, | |
528 | Entity and Text Nodes does not support get_attributes */ | |
529 | case XML_ATTRIBUTE_NODE: | |
bf4a43e1 | 530 | case XML_CDATA_SECTION_NODE: |
e906b136 ALH |
531 | case XML_COMMENT_NODE: |
532 | case XML_DOCUMENT_NODE: | |
533 | case XML_DOCUMENT_FRAG_NODE: | |
534 | case XML_ENTITY_NODE: | |
bfeb14d0 | 535 | case XML_ENTITY_REF_NODE: |
e906b136 ALH |
536 | case XML_TEXT_NODE: |
537 | *attributeMap = NULL; | |
538 | return S_FALSE; | |
539 | default: | |
540 | *attributeMap = create_nodemap( iface ); | |
541 | return S_OK; | |
542 | } | |
65293d8e MM |
543 | } |
544 | ||
545 | static HRESULT WINAPI xmlnode_insertBefore( | |
546 | IXMLDOMNode *iface, | |
547 | IXMLDOMNode* newChild, | |
548 | VARIANT refChild, | |
549 | IXMLDOMNode** outNewChild) | |
550 | { | |
50c64c04 HD |
551 | xmlnode *This = impl_from_IXMLDOMNode( iface ); |
552 | xmlNodePtr before_node, new_child_node; | |
553 | IXMLDOMNode *before = NULL, *new; | |
554 | HRESULT hr; | |
555 | ||
556 | TRACE("(%p)->(%p,var,%p)\n",This,newChild,outNewChild); | |
557 | ||
7fbf828a | 558 | if (!newChild) |
c75d739d PC |
559 | return E_INVALIDARG; |
560 | ||
50c64c04 HD |
561 | switch(V_VT(&refChild)) |
562 | { | |
563 | case VT_EMPTY: | |
564 | case VT_NULL: | |
565 | break; | |
566 | ||
567 | case VT_UNKNOWN: | |
568 | hr = IUnknown_QueryInterface(V_UNKNOWN(&refChild), &IID_IXMLDOMNode, (LPVOID)&before); | |
569 | if(FAILED(hr)) return hr; | |
570 | break; | |
571 | ||
572 | case VT_DISPATCH: | |
573 | hr = IDispatch_QueryInterface(V_DISPATCH(&refChild), &IID_IXMLDOMNode, (LPVOID)&before); | |
574 | if(FAILED(hr)) return hr; | |
575 | break; | |
576 | ||
577 | default: | |
578 | FIXME("refChild var type %x\n", V_VT(&refChild)); | |
579 | return E_FAIL; | |
580 | } | |
581 | ||
582 | IXMLDOMNode_QueryInterface(newChild, &IID_IXMLDOMNode, (LPVOID)&new); | |
583 | new_child_node = impl_from_IXMLDOMNode(new)->node; | |
584 | TRACE("new_child_node %p This->node %p\n", new_child_node, This->node); | |
585 | ||
f229469d MK |
586 | if(!new_child_node->parent) |
587 | if(xmldoc_remove_orphan(new_child_node->doc, new_child_node) != S_OK) | |
588 | WARN("%p is not an orphan of %p\n", new_child_node, new_child_node->doc); | |
589 | ||
50c64c04 HD |
590 | if(before) |
591 | { | |
592 | before_node = impl_from_IXMLDOMNode(before)->node; | |
593 | xmlAddPrevSibling(before_node, new_child_node); | |
594 | IXMLDOMNode_Release(before); | |
595 | } | |
596 | else | |
597 | { | |
598 | xmlAddChild(This->node, new_child_node); | |
599 | } | |
600 | ||
601 | IXMLDOMNode_Release(new); | |
602 | IXMLDOMNode_AddRef(newChild); | |
7fbf828a ALH |
603 | if(outNewChild) |
604 | *outNewChild = newChild; | |
605 | ||
50c64c04 HD |
606 | TRACE("ret S_OK\n"); |
607 | return S_OK; | |
65293d8e MM |
608 | } |
609 | ||
610 | static HRESULT WINAPI xmlnode_replaceChild( | |
611 | IXMLDOMNode *iface, | |
612 | IXMLDOMNode* newChild, | |
613 | IXMLDOMNode* oldChild, | |
614 | IXMLDOMNode** outOldChild) | |
615 | { | |
9d65ec27 | 616 | xmlnode *This = impl_from_IXMLDOMNode( iface ); |
6fe686f5 MK |
617 | xmlNode *old_child_ptr, *new_child_ptr; |
618 | xmlDocPtr leaving_doc; | |
619 | xmlNode *my_ancestor; | |
27e9a983 MK |
620 | IXMLDOMNode *realOldChild; |
621 | HRESULT hr; | |
9d65ec27 MK |
622 | |
623 | TRACE("%p->(%p,%p,%p)\n",This,newChild,oldChild,outOldChild); | |
624 | ||
625 | /* Do not believe any documentation telling that newChild == NULL | |
626 | means removal. It does certainly *not* apply to msxml3! */ | |
627 | if(!newChild || !oldChild) | |
628 | return E_INVALIDARG; | |
629 | ||
6fe686f5 MK |
630 | if(outOldChild) |
631 | *outOldChild = NULL; | |
632 | ||
27e9a983 MK |
633 | hr = IXMLDOMNode_QueryInterface(oldChild,&IID_IXMLDOMNode,(LPVOID*)&realOldChild); |
634 | if(FAILED(hr)) | |
635 | return hr; | |
636 | ||
637 | old_child_ptr = impl_from_IXMLDOMNode(realOldChild)->node; | |
638 | IXMLDOMNode_Release(realOldChild); | |
6fe686f5 MK |
639 | if(old_child_ptr->parent != This->node) |
640 | { | |
641 | WARN("childNode %p is not a child of %p\n", oldChild, iface); | |
642 | return E_INVALIDARG; | |
643 | } | |
644 | ||
645 | new_child_ptr = impl_from_IXMLDOMNode(newChild)->node; | |
646 | my_ancestor = This->node; | |
647 | while(my_ancestor) | |
648 | { | |
649 | if(my_ancestor == new_child_ptr) | |
650 | { | |
651 | WARN("tried to create loop\n"); | |
652 | return E_FAIL; | |
653 | } | |
654 | my_ancestor = my_ancestor->parent; | |
655 | } | |
656 | ||
f229469d MK |
657 | if(!new_child_ptr->parent) |
658 | if(xmldoc_remove_orphan(new_child_ptr->doc, new_child_ptr) != S_OK) | |
659 | WARN("%p is not an orphan of %p\n", new_child_ptr, new_child_ptr->doc); | |
660 | ||
6fe686f5 MK |
661 | leaving_doc = new_child_ptr->doc; |
662 | xmldoc_add_ref(old_child_ptr->doc); | |
663 | xmlReplaceNode(old_child_ptr, new_child_ptr); | |
664 | xmldoc_release(leaving_doc); | |
665 | ||
f229469d MK |
666 | xmldoc_add_orphan(old_child_ptr->doc, old_child_ptr); |
667 | ||
6fe686f5 MK |
668 | if(outOldChild) |
669 | { | |
670 | IXMLDOMNode_AddRef(oldChild); | |
671 | *outOldChild = oldChild; | |
672 | } | |
673 | ||
674 | return S_OK; | |
65293d8e MM |
675 | } |
676 | ||
677 | static HRESULT WINAPI xmlnode_removeChild( | |
678 | IXMLDOMNode *iface, | |
679 | IXMLDOMNode* childNode, | |
680 | IXMLDOMNode** oldChild) | |
681 | { | |
187ab1c0 | 682 | xmlnode *This = impl_from_IXMLDOMNode( iface ); |
75606f35 | 683 | xmlNode *child_node_ptr; |
57ee10ff MK |
684 | HRESULT hr; |
685 | IXMLDOMNode *child; | |
187ab1c0 HD |
686 | |
687 | TRACE("%p->(%p, %p)\n", This, childNode, oldChild); | |
688 | ||
30351482 MK |
689 | if(!childNode) return E_INVALIDARG; |
690 | ||
93e76ece PC |
691 | if(oldChild) |
692 | *oldChild = NULL; | |
a307901a | 693 | |
57ee10ff MK |
694 | hr = IXMLDOMNode_QueryInterface(childNode, &IID_IXMLDOMNode, (LPVOID)&child); |
695 | if(FAILED(hr)) | |
696 | return hr; | |
697 | ||
698 | child_node_ptr = impl_from_IXMLDOMNode(child)->node; | |
75606f35 | 699 | if(child_node_ptr->parent != This->node) |
187ab1c0 HD |
700 | { |
701 | WARN("childNode %p is not a child of %p\n", childNode, iface); | |
57ee10ff | 702 | IXMLDOMNode_Release(child); |
187ab1c0 HD |
703 | return E_INVALIDARG; |
704 | } | |
705 | ||
706 | xmlUnlinkNode(child_node_ptr); | |
707 | ||
57ee10ff MK |
708 | IXMLDOMNode_Release(child); |
709 | ||
93e76ece | 710 | if(oldChild) |
d676f7e5 PC |
711 | { |
712 | IXMLDOMNode_AddRef(childNode); | |
93e76ece | 713 | *oldChild = childNode; |
d676f7e5 PC |
714 | } |
715 | ||
187ab1c0 | 716 | return S_OK; |
65293d8e MM |
717 | } |
718 | ||
719 | static HRESULT WINAPI xmlnode_appendChild( | |
720 | IXMLDOMNode *iface, | |
721 | IXMLDOMNode* newChild, | |
722 | IXMLDOMNode** outNewChild) | |
723 | { | |
50c64c04 | 724 | xmlnode *This = impl_from_IXMLDOMNode( iface ); |
26b95dc7 | 725 | DOMNodeType type; |
50c64c04 | 726 | VARIANT var; |
26b95dc7 | 727 | HRESULT hr; |
50c64c04 HD |
728 | |
729 | TRACE("(%p)->(%p,%p)\n", This, newChild, outNewChild); | |
cdac6b50 | 730 | |
26b95dc7 PC |
731 | hr = IXMLDOMNode_get_nodeType(newChild, &type); |
732 | if(FAILED(hr) || type == NODE_ATTRIBUTE) { | |
733 | if(outNewChild) *outNewChild = NULL; | |
734 | return E_FAIL; | |
cdac6b50 ALH |
735 | } |
736 | ||
50c64c04 HD |
737 | VariantInit(&var); |
738 | return IXMLDOMNode_insertBefore(iface, newChild, var, outNewChild); | |
65293d8e MM |
739 | } |
740 | ||
741 | static HRESULT WINAPI xmlnode_hasChildNodes( | |
742 | IXMLDOMNode *iface, | |
743 | VARIANT_BOOL* hasChild) | |
744 | { | |
da3393d4 MM |
745 | xmlnode *This = impl_from_IXMLDOMNode( iface ); |
746 | ||
747 | TRACE("%p\n", This); | |
748 | ||
749 | if (!hasChild) | |
750 | return E_INVALIDARG; | |
751 | if (!This->node->children) | |
752 | { | |
753 | *hasChild = VARIANT_FALSE; | |
754 | return S_FALSE; | |
755 | } | |
756 | ||
757 | *hasChild = VARIANT_TRUE; | |
758 | return S_OK; | |
65293d8e MM |
759 | } |
760 | ||
761 | static HRESULT WINAPI xmlnode_get_ownerDocument( | |
762 | IXMLDOMNode *iface, | |
763 | IXMLDOMDocument** DOMDocument) | |
764 | { | |
800463c2 PC |
765 | xmlnode *This = impl_from_IXMLDOMNode( iface ); |
766 | ||
767 | TRACE("%p (%p)\n", This, DOMDocument); | |
768 | ||
769 | return DOMDocument_create_from_xmldoc(This->node->doc, (IXMLDOMDocument2**)DOMDocument); | |
65293d8e MM |
770 | } |
771 | ||
772 | static HRESULT WINAPI xmlnode_cloneNode( | |
773 | IXMLDOMNode *iface, | |
774 | VARIANT_BOOL deep, | |
775 | IXMLDOMNode** cloneRoot) | |
776 | { | |
86af5b97 ALH |
777 | xmlnode *This = impl_from_IXMLDOMNode( iface ); |
778 | xmlNodePtr pClone = NULL; | |
779 | IXMLDOMNode *pNode = NULL; | |
780 | ||
781 | TRACE("%p (%d)\n", This, deep); | |
782 | ||
783 | if(!cloneRoot) | |
784 | return E_INVALIDARG; | |
785 | ||
786 | pClone = xmlCopyNode(This->node, deep ? 1 : 2); | |
787 | if(pClone) | |
788 | { | |
789 | pClone->doc = This->node->doc; | |
f229469d | 790 | xmldoc_add_orphan(pClone->doc, pClone); |
86af5b97 ALH |
791 | |
792 | pNode = create_node(pClone); | |
793 | if(!pNode) | |
794 | { | |
795 | ERR("Copy failed\n"); | |
796 | return E_FAIL; | |
797 | } | |
798 | ||
799 | *cloneRoot = pNode; | |
800 | } | |
801 | else | |
802 | { | |
803 | ERR("Copy failed\n"); | |
804 | return E_FAIL; | |
805 | } | |
806 | ||
807 | return S_OK; | |
65293d8e MM |
808 | } |
809 | ||
2b7ae268 | 810 | static HRESULT WINAPI xmlnode_get_nodeTypeString( |
65293d8e MM |
811 | IXMLDOMNode *iface, |
812 | BSTR* xmlnodeType) | |
813 | { | |
055b5e44 ALH |
814 | xmlnode *This = impl_from_IXMLDOMNode( iface ); |
815 | const xmlChar *str; | |
816 | ||
817 | TRACE("%p\n", This ); | |
818 | ||
819 | if (!xmlnodeType) | |
820 | return E_INVALIDARG; | |
821 | ||
822 | if ( !This->node ) | |
823 | return E_FAIL; | |
824 | ||
825 | switch( This->node->type ) | |
826 | { | |
827 | case XML_ATTRIBUTE_NODE: | |
828 | str = (const xmlChar*) "attribute"; | |
829 | break; | |
830 | case XML_CDATA_SECTION_NODE: | |
831 | str = (const xmlChar*) "cdatasection"; | |
832 | break; | |
833 | case XML_COMMENT_NODE: | |
834 | str = (const xmlChar*) "comment"; | |
835 | break; | |
836 | case XML_DOCUMENT_NODE: | |
837 | str = (const xmlChar*) "document"; | |
838 | break; | |
839 | case XML_DOCUMENT_FRAG_NODE: | |
840 | str = (const xmlChar*) "documentfragment"; | |
841 | break; | |
842 | case XML_ELEMENT_NODE: | |
843 | str = (const xmlChar*) "element"; | |
844 | break; | |
845 | case XML_ENTITY_NODE: | |
846 | str = (const xmlChar*) "entity"; | |
847 | break; | |
848 | case XML_ENTITY_REF_NODE: | |
849 | str = (const xmlChar*) "entityreference"; | |
850 | break; | |
851 | case XML_NOTATION_NODE: | |
852 | str = (const xmlChar*) "notation"; | |
853 | break; | |
854 | case XML_PI_NODE: | |
855 | str = (const xmlChar*) "processinginstruction"; | |
856 | break; | |
857 | case XML_TEXT_NODE: | |
858 | str = (const xmlChar*) "text"; | |
859 | break; | |
860 | default: | |
c6a64414 | 861 | FIXME("Unknown node type (%d)\n", This->node->type); |
055b5e44 ALH |
862 | str = This->node->name; |
863 | break; | |
864 | } | |
865 | ||
866 | *xmlnodeType = bstr_from_xmlChar( str ); | |
867 | if (!*xmlnodeType) | |
868 | return S_FALSE; | |
869 | ||
870 | return S_OK; | |
65293d8e MM |
871 | } |
872 | ||
873 | static HRESULT WINAPI xmlnode_get_text( | |
874 | IXMLDOMNode *iface, | |
875 | BSTR* text) | |
876 | { | |
23f192d2 | 877 | xmlnode *This = impl_from_IXMLDOMNode( iface ); |
23f192d2 | 878 | BSTR str = NULL; |
549befe7 | 879 | xmlChar *pContent; |
23f192d2 | 880 | |
549befe7 | 881 | TRACE("%p type %d\n", This, This->node->type); |
23f192d2 MM |
882 | |
883 | if ( !text ) | |
884 | return E_INVALIDARG; | |
885 | ||
549befe7 ALH |
886 | pContent = xmlNodeGetContent((xmlNodePtr)This->node); |
887 | if(pContent) | |
04d5d0a6 | 888 | { |
549befe7 ALH |
889 | str = bstr_from_xmlChar(pContent); |
890 | xmlFree(pContent); | |
04d5d0a6 | 891 | } |
c443674d ALH |
892 | |
893 | /* Always return a string. */ | |
894 | if (!str) str = SysAllocStringLen( NULL, 0 ); | |
895 | ||
23f192d2 MM |
896 | TRACE("%p %s\n", This, debugstr_w(str) ); |
897 | *text = str; | |
898 | ||
899 | return S_OK; | |
65293d8e MM |
900 | } |
901 | ||
902 | static HRESULT WINAPI xmlnode_put_text( | |
903 | IXMLDOMNode *iface, | |
904 | BSTR text) | |
905 | { | |
b2101b81 | 906 | xmlnode *This = impl_from_IXMLDOMNode( iface ); |
e55da04e | 907 | xmlChar *str, *str2; |
b2101b81 ALH |
908 | |
909 | TRACE("%p\n", This); | |
910 | ||
911 | switch(This->node->type) | |
912 | { | |
913 | case XML_DOCUMENT_NODE: | |
914 | return E_FAIL; | |
915 | default: | |
916 | break; | |
917 | } | |
918 | ||
6a5dda71 | 919 | str = xmlChar_from_wchar(text); |
b2101b81 ALH |
920 | |
921 | /* Escape the string. */ | |
ae2017a9 MK |
922 | str2 = xmlEncodeEntitiesReentrant(This->node->doc, str); |
923 | HeapFree(GetProcessHeap(), 0, str); | |
b2101b81 | 924 | |
e55da04e MK |
925 | xmlNodeSetContent(This->node, str2); |
926 | xmlFree(str2); | |
b2101b81 ALH |
927 | |
928 | return S_OK; | |
65293d8e MM |
929 | } |
930 | ||
931 | static HRESULT WINAPI xmlnode_get_specified( | |
932 | IXMLDOMNode *iface, | |
933 | VARIANT_BOOL* isSpecified) | |
934 | { | |
935 | FIXME("\n"); | |
936 | return E_NOTIMPL; | |
937 | } | |
938 | ||
939 | static HRESULT WINAPI xmlnode_get_definition( | |
940 | IXMLDOMNode *iface, | |
941 | IXMLDOMNode** definitionNode) | |
942 | { | |
943 | FIXME("\n"); | |
944 | return E_NOTIMPL; | |
945 | } | |
946 | ||
2b7ae268 | 947 | static HRESULT WINAPI xmlnode_get_nodeTypedValue( |
65293d8e MM |
948 | IXMLDOMNode *iface, |
949 | VARIANT* typedValue) | |
950 | { | |
13606ed4 ALH |
951 | xmlnode *This = impl_from_IXMLDOMNode( iface ); |
952 | HRESULT r = S_FALSE; | |
953 | ||
954 | FIXME("ignoring data type %p %p\n", This, typedValue); | |
955 | ||
956 | if(!typedValue) | |
957 | return E_INVALIDARG; | |
958 | ||
959 | V_VT(typedValue) = VT_NULL; | |
960 | ||
961 | switch ( This->node->type ) | |
962 | { | |
963 | case XML_ELEMENT_NODE: | |
964 | { | |
965 | xmlChar *content = xmlNodeGetContent(This->node); | |
966 | V_VT(typedValue) = VT_BSTR; | |
967 | V_BSTR(typedValue) = bstr_from_xmlChar( content ); | |
968 | xmlFree(content); | |
969 | r = S_OK; | |
970 | break; | |
971 | } | |
972 | default: | |
973 | r = xmlnode_get_nodeValue(iface, typedValue); | |
974 | } | |
975 | ||
976 | return r; | |
65293d8e MM |
977 | } |
978 | ||
2b7ae268 | 979 | static HRESULT WINAPI xmlnode_put_nodeTypedValue( |
65293d8e MM |
980 | IXMLDOMNode *iface, |
981 | VARIANT typedValue) | |
982 | { | |
983 | FIXME("\n"); | |
984 | return E_NOTIMPL; | |
985 | } | |
986 | ||
987 | static HRESULT WINAPI xmlnode_get_dataType( | |
988 | IXMLDOMNode *iface, | |
989 | VARIANT* dataTypeName) | |
990 | { | |
e989d48f ALH |
991 | xmlnode *This = impl_from_IXMLDOMNode( iface ); |
992 | xmlChar *pVal; | |
993 | ||
994 | TRACE("iface %p\n", iface); | |
995 | ||
996 | if(!dataTypeName) | |
997 | return E_INVALIDARG; | |
998 | ||
8c3dd87f | 999 | /* Attribute, CDATA Section, Comment, Document, Document Fragment, |
e989d48f ALH |
1000 | Entity, Notation, PI, and Text Node are non-typed. */ |
1001 | V_BSTR(dataTypeName) = NULL; | |
1002 | V_VT(dataTypeName) = VT_NULL; | |
1003 | ||
1004 | switch ( This->node->type ) | |
1005 | { | |
e989d48f ALH |
1006 | case XML_ELEMENT_NODE: |
1007 | pVal = xmlGetNsProp(This->node, (xmlChar*)"dt", | |
1008 | (xmlChar*)"urn:schemas-microsoft-com:datatypes"); | |
1009 | if (pVal) | |
1010 | { | |
1011 | V_VT(dataTypeName) = VT_BSTR; | |
1012 | V_BSTR(dataTypeName) = bstr_from_xmlChar( pVal ); | |
1013 | xmlFree(pVal); | |
1014 | } | |
1015 | break; | |
1016 | case XML_ENTITY_REF_NODE: | |
1017 | FIXME("XML_ENTITY_REF_NODE should return a valid value.\n"); | |
1018 | break; | |
1019 | default: | |
1020 | TRACE("Type %d returning NULL\n", This->node->type); | |
1021 | } | |
1022 | ||
1023 | /* non-typed nodes return S_FALSE */ | |
1024 | if(V_VT(dataTypeName) == VT_NULL) | |
1025 | { | |
1026 | return S_FALSE; | |
1027 | } | |
1028 | ||
1029 | return S_OK; | |
65293d8e MM |
1030 | } |
1031 | ||
1032 | static HRESULT WINAPI xmlnode_put_dataType( | |
1033 | IXMLDOMNode *iface, | |
1034 | BSTR dataTypeName) | |
1035 | { | |
3c4cc5fb ALH |
1036 | xmlnode *This = impl_from_IXMLDOMNode( iface ); |
1037 | HRESULT hr = E_FAIL; | |
1038 | ||
1039 | TRACE("iface %p\n", iface); | |
1040 | ||
1041 | if(dataTypeName == NULL) | |
1042 | return E_INVALIDARG; | |
1043 | ||
1044 | /* An example of this is. The Text in the node needs to be a 0 or 1 for a boolean type. | |
1045 | This applies to changing types (string->bool) or setting a new one | |
1046 | */ | |
1047 | FIXME("Need to Validate the data before allowing a type to be set.\n"); | |
1048 | ||
1049 | /* Check all supported types. */ | |
1050 | if(lstrcmpiW(dataTypeName,szString) == 0 || | |
1051 | lstrcmpiW(dataTypeName,szNumber) == 0 || | |
1052 | lstrcmpiW(dataTypeName,szUUID) == 0 || | |
1053 | lstrcmpiW(dataTypeName,szInt) == 0 || | |
1054 | lstrcmpiW(dataTypeName,szI4) == 0 || | |
1055 | lstrcmpiW(dataTypeName,szFixed) == 0 || | |
1056 | lstrcmpiW(dataTypeName,szBoolean) == 0 || | |
1057 | lstrcmpiW(dataTypeName,szDateTime) == 0 || | |
1058 | lstrcmpiW(dataTypeName,szDateTimeTZ) == 0 || | |
1059 | lstrcmpiW(dataTypeName,szDate) == 0 || | |
1060 | lstrcmpiW(dataTypeName,szTime) == 0 || | |
1061 | lstrcmpiW(dataTypeName,szTimeTZ) == 0 || | |
1062 | lstrcmpiW(dataTypeName,szI1) == 0 || | |
3c4cc5fb ALH |
1063 | lstrcmpiW(dataTypeName,szI2) == 0 || |
1064 | lstrcmpiW(dataTypeName,szIU1) == 0 || | |
1065 | lstrcmpiW(dataTypeName,szIU2) == 0 || | |
1066 | lstrcmpiW(dataTypeName,szIU4) == 0 || | |
1067 | lstrcmpiW(dataTypeName,szR4) == 0 || | |
1068 | lstrcmpiW(dataTypeName,szR8) == 0 || | |
1069 | lstrcmpiW(dataTypeName,szFloat) == 0 || | |
1070 | lstrcmpiW(dataTypeName,szBinHex) == 0 || | |
1071 | lstrcmpiW(dataTypeName,szBinBase64) == 0) | |
1072 | { | |
1073 | xmlNsPtr pNS = NULL; | |
1074 | xmlAttrPtr pAttr = NULL; | |
6a5dda71 | 1075 | xmlChar* str = xmlChar_from_wchar(dataTypeName); |
3c4cc5fb ALH |
1076 | |
1077 | pAttr = xmlHasNsProp(This->node, (xmlChar*)"dt", | |
1078 | (xmlChar*)"urn:schemas-microsoft-com:datatypes"); | |
1079 | if (pAttr) | |
1080 | { | |
1081 | pAttr = xmlSetNsProp(This->node, pAttr->ns, (xmlChar*)"dt", str); | |
1082 | ||
1083 | hr = S_OK; | |
1084 | } | |
1085 | else | |
1086 | { | |
1087 | pNS = xmlNewNs(This->node, (xmlChar*)"urn:schemas-microsoft-com:datatypes", (xmlChar*)"dt"); | |
1088 | if(pNS) | |
1089 | { | |
1090 | pAttr = xmlNewNsProp(This->node, pNS, (xmlChar*)"dt", str); | |
1091 | if(pAttr) | |
1092 | { | |
1093 | xmlAddChild(This->node, (xmlNodePtr)pAttr); | |
1094 | ||
1095 | hr = S_OK; | |
1096 | } | |
1097 | else | |
1098 | ERR("Failed to create Attribute\n"); | |
1099 | } | |
1100 | else | |
1101 | ERR("Failed to Create Namepsace\n"); | |
1102 | } | |
ae2017a9 | 1103 | HeapFree( GetProcessHeap(), 0, str ); |
3c4cc5fb ALH |
1104 | } |
1105 | ||
1106 | return hr; | |
65293d8e MM |
1107 | } |
1108 | ||
95660514 ALH |
1109 | static BSTR EnsureCorrectEOL(BSTR sInput) |
1110 | { | |
1111 | static const WCHAR SZ_RETURN[] = {'\n',0}; | |
1112 | static const WCHAR SZ_LINEFEED[] = {'\r',0}; | |
1113 | int nNum = 0; | |
1114 | BSTR sNew; | |
1115 | int nLen; | |
1116 | int i; | |
1117 | ||
1118 | nLen = lstrlenW(sInput); | |
1119 | /* Count line endings */ | |
1120 | for(i=0; i < nLen; i++) | |
1121 | { | |
1122 | if(sInput[i] == SZ_RETURN[0]) | |
1123 | nNum++; | |
1124 | } | |
1125 | ||
1126 | TRACE("len=%d, num=%d\n", nLen, nNum); | |
1127 | ||
1128 | /* Add linefeed as needed */ | |
1129 | if(nNum > 0) | |
1130 | { | |
1131 | int nPlace = 0; | |
1132 | sNew = SysAllocStringLen(NULL, nLen + nNum+1); | |
1133 | for(i=0; i < nLen; i++) | |
1134 | { | |
1135 | if(sInput[i] == SZ_RETURN[0]) | |
1136 | { | |
1137 | sNew[i+nPlace] = SZ_LINEFEED[0]; | |
1138 | nPlace++; | |
1139 | } | |
1140 | sNew[i+nPlace] = sInput[i]; | |
1141 | } | |
1142 | ||
1143 | SysFreeString(sInput); | |
1144 | } | |
1145 | else | |
1146 | { | |
1147 | sNew = sInput; | |
1148 | } | |
1149 | ||
1150 | TRACE("len %d\n", lstrlenW(sNew)); | |
1151 | ||
1152 | return sNew; | |
1153 | } | |
1154 | ||
eb72aa05 PC |
1155 | /* Removes encoding information and last character (nullbyte) */ |
1156 | static BSTR EnsureNoEncoding(BSTR sInput) | |
1157 | { | |
1158 | static const WCHAR wszEncoding[] = {'e','n','c','o','d','i','n','g','='}; | |
1159 | BSTR sNew; | |
1160 | WCHAR *pBeg, *pEnd; | |
1161 | ||
1162 | pBeg = sInput; | |
1163 | while(*pBeg != '\n' && memcmp(pBeg, wszEncoding, sizeof(wszEncoding))) | |
1164 | pBeg++; | |
1165 | ||
1166 | if(*pBeg == '\n') | |
1167 | { | |
1168 | SysReAllocStringLen(&sInput, sInput, SysStringLen(sInput)-1); | |
1169 | return sInput; | |
1170 | } | |
1171 | pBeg--; | |
1172 | ||
1173 | pEnd = pBeg + sizeof(wszEncoding)/sizeof(WCHAR) + 2; | |
1174 | while(*pEnd != '\"') pEnd++; | |
1175 | pEnd++; | |
1176 | ||
1177 | sNew = SysAllocStringLen(NULL, | |
1178 | pBeg-sInput + SysStringLen(sInput)-(pEnd-sInput)-1); | |
1179 | memcpy(sNew, sInput, (pBeg-sInput)*sizeof(WCHAR)); | |
1180 | memcpy(&sNew[pBeg-sInput], pEnd, (SysStringLen(sInput)-(pEnd-sInput)-1)*sizeof(WCHAR)); | |
1181 | ||
1182 | SysFreeString(sInput); | |
1183 | return sNew; | |
1184 | } | |
1185 | ||
95660514 ALH |
1186 | /* |
1187 | * We are trying to replicate the same behaviour as msxml by converting | |
1188 | * line endings to \r\n and using idents as \t. The problem is that msxml | |
1189 | * only formats nodes that have a line ending. Using libxml we cannot | |
1190 | * reproduce behaviour exactly. | |
1191 | * | |
1192 | */ | |
65293d8e MM |
1193 | static HRESULT WINAPI xmlnode_get_xml( |
1194 | IXMLDOMNode *iface, | |
1195 | BSTR* xmlString) | |
1196 | { | |
11331847 ALH |
1197 | xmlnode *This = impl_from_IXMLDOMNode( iface ); |
1198 | xmlBufferPtr pXmlBuf; | |
1199 | int nSize; | |
1200 | ||
95660514 | 1201 | TRACE("iface %p %d\n", iface, This->node->type); |
11331847 ALH |
1202 | |
1203 | if(!xmlString) | |
1204 | return E_INVALIDARG; | |
1205 | ||
1206 | *xmlString = NULL; | |
1207 | ||
1208 | pXmlBuf = xmlBufferCreate(); | |
1209 | if(pXmlBuf) | |
1210 | { | |
95660514 | 1211 | nSize = xmlNodeDump(pXmlBuf, This->node->doc, This->node, 0, 1); |
11331847 ALH |
1212 | if(nSize > 0) |
1213 | { | |
1214 | const xmlChar *pContent; | |
95660514 | 1215 | BSTR bstrContent; |
11331847 | 1216 | |
05faae7b | 1217 | /* Attribute Nodes return a space in front of their name */ |
11331847 ALH |
1218 | pContent = xmlBufferContent(pXmlBuf); |
1219 | if( ((char*)pContent)[0] == ' ') | |
95660514 | 1220 | bstrContent = bstr_from_xmlChar(pContent+1); |
11331847 | 1221 | else |
95660514 | 1222 | bstrContent = bstr_from_xmlChar(pContent); |
11331847 | 1223 | |
eb72aa05 PC |
1224 | switch(This->node->type) |
1225 | { | |
1226 | case XML_ELEMENT_NODE: | |
1227 | *xmlString = EnsureCorrectEOL(bstrContent); | |
1228 | break; | |
1229 | case XML_DOCUMENT_NODE: | |
1230 | *xmlString = EnsureCorrectEOL(bstrContent); | |
1231 | *xmlString = EnsureNoEncoding(*xmlString); | |
1232 | break; | |
1233 | default: | |
1234 | *xmlString = bstrContent; | |
1235 | } | |
11331847 | 1236 | } |
95660514 ALH |
1237 | |
1238 | xmlBufferFree(pXmlBuf); | |
11331847 ALH |
1239 | } |
1240 | ||
1241 | /* Always returns a string. */ | |
1242 | if(*xmlString == NULL) *xmlString = SysAllocStringLen( NULL, 0 ); | |
1243 | ||
1244 | return S_OK; | |
65293d8e MM |
1245 | } |
1246 | ||
1247 | static HRESULT WINAPI xmlnode_transformNode( | |
1248 | IXMLDOMNode *iface, | |
1249 | IXMLDOMNode* styleSheet, | |
1250 | BSTR* xmlString) | |
1251 | { | |
3d384f17 | 1252 | #ifdef SONAME_LIBXSLT |
880bacb5 ALH |
1253 | xmlnode *This = impl_from_IXMLDOMNode( iface ); |
1254 | xmlnode *pStyleSheet = NULL; | |
1255 | xsltStylesheetPtr xsltSS = NULL; | |
1256 | xmlDocPtr result = NULL; | |
1257 | IXMLDOMNode *ssNew; | |
1258 | ||
1259 | TRACE("%p %p %p\n", This, styleSheet, xmlString); | |
1260 | ||
3d384f17 FG |
1261 | if (!libxslt_handle) |
1262 | return E_NOTIMPL; | |
880bacb5 ALH |
1263 | if(!styleSheet || !xmlString) |
1264 | return E_INVALIDARG; | |
1265 | ||
1266 | *xmlString = NULL; | |
1267 | ||
1268 | if(IXMLDOMNode_QueryInterface(styleSheet, &IID_IXMLDOMNode, (LPVOID)&ssNew) == S_OK) | |
1269 | { | |
1270 | pStyleSheet = impl_from_IXMLDOMNode( ssNew ); | |
1271 | ||
3d384f17 | 1272 | xsltSS = pxsltParseStylesheetDoc( pStyleSheet->node->doc); |
880bacb5 ALH |
1273 | if(xsltSS) |
1274 | { | |
3d384f17 | 1275 | result = pxsltApplyStylesheet(xsltSS, This->node->doc, NULL); |
880bacb5 ALH |
1276 | if(result) |
1277 | { | |
42db8b43 | 1278 | const xmlChar *pContent; |
880bacb5 | 1279 | |
42db8b43 | 1280 | if(result->type == XML_HTML_DOCUMENT_NODE) |
880bacb5 | 1281 | { |
42db8b43 ALH |
1282 | xmlOutputBufferPtr pOutput = xmlAllocOutputBuffer(NULL); |
1283 | if(pOutput) | |
880bacb5 | 1284 | { |
42db8b43 | 1285 | htmlDocContentDumpOutput(pOutput, result->doc, NULL); |
3948541a MM |
1286 | pContent = xmlBufferContent(pOutput->buffer); |
1287 | *xmlString = bstr_from_xmlChar(pContent); | |
42db8b43 ALH |
1288 | xmlOutputBufferClose(pOutput); |
1289 | } | |
1290 | } | |
1291 | else | |
1292 | { | |
1293 | xmlBufferPtr pXmlBuf; | |
1294 | int nSize; | |
880bacb5 | 1295 | |
42db8b43 ALH |
1296 | pXmlBuf = xmlBufferCreate(); |
1297 | if(pXmlBuf) | |
1298 | { | |
1299 | nSize = xmlNodeDump(pXmlBuf, NULL, (xmlNodePtr)result, 0, 0); | |
1300 | if(nSize > 0) | |
1301 | { | |
1302 | pContent = xmlBufferContent(pXmlBuf); | |
1303 | *xmlString = bstr_from_xmlChar(pContent); | |
42db8b43 | 1304 | } |
3948541a | 1305 | xmlBufferFree(pXmlBuf); |
880bacb5 ALH |
1306 | } |
1307 | } | |
3948541a | 1308 | xmlFreeDoc(result); |
880bacb5 | 1309 | } |
8524cc17 MM |
1310 | /* libxslt "helpfully" frees the XML document the stylesheet was |
1311 | generated from, too */ | |
1312 | xsltSS->doc = NULL; | |
3d384f17 | 1313 | pxsltFreeStylesheet(xsltSS); |
880bacb5 ALH |
1314 | } |
1315 | ||
1316 | IXMLDOMNode_Release(ssNew); | |
1317 | } | |
1318 | ||
1319 | if(*xmlString == NULL) | |
1320 | *xmlString = SysAllocStringLen(NULL, 0); | |
1321 | ||
1322 | return S_OK; | |
1323 | #else | |
1324 | FIXME("libxslt headers were not found at compile time\n"); | |
65293d8e | 1325 | return E_NOTIMPL; |
880bacb5 | 1326 | #endif |
65293d8e MM |
1327 | } |
1328 | ||
1329 | static HRESULT WINAPI xmlnode_selectNodes( | |
1330 | IXMLDOMNode *iface, | |
1331 | BSTR queryString, | |
1332 | IXMLDOMNodeList** resultList) | |
1333 | { | |
f3719a88 | 1334 | xmlnode *This = impl_from_IXMLDOMNode( iface ); |
f3719a88 MM |
1335 | |
1336 | TRACE("%p %s %p\n", This, debugstr_w(queryString), resultList ); | |
1337 | ||
e1cbec75 | 1338 | return queryresult_create( This->node, queryString, resultList ); |
65293d8e MM |
1339 | } |
1340 | ||
1341 | static HRESULT WINAPI xmlnode_selectSingleNode( | |
1342 | IXMLDOMNode *iface, | |
1343 | BSTR queryString, | |
1344 | IXMLDOMNode** resultNode) | |
1345 | { | |
c3687360 HD |
1346 | xmlnode *This = impl_from_IXMLDOMNode( iface ); |
1347 | IXMLDOMNodeList *list; | |
1348 | HRESULT r; | |
1349 | ||
1350 | TRACE("%p %s %p\n", This, debugstr_w(queryString), resultNode ); | |
1351 | ||
e1cbec75 | 1352 | *resultNode = NULL; |
c3687360 | 1353 | r = IXMLDOMNode_selectNodes(iface, queryString, &list); |
bce90cfb | 1354 | if(r == S_OK) |
c3687360 HD |
1355 | { |
1356 | r = IXMLDOMNodeList_nextNode(list, resultNode); | |
1357 | IXMLDOMNodeList_Release(list); | |
1358 | } | |
1359 | return r; | |
65293d8e MM |
1360 | } |
1361 | ||
1362 | static HRESULT WINAPI xmlnode_get_parsed( | |
1363 | IXMLDOMNode *iface, | |
1364 | VARIANT_BOOL* isParsed) | |
1365 | { | |
1366 | FIXME("\n"); | |
1367 | return E_NOTIMPL; | |
1368 | } | |
1369 | ||
1370 | static HRESULT WINAPI xmlnode_get_namespaceURI( | |
1371 | IXMLDOMNode *iface, | |
1372 | BSTR* namespaceURI) | |
1373 | { | |
8842ccb6 ALH |
1374 | xmlnode *This = impl_from_IXMLDOMNode( iface ); |
1375 | HRESULT hr = S_FALSE; | |
1376 | xmlNsPtr *pNSList; | |
1377 | ||
1378 | TRACE("%p %p\n", This, namespaceURI ); | |
1379 | ||
1380 | if(!namespaceURI) | |
1381 | return E_INVALIDARG; | |
1382 | ||
1383 | *namespaceURI = NULL; | |
1384 | ||
1385 | pNSList = xmlGetNsList(This->node->doc, This->node); | |
1386 | if(pNSList) | |
1387 | { | |
1388 | *namespaceURI = bstr_from_xmlChar( pNSList[0]->href ); | |
1389 | ||
19d635f9 | 1390 | xmlFree( pNSList ); |
8842ccb6 ALH |
1391 | hr = S_OK; |
1392 | } | |
1393 | ||
1394 | return hr; | |
65293d8e MM |
1395 | } |
1396 | ||
1397 | static HRESULT WINAPI xmlnode_get_prefix( | |
1398 | IXMLDOMNode *iface, | |
1399 | BSTR* prefixString) | |
1400 | { | |
38634f0e ALH |
1401 | xmlnode *This = impl_from_IXMLDOMNode( iface ); |
1402 | HRESULT hr = S_FALSE; | |
1403 | xmlNsPtr *pNSList; | |
1404 | ||
1405 | TRACE("%p %p\n", This, prefixString ); | |
1406 | ||
1407 | if(!prefixString) | |
1408 | return E_INVALIDARG; | |
1409 | ||
1410 | *prefixString = NULL; | |
1411 | ||
1412 | pNSList = xmlGetNsList(This->node->doc, This->node); | |
1413 | if(pNSList) | |
1414 | { | |
1415 | *prefixString = bstr_from_xmlChar( pNSList[0]->prefix ); | |
1416 | ||
19d635f9 | 1417 | xmlFree(pNSList); |
38634f0e ALH |
1418 | hr = S_OK; |
1419 | } | |
1420 | ||
1421 | return hr; | |
65293d8e MM |
1422 | } |
1423 | ||
1424 | static HRESULT WINAPI xmlnode_get_baseName( | |
1425 | IXMLDOMNode *iface, | |
1426 | BSTR* nameString) | |
1427 | { | |
23f192d2 MM |
1428 | xmlnode *This = impl_from_IXMLDOMNode( iface ); |
1429 | BSTR str = NULL; | |
1430 | HRESULT r = S_FALSE; | |
1431 | ||
1432 | TRACE("%p %p\n", This, nameString ); | |
1433 | ||
1434 | if ( !nameString ) | |
1435 | return E_INVALIDARG; | |
1436 | ||
1437 | switch ( This->node->type ) | |
1438 | { | |
1439 | case XML_ELEMENT_NODE: | |
1440 | case XML_ATTRIBUTE_NODE: | |
1441 | str = bstr_from_xmlChar( This->node->name ); | |
1442 | r = S_OK; | |
1443 | break; | |
1444 | case XML_TEXT_NODE: | |
1445 | break; | |
1446 | default: | |
1447 | ERR("Unhandled type %d\n", This->node->type ); | |
1448 | break; | |
1449 | } | |
1450 | ||
7ff24491 | 1451 | TRACE("returning %08x str = %s\n", r, debugstr_w( str ) ); |
23f192d2 MM |
1452 | |
1453 | *nameString = str; | |
1454 | return r; | |
65293d8e MM |
1455 | } |
1456 | ||
1457 | static HRESULT WINAPI xmlnode_transformNodeToObject( | |
1458 | IXMLDOMNode *iface, | |
1459 | IXMLDOMNode* stylesheet, | |
1460 | VARIANT outputObject) | |
1461 | { | |
1462 | FIXME("\n"); | |
1463 | return E_NOTIMPL; | |
1464 | } | |
1465 | ||
1466 | static const struct IXMLDOMNodeVtbl xmlnode_vtbl = | |
1467 | { | |
1468 | xmlnode_QueryInterface, | |
1469 | xmlnode_AddRef, | |
1470 | xmlnode_Release, | |
1471 | xmlnode_GetTypeInfoCount, | |
1472 | xmlnode_GetTypeInfo, | |
1473 | xmlnode_GetIDsOfNames, | |
1474 | xmlnode_Invoke, | |
2b7ae268 MM |
1475 | xmlnode_get_nodeName, |
1476 | xmlnode_get_nodeValue, | |
1477 | xmlnode_put_nodeValue, | |
1478 | xmlnode_get_nodeType, | |
65293d8e MM |
1479 | xmlnode_get_parentNode, |
1480 | xmlnode_get_childNodes, | |
1481 | xmlnode_get_firstChild, | |
1482 | xmlnode_get_lastChild, | |
1483 | xmlnode_get_previousSibling, | |
1484 | xmlnode_get_nextSibling, | |
1485 | xmlnode_get_attributes, | |
1486 | xmlnode_insertBefore, | |
1487 | xmlnode_replaceChild, | |
1488 | xmlnode_removeChild, | |
1489 | xmlnode_appendChild, | |
1490 | xmlnode_hasChildNodes, | |
1491 | xmlnode_get_ownerDocument, | |
1492 | xmlnode_cloneNode, | |
2b7ae268 | 1493 | xmlnode_get_nodeTypeString, |
65293d8e MM |
1494 | xmlnode_get_text, |
1495 | xmlnode_put_text, | |
1496 | xmlnode_get_specified, | |
1497 | xmlnode_get_definition, | |
2b7ae268 MM |
1498 | xmlnode_get_nodeTypedValue, |
1499 | xmlnode_put_nodeTypedValue, | |
65293d8e MM |
1500 | xmlnode_get_dataType, |
1501 | xmlnode_put_dataType, | |
1502 | xmlnode_get_xml, | |
1503 | xmlnode_transformNode, | |
1504 | xmlnode_selectNodes, | |
1505 | xmlnode_selectSingleNode, | |
1506 | xmlnode_get_parsed, | |
1507 | xmlnode_get_namespaceURI, | |
1508 | xmlnode_get_prefix, | |
1509 | xmlnode_get_baseName, | |
1510 | xmlnode_transformNodeToObject, | |
1511 | }; | |
1512 | ||
83e91274 | 1513 | void destroy_xmlnode(xmlnode *This) |
65293d8e | 1514 | { |
83e91274 JC |
1515 | if(This->node) |
1516 | xmldoc_release(This->node->doc); | |
3f6bb98f HD |
1517 | } |
1518 | ||
04eff32b | 1519 | void init_xmlnode(xmlnode *This, xmlNodePtr node, IUnknown *outer, dispex_static_data_t *dispex_data ) |
3f6bb98f | 1520 | { |
3f6bb98f HD |
1521 | if(node) |
1522 | xmldoc_add_ref( node->doc ); | |
65293d8e MM |
1523 | |
1524 | This->lpVtbl = &xmlnode_vtbl; | |
1525 | This->ref = 1; | |
23f192d2 | 1526 | This->node = node; |
04eff32b | 1527 | This->pUnkOuter = outer; |
23f192d2 | 1528 | |
04eff32b JC |
1529 | if(dispex_data) |
1530 | init_dispex(&This->dispex, This->pUnkOuter, dispex_data); | |
65293d8e MM |
1531 | } |
1532 | ||
3f6bb98f HD |
1533 | IXMLDOMNode *create_node( xmlNodePtr node ) |
1534 | { | |
1535 | IUnknown *pUnk; | |
1536 | IXMLDOMNode *ret; | |
1537 | HRESULT hr; | |
1538 | ||
1539 | if ( !node ) | |
1540 | return NULL; | |
1541 | ||
1542 | TRACE("type %d\n", node->type); | |
1543 | switch(node->type) | |
1544 | { | |
1545 | case XML_ELEMENT_NODE: | |
c2b2e1ea | 1546 | pUnk = create_element( node ); |
3f6bb98f | 1547 | break; |
a545fee7 HD |
1548 | case XML_ATTRIBUTE_NODE: |
1549 | pUnk = create_attribute( node ); | |
1550 | break; | |
5d629e7c HD |
1551 | case XML_TEXT_NODE: |
1552 | pUnk = create_text( node ); | |
1553 | break; | |
c4ac69b7 ZH |
1554 | case XML_CDATA_SECTION_NODE: |
1555 | pUnk = create_cdata( node ); | |
1556 | break; | |
a545fee7 HD |
1557 | case XML_COMMENT_NODE: |
1558 | pUnk = create_comment( node ); | |
1559 | break; | |
3f6bb98f | 1560 | case XML_DOCUMENT_NODE: |
89f1bfab ZH |
1561 | pUnk = create_domdoc( node ); |
1562 | break; | |
04eff32b JC |
1563 | default: { |
1564 | xmlnode *new_node; | |
1565 | ||
3f6bb98f | 1566 | FIXME("only creating basic node for type %d\n", node->type); |
04eff32b JC |
1567 | |
1568 | new_node = heap_alloc(sizeof(xmlnode)); | |
1569 | if(!new_node) | |
1570 | return NULL; | |
1571 | ||
1572 | init_xmlnode(new_node, node, NULL, NULL); | |
1573 | pUnk = (IUnknown*)IXMLDOMNode_from_impl(new_node); | |
1574 | } | |
3f6bb98f HD |
1575 | } |
1576 | ||
1577 | hr = IUnknown_QueryInterface(pUnk, &IID_IXMLDOMNode, (LPVOID*)&ret); | |
1578 | IUnknown_Release(pUnk); | |
1579 | if(FAILED(hr)) return NULL; | |
1580 | return ret; | |
1581 | } | |
65293d8e | 1582 | #endif |