4 * Copyright 2005 Mike McCormack
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
34 #include "msxml_private.h"
37 # include <libxml/HTMLtree.h>
40 #include "wine/debug.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(msxml
);
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};
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};
69 static inline xmlnode
*impl_from_InternalUnknown( IUnknown
*iface
)
71 return (xmlnode
*)((char*)iface
- FIELD_OFFSET(xmlnode
, lpInternalUnkVtbl
));
74 xmlNodePtr
xmlNodePtr_from_domnode( IXMLDOMNode
*iface
, xmlElementType type
)
80 This
= impl_from_IXMLDOMNode( iface
);
83 if ( type
&& This
->node
->type
!= type
)
88 static HRESULT WINAPI
xmlnode_QueryInterface(
93 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
94 TRACE("%p %s %p\n", This
, debugstr_guid(riid
), ppvObject
);
96 return IUnknown_QueryInterface(This
->pUnkOuter
, riid
, ppvObject
);
99 static ULONG WINAPI
xmlnode_AddRef(
102 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
103 return IUnknown_AddRef(This
->pUnkOuter
);
106 static ULONG WINAPI
xmlnode_Release(
109 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
110 return IUnknown_Release(This
->pUnkOuter
);
113 static HRESULT WINAPI
xmlnode_GetTypeInfoCount(
117 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
119 TRACE("(%p)->(%p)\n", This
, pctinfo
);
126 static HRESULT WINAPI
xmlnode_GetTypeInfo(
130 ITypeInfo
** ppTInfo
)
132 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
135 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
137 hr
= get_typeinfo(IXMLDOMNode_tid
, ppTInfo
);
142 static HRESULT WINAPI
xmlnode_GetIDsOfNames(
150 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
155 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
158 if(!rgszNames
|| cNames
== 0 || !rgDispId
)
161 hr
= get_typeinfo(IXMLDOMNode_tid
, &typeinfo
);
164 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
165 ITypeInfo_Release(typeinfo
);
171 static HRESULT WINAPI
xmlnode_Invoke(
177 DISPPARAMS
* pDispParams
,
179 EXCEPINFO
* pExcepInfo
,
182 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
186 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
187 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
189 hr
= get_typeinfo(IXMLDOMNode_tid
, &typeinfo
);
192 hr
= ITypeInfo_Invoke(typeinfo
, &(This
->lpVtbl
), dispIdMember
, wFlags
, pDispParams
,
193 pVarResult
, pExcepInfo
, puArgErr
);
194 ITypeInfo_Release(typeinfo
);
200 static HRESULT WINAPI
xmlnode_get_nodeName(
204 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
207 TRACE("%p\n", This
);
215 switch( This
->node
->type
)
217 case XML_CDATA_SECTION_NODE
:
218 str
= (const xmlChar
*) "#cdata-section";
220 case XML_COMMENT_NODE
:
221 str
= (const xmlChar
*) "#comment";
223 case XML_DOCUMENT_FRAG_NODE
:
224 str
= (const xmlChar
*) "#document-fragment";
227 str
= (const xmlChar
*) "#text";
229 case XML_DOCUMENT_NODE
:
230 str
= (const xmlChar
*) "#document";
232 case XML_ATTRIBUTE_NODE
:
233 case XML_ELEMENT_NODE
:
235 str
= This
->node
->name
;
238 FIXME("nodeName not mapped correctly (%d)\n", This
->node
->type
);
239 str
= This
->node
->name
;
243 *name
= bstr_from_xmlChar( str
);
250 BSTR
bstr_from_xmlChar( const xmlChar
*buf
)
259 len
= MultiByteToWideChar( CP_UTF8
, 0, (LPCSTR
) buf
, -1, NULL
, 0 );
260 str
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof (WCHAR
) );
263 MultiByteToWideChar( CP_UTF8
, 0, (LPCSTR
) buf
, -1, str
, len
);
264 bstr
= SysAllocString( str
);
265 HeapFree( GetProcessHeap(), 0, str
);
269 static HRESULT WINAPI
xmlnode_get_nodeValue(
273 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
276 TRACE("%p %p\n", This
, value
);
281 V_BSTR(value
) = NULL
;
282 V_VT(value
) = VT_NULL
;
284 switch ( This
->node
->type
)
286 case XML_CDATA_SECTION_NODE
:
287 case XML_COMMENT_NODE
:
289 case XML_ATTRIBUTE_NODE
:
291 xmlChar
*content
= xmlNodeGetContent(This
->node
);
292 V_VT(value
) = VT_BSTR
;
293 V_BSTR(value
) = bstr_from_xmlChar( content
);
299 V_VT(value
) = VT_BSTR
;
300 V_BSTR(value
) = bstr_from_xmlChar( This
->node
->content
);
303 case XML_ELEMENT_NODE
:
304 case XML_DOCUMENT_NODE
:
305 /* these seem to return NULL */
309 FIXME("node %p type %d\n", This
, This
->node
->type
);
312 TRACE("%p returned %s\n", This
, debugstr_w( V_BSTR(value
) ) );
317 static HRESULT WINAPI
xmlnode_put_nodeValue(
321 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
324 VARIANT string_value
;
326 TRACE("%p type(%d)\n", This
, This
->node
->type
);
328 VariantInit(&string_value
);
329 hr
= VariantChangeType(&string_value
, &value
, 0, VT_BSTR
);
332 VariantClear(&string_value
);
333 WARN("Couldn't convert to VT_BSTR\n");
338 /* Document, Document Fragment, Document Type, Element,
339 Entity, Entity Reference, Notation aren't supported. */
340 switch ( This
->node
->type
)
342 case XML_ATTRIBUTE_NODE
:
343 case XML_CDATA_SECTION_NODE
:
344 case XML_COMMENT_NODE
:
348 str
= xmlChar_from_wchar(V_BSTR(&string_value
));
349 xmlNodeSetContent(This
->node
, str
);
350 HeapFree(GetProcessHeap(),0,str
);
355 /* Do nothing for unsupported types. */
359 VariantClear(&string_value
);
364 static HRESULT WINAPI
xmlnode_get_nodeType(
368 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
370 TRACE("%p %p\n", This
, type
);
372 assert( (int)NODE_ELEMENT
== (int)XML_ELEMENT_NODE
);
373 assert( (int)NODE_NOTATION
== (int)XML_NOTATION_NODE
);
375 *type
= This
->node
->type
;
380 static HRESULT
get_node(
386 TRACE("%p->%s %p\n", This
, name
, node
);
391 /* if we don't have a doc, use our parent. */
392 if(node
&& !node
->doc
&& node
->parent
)
393 node
->doc
= node
->parent
->doc
;
395 *out
= create_node( node
);
401 static HRESULT WINAPI
xmlnode_get_parentNode(
403 IXMLDOMNode
** parent
)
405 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
406 return get_node( This
, "parent", This
->node
->parent
, parent
);
409 static HRESULT WINAPI
xmlnode_get_childNodes(
411 IXMLDOMNodeList
** childList
)
413 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
415 TRACE("%p %p\n", This
, childList
);
420 *childList
= create_children_nodelist(This
->node
);
421 if (*childList
== NULL
)
422 return E_OUTOFMEMORY
;
427 static HRESULT WINAPI
xmlnode_get_firstChild(
429 IXMLDOMNode
** firstChild
)
431 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
432 return get_node( This
, "firstChild", This
->node
->children
, firstChild
);
435 static HRESULT WINAPI
xmlnode_get_lastChild(
437 IXMLDOMNode
** lastChild
)
439 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
441 TRACE("%p\n", This
);
446 switch( This
->node
->type
)
448 /* CDATASection, Comment, PI and Text Nodes do not support lastChild */
450 case XML_CDATA_SECTION_NODE
:
452 case XML_COMMENT_NODE
:
456 return get_node( This
, "lastChild", This
->node
->last
, lastChild
);
460 static HRESULT WINAPI
xmlnode_get_previousSibling(
462 IXMLDOMNode
** previousSibling
)
464 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
466 TRACE("%p\n", This
);
468 if (!previousSibling
)
471 switch( This
->node
->type
)
473 /* Attribute, Document and Document Fragment Nodes do not support previousSibling */
474 case XML_DOCUMENT_NODE
:
475 case XML_DOCUMENT_FRAG_NODE
:
476 case XML_ATTRIBUTE_NODE
:
477 *previousSibling
= NULL
;
480 return get_node( This
, "previous", This
->node
->prev
, previousSibling
);
484 static HRESULT WINAPI
xmlnode_get_nextSibling(
486 IXMLDOMNode
** nextSibling
)
488 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
490 TRACE("%p\n", This
);
495 switch( This
->node
->type
)
497 /* Attribute, Document and Document Fragment Nodes do not support nextSibling */
498 case XML_DOCUMENT_NODE
:
499 case XML_DOCUMENT_FRAG_NODE
:
500 case XML_ATTRIBUTE_NODE
:
504 return get_node( This
, "next", This
->node
->next
, nextSibling
);
508 static HRESULT WINAPI
xmlnode_get_attributes(
510 IXMLDOMNamedNodeMap
** attributeMap
)
512 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
518 switch( This
->node
->type
)
520 /* Attribute, CDataSection, Comment, Documents, Documents Fragments,
521 Entity and Text Nodes does not support get_attributes */
522 case XML_ATTRIBUTE_NODE
:
523 case XML_CDATA_SECTION_NODE
:
524 case XML_COMMENT_NODE
:
525 case XML_DOCUMENT_NODE
:
526 case XML_DOCUMENT_FRAG_NODE
:
527 case XML_ENTITY_NODE
:
528 case XML_ENTITY_REF_NODE
:
530 *attributeMap
= NULL
;
533 *attributeMap
= create_nodemap( iface
);
538 static HRESULT WINAPI
xmlnode_insertBefore(
540 IXMLDOMNode
* newChild
,
542 IXMLDOMNode
** outNewChild
)
544 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
545 xmlNodePtr before_node
, new_child_node
;
546 IXMLDOMNode
*before
= NULL
, *new;
549 TRACE("(%p)->(%p,var,%p)\n",This
,newChild
,outNewChild
);
554 switch(V_VT(&refChild
))
561 hr
= IUnknown_QueryInterface(V_UNKNOWN(&refChild
), &IID_IXMLDOMNode
, (LPVOID
)&before
);
562 if(FAILED(hr
)) return hr
;
566 hr
= IDispatch_QueryInterface(V_DISPATCH(&refChild
), &IID_IXMLDOMNode
, (LPVOID
)&before
);
567 if(FAILED(hr
)) return hr
;
571 FIXME("refChild var type %x\n", V_VT(&refChild
));
575 IXMLDOMNode_QueryInterface(newChild
, &IID_IXMLDOMNode
, (LPVOID
)&new);
576 new_child_node
= impl_from_IXMLDOMNode(new)->node
;
577 TRACE("new_child_node %p This->node %p\n", new_child_node
, This
->node
);
579 if(!new_child_node
->parent
)
580 if(xmldoc_remove_orphan(new_child_node
->doc
, new_child_node
) != S_OK
)
581 WARN("%p is not an orphan of %p\n", new_child_node
, new_child_node
->doc
);
585 before_node
= impl_from_IXMLDOMNode(before
)->node
;
586 xmlAddPrevSibling(before_node
, new_child_node
);
587 IXMLDOMNode_Release(before
);
591 xmlAddChild(This
->node
, new_child_node
);
594 IXMLDOMNode_Release(new);
595 IXMLDOMNode_AddRef(newChild
);
597 *outNewChild
= newChild
;
603 static HRESULT WINAPI
xmlnode_replaceChild(
605 IXMLDOMNode
* newChild
,
606 IXMLDOMNode
* oldChild
,
607 IXMLDOMNode
** outOldChild
)
609 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
610 xmlNode
*old_child_ptr
, *new_child_ptr
;
611 xmlDocPtr leaving_doc
;
612 xmlNode
*my_ancestor
;
613 IXMLDOMNode
*realOldChild
;
616 TRACE("%p->(%p,%p,%p)\n",This
,newChild
,oldChild
,outOldChild
);
618 /* Do not believe any documentation telling that newChild == NULL
619 means removal. It does certainly *not* apply to msxml3! */
620 if(!newChild
|| !oldChild
)
626 hr
= IXMLDOMNode_QueryInterface(oldChild
,&IID_IXMLDOMNode
,(LPVOID
*)&realOldChild
);
630 old_child_ptr
= impl_from_IXMLDOMNode(realOldChild
)->node
;
631 IXMLDOMNode_Release(realOldChild
);
632 if(old_child_ptr
->parent
!= This
->node
)
634 WARN("childNode %p is not a child of %p\n", oldChild
, iface
);
638 new_child_ptr
= impl_from_IXMLDOMNode(newChild
)->node
;
639 my_ancestor
= This
->node
;
642 if(my_ancestor
== new_child_ptr
)
644 WARN("tried to create loop\n");
647 my_ancestor
= my_ancestor
->parent
;
650 if(!new_child_ptr
->parent
)
651 if(xmldoc_remove_orphan(new_child_ptr
->doc
, new_child_ptr
) != S_OK
)
652 WARN("%p is not an orphan of %p\n", new_child_ptr
, new_child_ptr
->doc
);
654 leaving_doc
= new_child_ptr
->doc
;
655 xmldoc_add_ref(old_child_ptr
->doc
);
656 xmlReplaceNode(old_child_ptr
, new_child_ptr
);
657 xmldoc_release(leaving_doc
);
659 xmldoc_add_orphan(old_child_ptr
->doc
, old_child_ptr
);
663 IXMLDOMNode_AddRef(oldChild
);
664 *outOldChild
= oldChild
;
670 static HRESULT WINAPI
xmlnode_removeChild(
672 IXMLDOMNode
* childNode
,
673 IXMLDOMNode
** oldChild
)
675 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
676 xmlNode
*child_node_ptr
;
680 TRACE("%p->(%p, %p)\n", This
, childNode
, oldChild
);
682 if(!childNode
) return E_INVALIDARG
;
687 hr
= IXMLDOMNode_QueryInterface(childNode
, &IID_IXMLDOMNode
, (LPVOID
)&child
);
691 child_node_ptr
= impl_from_IXMLDOMNode(child
)->node
;
692 if(child_node_ptr
->parent
!= This
->node
)
694 WARN("childNode %p is not a child of %p\n", childNode
, iface
);
695 IXMLDOMNode_Release(child
);
699 xmlUnlinkNode(child_node_ptr
);
701 IXMLDOMNode_Release(child
);
705 IXMLDOMNode_AddRef(childNode
);
706 *oldChild
= childNode
;
712 static HRESULT WINAPI
xmlnode_appendChild(
714 IXMLDOMNode
* newChild
,
715 IXMLDOMNode
** outNewChild
)
717 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
722 TRACE("(%p)->(%p,%p)\n", This
, newChild
, outNewChild
);
724 hr
= IXMLDOMNode_get_nodeType(newChild
, &type
);
725 if(FAILED(hr
) || type
== NODE_ATTRIBUTE
) {
726 if(outNewChild
) *outNewChild
= NULL
;
731 return IXMLDOMNode_insertBefore(iface
, newChild
, var
, outNewChild
);
734 static HRESULT WINAPI
xmlnode_hasChildNodes(
736 VARIANT_BOOL
* hasChild
)
738 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
744 if (!This
->node
->children
)
746 *hasChild
= VARIANT_FALSE
;
750 *hasChild
= VARIANT_TRUE
;
754 static HRESULT WINAPI
xmlnode_get_ownerDocument(
756 IXMLDOMDocument
** DOMDocument
)
758 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
760 TRACE("%p (%p)\n", This
, DOMDocument
);
762 return DOMDocument_create_from_xmldoc(This
->node
->doc
, (IXMLDOMDocument2
**)DOMDocument
);
765 static HRESULT WINAPI
xmlnode_cloneNode(
768 IXMLDOMNode
** cloneRoot
)
770 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
771 xmlNodePtr pClone
= NULL
;
772 IXMLDOMNode
*pNode
= NULL
;
774 TRACE("%p (%d)\n", This
, deep
);
779 pClone
= xmlCopyNode(This
->node
, deep
? 1 : 2);
782 pClone
->doc
= This
->node
->doc
;
783 xmldoc_add_orphan(pClone
->doc
, pClone
);
785 pNode
= create_node(pClone
);
788 ERR("Copy failed\n");
796 ERR("Copy failed\n");
803 static HRESULT WINAPI
xmlnode_get_nodeTypeString(
807 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
810 TRACE("%p\n", This
);
818 switch( This
->node
->type
)
820 case XML_ATTRIBUTE_NODE
:
821 str
= (const xmlChar
*) "attribute";
823 case XML_CDATA_SECTION_NODE
:
824 str
= (const xmlChar
*) "cdatasection";
826 case XML_COMMENT_NODE
:
827 str
= (const xmlChar
*) "comment";
829 case XML_DOCUMENT_NODE
:
830 str
= (const xmlChar
*) "document";
832 case XML_DOCUMENT_FRAG_NODE
:
833 str
= (const xmlChar
*) "documentfragment";
835 case XML_ELEMENT_NODE
:
836 str
= (const xmlChar
*) "element";
838 case XML_ENTITY_NODE
:
839 str
= (const xmlChar
*) "entity";
841 case XML_ENTITY_REF_NODE
:
842 str
= (const xmlChar
*) "entityreference";
844 case XML_NOTATION_NODE
:
845 str
= (const xmlChar
*) "notation";
848 str
= (const xmlChar
*) "processinginstruction";
851 str
= (const xmlChar
*) "text";
854 FIXME("Unknown node type (%d)\n", This
->node
->type
);
855 str
= This
->node
->name
;
859 *xmlnodeType
= bstr_from_xmlChar( str
);
866 static HRESULT WINAPI
xmlnode_get_text(
870 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
874 TRACE("%p type %d\n", This
, This
->node
->type
);
879 pContent
= xmlNodeGetContent((xmlNodePtr
)This
->node
);
882 str
= bstr_from_xmlChar(pContent
);
886 /* Always return a string. */
887 if (!str
) str
= SysAllocStringLen( NULL
, 0 );
889 TRACE("%p %s\n", This
, debugstr_w(str
) );
895 static HRESULT WINAPI
xmlnode_put_text(
899 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
904 switch(This
->node
->type
)
906 case XML_DOCUMENT_NODE
:
912 str
= xmlChar_from_wchar(text
);
914 /* Escape the string. */
915 str2
= xmlEncodeEntitiesReentrant(This
->node
->doc
, str
);
916 HeapFree(GetProcessHeap(), 0, str
);
918 xmlNodeSetContent(This
->node
, str2
);
924 static HRESULT WINAPI
xmlnode_get_specified(
926 VARIANT_BOOL
* isSpecified
)
932 static HRESULT WINAPI
xmlnode_get_definition(
934 IXMLDOMNode
** definitionNode
)
940 static HRESULT WINAPI
xmlnode_get_nodeTypedValue(
944 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
947 FIXME("ignoring data type %p %p\n", This
, typedValue
);
952 V_VT(typedValue
) = VT_NULL
;
954 switch ( This
->node
->type
)
956 case XML_ELEMENT_NODE
:
958 xmlChar
*content
= xmlNodeGetContent(This
->node
);
959 V_VT(typedValue
) = VT_BSTR
;
960 V_BSTR(typedValue
) = bstr_from_xmlChar( content
);
966 r
= xmlnode_get_nodeValue(iface
, typedValue
);
972 static HRESULT WINAPI
xmlnode_put_nodeTypedValue(
980 static HRESULT WINAPI
xmlnode_get_dataType(
982 VARIANT
* dataTypeName
)
984 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
987 TRACE("iface %p\n", iface
);
992 /* Attribute, CDATA Section, Comment, Document, Document Fragment,
993 Entity, Notation, PI, and Text Node are non-typed. */
994 V_BSTR(dataTypeName
) = NULL
;
995 V_VT(dataTypeName
) = VT_NULL
;
997 switch ( This
->node
->type
)
999 case XML_ELEMENT_NODE
:
1000 pVal
= xmlGetNsProp(This
->node
, (xmlChar
*)"dt",
1001 (xmlChar
*)"urn:schemas-microsoft-com:datatypes");
1004 V_VT(dataTypeName
) = VT_BSTR
;
1005 V_BSTR(dataTypeName
) = bstr_from_xmlChar( pVal
);
1009 case XML_ENTITY_REF_NODE
:
1010 FIXME("XML_ENTITY_REF_NODE should return a valid value.\n");
1013 TRACE("Type %d returning NULL\n", This
->node
->type
);
1016 /* non-typed nodes return S_FALSE */
1017 if(V_VT(dataTypeName
) == VT_NULL
)
1025 static HRESULT WINAPI
xmlnode_put_dataType(
1029 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
1030 HRESULT hr
= E_FAIL
;
1032 TRACE("iface %p\n", iface
);
1034 if(dataTypeName
== NULL
)
1035 return E_INVALIDARG
;
1037 /* An example of this is. The Text in the node needs to be a 0 or 1 for a boolean type.
1038 This applies to changing types (string->bool) or setting a new one
1040 FIXME("Need to Validate the data before allowing a type to be set.\n");
1042 /* Check all supported types. */
1043 if(lstrcmpiW(dataTypeName
,szString
) == 0 ||
1044 lstrcmpiW(dataTypeName
,szNumber
) == 0 ||
1045 lstrcmpiW(dataTypeName
,szUUID
) == 0 ||
1046 lstrcmpiW(dataTypeName
,szInt
) == 0 ||
1047 lstrcmpiW(dataTypeName
,szI4
) == 0 ||
1048 lstrcmpiW(dataTypeName
,szFixed
) == 0 ||
1049 lstrcmpiW(dataTypeName
,szBoolean
) == 0 ||
1050 lstrcmpiW(dataTypeName
,szDateTime
) == 0 ||
1051 lstrcmpiW(dataTypeName
,szDateTimeTZ
) == 0 ||
1052 lstrcmpiW(dataTypeName
,szDate
) == 0 ||
1053 lstrcmpiW(dataTypeName
,szTime
) == 0 ||
1054 lstrcmpiW(dataTypeName
,szTimeTZ
) == 0 ||
1055 lstrcmpiW(dataTypeName
,szI1
) == 0 ||
1056 lstrcmpiW(dataTypeName
,szI2
) == 0 ||
1057 lstrcmpiW(dataTypeName
,szIU1
) == 0 ||
1058 lstrcmpiW(dataTypeName
,szIU2
) == 0 ||
1059 lstrcmpiW(dataTypeName
,szIU4
) == 0 ||
1060 lstrcmpiW(dataTypeName
,szR4
) == 0 ||
1061 lstrcmpiW(dataTypeName
,szR8
) == 0 ||
1062 lstrcmpiW(dataTypeName
,szFloat
) == 0 ||
1063 lstrcmpiW(dataTypeName
,szBinHex
) == 0 ||
1064 lstrcmpiW(dataTypeName
,szBinBase64
) == 0)
1066 xmlNsPtr pNS
= NULL
;
1067 xmlAttrPtr pAttr
= NULL
;
1068 xmlChar
* str
= xmlChar_from_wchar(dataTypeName
);
1070 pAttr
= xmlHasNsProp(This
->node
, (xmlChar
*)"dt",
1071 (xmlChar
*)"urn:schemas-microsoft-com:datatypes");
1074 pAttr
= xmlSetNsProp(This
->node
, pAttr
->ns
, (xmlChar
*)"dt", str
);
1080 pNS
= xmlNewNs(This
->node
, (xmlChar
*)"urn:schemas-microsoft-com:datatypes", (xmlChar
*)"dt");
1083 pAttr
= xmlNewNsProp(This
->node
, pNS
, (xmlChar
*)"dt", str
);
1086 xmlAddChild(This
->node
, (xmlNodePtr
)pAttr
);
1091 ERR("Failed to create Attribute\n");
1094 ERR("Failed to Create Namepsace\n");
1096 HeapFree( GetProcessHeap(), 0, str
);
1102 static BSTR
EnsureCorrectEOL(BSTR sInput
)
1104 static const WCHAR SZ_RETURN
[] = {'\n',0};
1105 static const WCHAR SZ_LINEFEED
[] = {'\r',0};
1111 nLen
= lstrlenW(sInput
);
1112 /* Count line endings */
1113 for(i
=0; i
< nLen
; i
++)
1115 if(sInput
[i
] == SZ_RETURN
[0])
1119 TRACE("len=%d, num=%d\n", nLen
, nNum
);
1121 /* Add linefeed as needed */
1125 sNew
= SysAllocStringLen(NULL
, nLen
+ nNum
+1);
1126 for(i
=0; i
< nLen
; i
++)
1128 if(sInput
[i
] == SZ_RETURN
[0])
1130 sNew
[i
+nPlace
] = SZ_LINEFEED
[0];
1133 sNew
[i
+nPlace
] = sInput
[i
];
1136 SysFreeString(sInput
);
1143 TRACE("len %d\n", lstrlenW(sNew
));
1148 /* Removes encoding information and last character (nullbyte) */
1149 static BSTR
EnsureNoEncoding(BSTR sInput
)
1151 static const WCHAR wszEncoding
[] = {'e','n','c','o','d','i','n','g','='};
1156 while(*pBeg
!= '\n' && memcmp(pBeg
, wszEncoding
, sizeof(wszEncoding
)))
1161 SysReAllocStringLen(&sInput
, sInput
, SysStringLen(sInput
)-1);
1166 pEnd
= pBeg
+ sizeof(wszEncoding
)/sizeof(WCHAR
) + 2;
1167 while(*pEnd
!= '\"') pEnd
++;
1170 sNew
= SysAllocStringLen(NULL
,
1171 pBeg
-sInput
+ SysStringLen(sInput
)-(pEnd
-sInput
)-1);
1172 memcpy(sNew
, sInput
, (pBeg
-sInput
)*sizeof(WCHAR
));
1173 memcpy(&sNew
[pBeg
-sInput
], pEnd
, (SysStringLen(sInput
)-(pEnd
-sInput
)-1)*sizeof(WCHAR
));
1175 SysFreeString(sInput
);
1180 * We are trying to replicate the same behaviour as msxml by converting
1181 * line endings to \r\n and using idents as \t. The problem is that msxml
1182 * only formats nodes that have a line ending. Using libxml we cannot
1183 * reproduce behaviour exactly.
1186 static HRESULT WINAPI
xmlnode_get_xml(
1190 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
1191 xmlBufferPtr pXmlBuf
;
1194 TRACE("iface %p %d\n", iface
, This
->node
->type
);
1197 return E_INVALIDARG
;
1201 pXmlBuf
= xmlBufferCreate();
1204 nSize
= xmlNodeDump(pXmlBuf
, This
->node
->doc
, This
->node
, 0, 1);
1207 const xmlChar
*pContent
;
1210 /* Attribute Nodes return a space in front of their name */
1211 pContent
= xmlBufferContent(pXmlBuf
);
1212 if( ((char*)pContent
)[0] == ' ')
1213 bstrContent
= bstr_from_xmlChar(pContent
+1);
1215 bstrContent
= bstr_from_xmlChar(pContent
);
1217 switch(This
->node
->type
)
1219 case XML_ELEMENT_NODE
:
1220 *xmlString
= EnsureCorrectEOL(bstrContent
);
1222 case XML_DOCUMENT_NODE
:
1223 *xmlString
= EnsureCorrectEOL(bstrContent
);
1224 *xmlString
= EnsureNoEncoding(*xmlString
);
1227 *xmlString
= bstrContent
;
1231 xmlBufferFree(pXmlBuf
);
1234 /* Always returns a string. */
1235 if(*xmlString
== NULL
) *xmlString
= SysAllocStringLen( NULL
, 0 );
1240 static HRESULT WINAPI
xmlnode_transformNode(
1242 IXMLDOMNode
* styleSheet
,
1245 #ifdef SONAME_LIBXSLT
1246 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
1247 xmlnode
*pStyleSheet
= NULL
;
1248 xsltStylesheetPtr xsltSS
= NULL
;
1249 xmlDocPtr result
= NULL
;
1252 TRACE("%p %p %p\n", This
, styleSheet
, xmlString
);
1254 if (!libxslt_handle
)
1256 if(!styleSheet
|| !xmlString
)
1257 return E_INVALIDARG
;
1261 if(IXMLDOMNode_QueryInterface(styleSheet
, &IID_IXMLDOMNode
, (LPVOID
)&ssNew
) == S_OK
)
1263 pStyleSheet
= impl_from_IXMLDOMNode( ssNew
);
1265 xsltSS
= pxsltParseStylesheetDoc( pStyleSheet
->node
->doc
);
1268 result
= pxsltApplyStylesheet(xsltSS
, This
->node
->doc
, NULL
);
1271 const xmlChar
*pContent
;
1273 if(result
->type
== XML_HTML_DOCUMENT_NODE
)
1275 xmlOutputBufferPtr pOutput
= xmlAllocOutputBuffer(NULL
);
1278 htmlDocContentDumpOutput(pOutput
, result
->doc
, NULL
);
1279 pContent
= xmlBufferContent(pOutput
->buffer
);
1280 *xmlString
= bstr_from_xmlChar(pContent
);
1281 xmlOutputBufferClose(pOutput
);
1286 xmlBufferPtr pXmlBuf
;
1289 pXmlBuf
= xmlBufferCreate();
1292 nSize
= xmlNodeDump(pXmlBuf
, NULL
, (xmlNodePtr
)result
, 0, 0);
1295 pContent
= xmlBufferContent(pXmlBuf
);
1296 *xmlString
= bstr_from_xmlChar(pContent
);
1298 xmlBufferFree(pXmlBuf
);
1303 /* libxslt "helpfully" frees the XML document the stylesheet was
1304 generated from, too */
1306 pxsltFreeStylesheet(xsltSS
);
1309 IXMLDOMNode_Release(ssNew
);
1312 if(*xmlString
== NULL
)
1313 *xmlString
= SysAllocStringLen(NULL
, 0);
1317 FIXME("libxslt headers were not found at compile time\n");
1322 static HRESULT WINAPI
xmlnode_selectNodes(
1325 IXMLDOMNodeList
** resultList
)
1327 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
1329 TRACE("%p %s %p\n", This
, debugstr_w(queryString
), resultList
);
1331 return queryresult_create( This
->node
, queryString
, resultList
);
1334 static HRESULT WINAPI
xmlnode_selectSingleNode(
1337 IXMLDOMNode
** resultNode
)
1339 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
1340 IXMLDOMNodeList
*list
;
1343 TRACE("%p %s %p\n", This
, debugstr_w(queryString
), resultNode
);
1346 r
= IXMLDOMNode_selectNodes(iface
, queryString
, &list
);
1349 r
= IXMLDOMNodeList_nextNode(list
, resultNode
);
1350 IXMLDOMNodeList_Release(list
);
1355 static HRESULT WINAPI
xmlnode_get_parsed(
1357 VARIANT_BOOL
* isParsed
)
1363 static HRESULT WINAPI
xmlnode_get_namespaceURI(
1367 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
1368 HRESULT hr
= S_FALSE
;
1371 TRACE("%p %p\n", This
, namespaceURI
);
1374 return E_INVALIDARG
;
1376 *namespaceURI
= NULL
;
1378 pNSList
= xmlGetNsList(This
->node
->doc
, This
->node
);
1381 *namespaceURI
= bstr_from_xmlChar( pNSList
[0]->href
);
1390 static HRESULT WINAPI
xmlnode_get_prefix(
1394 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
1395 HRESULT hr
= S_FALSE
;
1398 TRACE("%p %p\n", This
, prefixString
);
1401 return E_INVALIDARG
;
1403 *prefixString
= NULL
;
1405 pNSList
= xmlGetNsList(This
->node
->doc
, This
->node
);
1408 *prefixString
= bstr_from_xmlChar( pNSList
[0]->prefix
);
1417 static HRESULT WINAPI
xmlnode_get_baseName(
1421 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
1423 HRESULT r
= S_FALSE
;
1425 TRACE("%p %p\n", This
, nameString
);
1428 return E_INVALIDARG
;
1430 switch ( This
->node
->type
)
1432 case XML_ELEMENT_NODE
:
1433 case XML_ATTRIBUTE_NODE
:
1434 str
= bstr_from_xmlChar( This
->node
->name
);
1440 ERR("Unhandled type %d\n", This
->node
->type
);
1444 TRACE("returning %08x str = %s\n", r
, debugstr_w( str
) );
1450 static HRESULT WINAPI
xmlnode_transformNodeToObject(
1452 IXMLDOMNode
* stylesheet
,
1453 VARIANT outputObject
)
1459 static const struct IXMLDOMNodeVtbl xmlnode_vtbl
=
1461 xmlnode_QueryInterface
,
1464 xmlnode_GetTypeInfoCount
,
1465 xmlnode_GetTypeInfo
,
1466 xmlnode_GetIDsOfNames
,
1468 xmlnode_get_nodeName
,
1469 xmlnode_get_nodeValue
,
1470 xmlnode_put_nodeValue
,
1471 xmlnode_get_nodeType
,
1472 xmlnode_get_parentNode
,
1473 xmlnode_get_childNodes
,
1474 xmlnode_get_firstChild
,
1475 xmlnode_get_lastChild
,
1476 xmlnode_get_previousSibling
,
1477 xmlnode_get_nextSibling
,
1478 xmlnode_get_attributes
,
1479 xmlnode_insertBefore
,
1480 xmlnode_replaceChild
,
1481 xmlnode_removeChild
,
1482 xmlnode_appendChild
,
1483 xmlnode_hasChildNodes
,
1484 xmlnode_get_ownerDocument
,
1486 xmlnode_get_nodeTypeString
,
1489 xmlnode_get_specified
,
1490 xmlnode_get_definition
,
1491 xmlnode_get_nodeTypedValue
,
1492 xmlnode_put_nodeTypedValue
,
1493 xmlnode_get_dataType
,
1494 xmlnode_put_dataType
,
1496 xmlnode_transformNode
,
1497 xmlnode_selectNodes
,
1498 xmlnode_selectSingleNode
,
1500 xmlnode_get_namespaceURI
,
1502 xmlnode_get_baseName
,
1503 xmlnode_transformNodeToObject
,
1506 static HRESULT WINAPI
Internal_QueryInterface(
1511 xmlnode
*This
= impl_from_InternalUnknown( iface
);
1513 TRACE("%p %s %p\n", iface
, debugstr_guid(riid
), ppvObject
);
1516 if ( IsEqualGUID( riid
, &IID_IUnknown
))
1518 else if ( IsEqualGUID( riid
, &IID_IDispatch
) ||
1519 IsEqualGUID( riid
, &IID_IXMLDOMNode
) )
1520 *ppvObject
= &This
->lpVtbl
;
1523 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
1525 return E_NOINTERFACE
;
1528 IUnknown_AddRef( (IUnknown
*)*ppvObject
);
1533 static ULONG WINAPI
Internal_AddRef(
1536 xmlnode
*This
= impl_from_InternalUnknown( iface
);
1537 return InterlockedIncrement( &This
->ref
);
1540 static ULONG WINAPI
Internal_Release(
1543 xmlnode
*This
= impl_from_InternalUnknown( iface
);
1546 ref
= InterlockedDecrement( &This
->ref
);
1550 xmldoc_release( This
->node
->doc
);
1551 HeapFree( GetProcessHeap(), 0, This
);
1557 static const struct IUnknownVtbl internal_unk_vtbl
=
1559 Internal_QueryInterface
,
1564 IUnknown
*create_basic_node( xmlNodePtr node
, IUnknown
*pUnkOuter
)
1568 This
= HeapAlloc( GetProcessHeap(), 0, sizeof *This
);
1573 xmldoc_add_ref( node
->doc
);
1575 This
->lpVtbl
= &xmlnode_vtbl
;
1576 This
->lpInternalUnkVtbl
= &internal_unk_vtbl
;
1579 This
->pUnkOuter
= pUnkOuter
; /* Don't take a ref on outer Unknown */
1581 This
->pUnkOuter
= (IUnknown
*)&This
->lpInternalUnkVtbl
;
1586 return (IUnknown
*)&This
->lpInternalUnkVtbl
;
1589 IXMLDOMNode
*create_node( xmlNodePtr node
)
1598 TRACE("type %d\n", node
->type
);
1601 case XML_ELEMENT_NODE
:
1602 pUnk
= create_element( node
, NULL
);
1604 case XML_ATTRIBUTE_NODE
:
1605 pUnk
= create_attribute( node
);
1608 pUnk
= create_text( node
);
1610 case XML_CDATA_SECTION_NODE
:
1611 pUnk
= create_cdata( node
);
1613 case XML_COMMENT_NODE
:
1614 pUnk
= create_comment( node
);
1616 case XML_DOCUMENT_NODE
:
1617 pUnk
= create_domdoc( node
);
1620 FIXME("only creating basic node for type %d\n", node
->type
);
1621 pUnk
= create_basic_node( node
, NULL
);
1624 hr
= IUnknown_QueryInterface(pUnk
, &IID_IXMLDOMNode
, (LPVOID
*)&ret
);
1625 IUnknown_Release(pUnk
);
1626 if(FAILED(hr
)) return NULL
;