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 static HRESULT WINAPI
xmlnode_get_nodeValue(
254 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
257 TRACE("%p %p\n", This
, value
);
262 V_BSTR(value
) = NULL
;
263 V_VT(value
) = VT_NULL
;
265 switch ( This
->node
->type
)
267 case XML_CDATA_SECTION_NODE
:
268 case XML_COMMENT_NODE
:
270 case XML_ATTRIBUTE_NODE
:
272 xmlChar
*content
= xmlNodeGetContent(This
->node
);
273 V_VT(value
) = VT_BSTR
;
274 V_BSTR(value
) = bstr_from_xmlChar( content
);
280 V_VT(value
) = VT_BSTR
;
281 V_BSTR(value
) = bstr_from_xmlChar( This
->node
->content
);
284 case XML_ELEMENT_NODE
:
285 case XML_DOCUMENT_NODE
:
286 /* these seem to return NULL */
290 FIXME("node %p type %d\n", This
, This
->node
->type
);
293 TRACE("%p returned %s\n", This
, debugstr_w( V_BSTR(value
) ) );
298 static HRESULT WINAPI
xmlnode_put_nodeValue(
302 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
305 VARIANT string_value
;
307 TRACE("%p type(%d)\n", This
, This
->node
->type
);
309 VariantInit(&string_value
);
310 hr
= VariantChangeType(&string_value
, &value
, 0, VT_BSTR
);
313 VariantClear(&string_value
);
314 WARN("Couldn't convert to VT_BSTR\n");
319 /* Document, Document Fragment, Document Type, Element,
320 Entity, Entity Reference, Notation aren't supported. */
321 switch ( This
->node
->type
)
323 case XML_ATTRIBUTE_NODE
:
324 case XML_CDATA_SECTION_NODE
:
325 case XML_COMMENT_NODE
:
329 str
= xmlChar_from_wchar(V_BSTR(&string_value
));
330 xmlNodeSetContent(This
->node
, str
);
331 HeapFree(GetProcessHeap(),0,str
);
336 /* Do nothing for unsupported types. */
340 VariantClear(&string_value
);
345 static HRESULT WINAPI
xmlnode_get_nodeType(
349 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
351 TRACE("%p %p\n", This
, type
);
353 assert( (int)NODE_ELEMENT
== (int)XML_ELEMENT_NODE
);
354 assert( (int)NODE_NOTATION
== (int)XML_NOTATION_NODE
);
356 *type
= This
->node
->type
;
361 static HRESULT
get_node(
367 TRACE("%p->%s %p\n", This
, name
, node
);
372 /* if we don't have a doc, use our parent. */
373 if(node
&& !node
->doc
&& node
->parent
)
374 node
->doc
= node
->parent
->doc
;
376 *out
= create_node( node
);
382 static HRESULT WINAPI
xmlnode_get_parentNode(
384 IXMLDOMNode
** parent
)
386 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
387 return get_node( This
, "parent", This
->node
->parent
, parent
);
390 static HRESULT WINAPI
xmlnode_get_childNodes(
392 IXMLDOMNodeList
** childList
)
394 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
396 TRACE("%p %p\n", This
, childList
);
401 *childList
= create_children_nodelist(This
->node
);
402 if (*childList
== NULL
)
403 return E_OUTOFMEMORY
;
408 static HRESULT WINAPI
xmlnode_get_firstChild(
410 IXMLDOMNode
** firstChild
)
412 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
413 return get_node( This
, "firstChild", This
->node
->children
, firstChild
);
416 static HRESULT WINAPI
xmlnode_get_lastChild(
418 IXMLDOMNode
** lastChild
)
420 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
422 TRACE("%p\n", This
);
427 switch( This
->node
->type
)
429 /* CDATASection, Comment, PI and Text Nodes do not support lastChild */
431 case XML_CDATA_SECTION_NODE
:
433 case XML_COMMENT_NODE
:
437 return get_node( This
, "lastChild", This
->node
->last
, lastChild
);
441 static HRESULT WINAPI
xmlnode_get_previousSibling(
443 IXMLDOMNode
** previousSibling
)
445 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
447 TRACE("%p\n", This
);
449 if (!previousSibling
)
452 switch( This
->node
->type
)
454 /* Attribute, Document and Document Fragment Nodes do not support previousSibling */
455 case XML_DOCUMENT_NODE
:
456 case XML_DOCUMENT_FRAG_NODE
:
457 case XML_ATTRIBUTE_NODE
:
458 *previousSibling
= NULL
;
461 return get_node( This
, "previous", This
->node
->prev
, previousSibling
);
465 static HRESULT WINAPI
xmlnode_get_nextSibling(
467 IXMLDOMNode
** nextSibling
)
469 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
471 TRACE("%p\n", This
);
476 switch( This
->node
->type
)
478 /* Attribute, Document and Document Fragment Nodes do not support nextSibling */
479 case XML_DOCUMENT_NODE
:
480 case XML_DOCUMENT_FRAG_NODE
:
481 case XML_ATTRIBUTE_NODE
:
485 return get_node( This
, "next", This
->node
->next
, nextSibling
);
489 static HRESULT WINAPI
xmlnode_get_attributes(
491 IXMLDOMNamedNodeMap
** attributeMap
)
493 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
499 switch( This
->node
->type
)
501 /* Attribute, CDataSection, Comment, Documents, Documents Fragments,
502 Entity and Text Nodes does not support get_attributes */
503 case XML_ATTRIBUTE_NODE
:
504 case XML_CDATA_SECTION_NODE
:
505 case XML_COMMENT_NODE
:
506 case XML_DOCUMENT_NODE
:
507 case XML_DOCUMENT_FRAG_NODE
:
508 case XML_ENTITY_NODE
:
509 case XML_ENTITY_REF_NODE
:
511 *attributeMap
= NULL
;
514 *attributeMap
= create_nodemap( iface
);
519 static HRESULT WINAPI
xmlnode_insertBefore(
521 IXMLDOMNode
* newChild
,
523 IXMLDOMNode
** outNewChild
)
525 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
526 xmlNodePtr before_node
, new_child_node
;
527 IXMLDOMNode
*before
= NULL
, *new;
530 TRACE("(%p)->(%p,var,%p)\n",This
,newChild
,outNewChild
);
535 switch(V_VT(&refChild
))
542 hr
= IUnknown_QueryInterface(V_UNKNOWN(&refChild
), &IID_IXMLDOMNode
, (LPVOID
)&before
);
543 if(FAILED(hr
)) return hr
;
547 hr
= IDispatch_QueryInterface(V_DISPATCH(&refChild
), &IID_IXMLDOMNode
, (LPVOID
)&before
);
548 if(FAILED(hr
)) return hr
;
552 FIXME("refChild var type %x\n", V_VT(&refChild
));
556 IXMLDOMNode_QueryInterface(newChild
, &IID_IXMLDOMNode
, (LPVOID
)&new);
557 new_child_node
= impl_from_IXMLDOMNode(new)->node
;
558 TRACE("new_child_node %p This->node %p\n", new_child_node
, This
->node
);
560 if(!new_child_node
->parent
)
561 if(xmldoc_remove_orphan(new_child_node
->doc
, new_child_node
) != S_OK
)
562 WARN("%p is not an orphan of %p\n", new_child_node
, new_child_node
->doc
);
566 before_node
= impl_from_IXMLDOMNode(before
)->node
;
567 xmlAddPrevSibling(before_node
, new_child_node
);
568 IXMLDOMNode_Release(before
);
572 xmlAddChild(This
->node
, new_child_node
);
575 IXMLDOMNode_Release(new);
576 IXMLDOMNode_AddRef(newChild
);
578 *outNewChild
= newChild
;
584 static HRESULT WINAPI
xmlnode_replaceChild(
586 IXMLDOMNode
* newChild
,
587 IXMLDOMNode
* oldChild
,
588 IXMLDOMNode
** outOldChild
)
590 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
591 xmlNode
*old_child_ptr
, *new_child_ptr
;
592 xmlDocPtr leaving_doc
;
593 xmlNode
*my_ancestor
;
594 IXMLDOMNode
*realOldChild
;
597 TRACE("%p->(%p,%p,%p)\n",This
,newChild
,oldChild
,outOldChild
);
599 /* Do not believe any documentation telling that newChild == NULL
600 means removal. It does certainly *not* apply to msxml3! */
601 if(!newChild
|| !oldChild
)
607 hr
= IXMLDOMNode_QueryInterface(oldChild
,&IID_IXMLDOMNode
,(LPVOID
*)&realOldChild
);
611 old_child_ptr
= impl_from_IXMLDOMNode(realOldChild
)->node
;
612 IXMLDOMNode_Release(realOldChild
);
613 if(old_child_ptr
->parent
!= This
->node
)
615 WARN("childNode %p is not a child of %p\n", oldChild
, iface
);
619 new_child_ptr
= impl_from_IXMLDOMNode(newChild
)->node
;
620 my_ancestor
= This
->node
;
623 if(my_ancestor
== new_child_ptr
)
625 WARN("tried to create loop\n");
628 my_ancestor
= my_ancestor
->parent
;
631 if(!new_child_ptr
->parent
)
632 if(xmldoc_remove_orphan(new_child_ptr
->doc
, new_child_ptr
) != S_OK
)
633 WARN("%p is not an orphan of %p\n", new_child_ptr
, new_child_ptr
->doc
);
635 leaving_doc
= new_child_ptr
->doc
;
636 xmldoc_add_ref(old_child_ptr
->doc
);
637 xmlReplaceNode(old_child_ptr
, new_child_ptr
);
638 xmldoc_release(leaving_doc
);
640 xmldoc_add_orphan(old_child_ptr
->doc
, old_child_ptr
);
644 IXMLDOMNode_AddRef(oldChild
);
645 *outOldChild
= oldChild
;
651 static HRESULT WINAPI
xmlnode_removeChild(
653 IXMLDOMNode
* childNode
,
654 IXMLDOMNode
** oldChild
)
656 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
657 xmlNode
*child_node_ptr
;
661 TRACE("%p->(%p, %p)\n", This
, childNode
, oldChild
);
663 if(!childNode
) return E_INVALIDARG
;
668 hr
= IXMLDOMNode_QueryInterface(childNode
, &IID_IXMLDOMNode
, (LPVOID
)&child
);
672 child_node_ptr
= impl_from_IXMLDOMNode(child
)->node
;
673 if(child_node_ptr
->parent
!= This
->node
)
675 WARN("childNode %p is not a child of %p\n", childNode
, iface
);
676 IXMLDOMNode_Release(child
);
680 xmlUnlinkNode(child_node_ptr
);
682 IXMLDOMNode_Release(child
);
686 IXMLDOMNode_AddRef(childNode
);
687 *oldChild
= childNode
;
693 static HRESULT WINAPI
xmlnode_appendChild(
695 IXMLDOMNode
* newChild
,
696 IXMLDOMNode
** outNewChild
)
698 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
703 TRACE("(%p)->(%p,%p)\n", This
, newChild
, outNewChild
);
705 hr
= IXMLDOMNode_get_nodeType(newChild
, &type
);
706 if(FAILED(hr
) || type
== NODE_ATTRIBUTE
) {
707 if(outNewChild
) *outNewChild
= NULL
;
712 return IXMLDOMNode_insertBefore(iface
, newChild
, var
, outNewChild
);
715 static HRESULT WINAPI
xmlnode_hasChildNodes(
717 VARIANT_BOOL
* hasChild
)
719 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
725 if (!This
->node
->children
)
727 *hasChild
= VARIANT_FALSE
;
731 *hasChild
= VARIANT_TRUE
;
735 static HRESULT WINAPI
xmlnode_get_ownerDocument(
737 IXMLDOMDocument
** DOMDocument
)
739 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
741 TRACE("%p (%p)\n", This
, DOMDocument
);
743 return DOMDocument_create_from_xmldoc(This
->node
->doc
, (IXMLDOMDocument2
**)DOMDocument
);
746 static HRESULT WINAPI
xmlnode_cloneNode(
749 IXMLDOMNode
** cloneRoot
)
751 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
752 xmlNodePtr pClone
= NULL
;
753 IXMLDOMNode
*pNode
= NULL
;
755 TRACE("%p (%d)\n", This
, deep
);
760 pClone
= xmlCopyNode(This
->node
, deep
? 1 : 2);
763 pClone
->doc
= This
->node
->doc
;
764 xmldoc_add_orphan(pClone
->doc
, pClone
);
766 pNode
= create_node(pClone
);
769 ERR("Copy failed\n");
777 ERR("Copy failed\n");
784 static HRESULT WINAPI
xmlnode_get_nodeTypeString(
788 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
791 TRACE("%p\n", This
);
799 switch( This
->node
->type
)
801 case XML_ATTRIBUTE_NODE
:
802 str
= (const xmlChar
*) "attribute";
804 case XML_CDATA_SECTION_NODE
:
805 str
= (const xmlChar
*) "cdatasection";
807 case XML_COMMENT_NODE
:
808 str
= (const xmlChar
*) "comment";
810 case XML_DOCUMENT_NODE
:
811 str
= (const xmlChar
*) "document";
813 case XML_DOCUMENT_FRAG_NODE
:
814 str
= (const xmlChar
*) "documentfragment";
816 case XML_ELEMENT_NODE
:
817 str
= (const xmlChar
*) "element";
819 case XML_ENTITY_NODE
:
820 str
= (const xmlChar
*) "entity";
822 case XML_ENTITY_REF_NODE
:
823 str
= (const xmlChar
*) "entityreference";
825 case XML_NOTATION_NODE
:
826 str
= (const xmlChar
*) "notation";
829 str
= (const xmlChar
*) "processinginstruction";
832 str
= (const xmlChar
*) "text";
835 FIXME("Unknown node type (%d)\n", This
->node
->type
);
836 str
= This
->node
->name
;
840 *xmlnodeType
= bstr_from_xmlChar( str
);
847 static HRESULT WINAPI
xmlnode_get_text(
851 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
855 TRACE("%p type %d\n", This
, This
->node
->type
);
860 pContent
= xmlNodeGetContent((xmlNodePtr
)This
->node
);
863 str
= bstr_from_xmlChar(pContent
);
867 /* Always return a string. */
868 if (!str
) str
= SysAllocStringLen( NULL
, 0 );
870 TRACE("%p %s\n", This
, debugstr_w(str
) );
876 static HRESULT WINAPI
xmlnode_put_text(
880 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
885 switch(This
->node
->type
)
887 case XML_DOCUMENT_NODE
:
893 str
= xmlChar_from_wchar(text
);
895 /* Escape the string. */
896 str2
= xmlEncodeEntitiesReentrant(This
->node
->doc
, str
);
897 HeapFree(GetProcessHeap(), 0, str
);
899 xmlNodeSetContent(This
->node
, str2
);
905 static HRESULT WINAPI
xmlnode_get_specified(
907 VARIANT_BOOL
* isSpecified
)
913 static HRESULT WINAPI
xmlnode_get_definition(
915 IXMLDOMNode
** definitionNode
)
921 static HRESULT WINAPI
xmlnode_get_nodeTypedValue(
925 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
928 FIXME("ignoring data type %p %p\n", This
, typedValue
);
933 V_VT(typedValue
) = VT_NULL
;
935 switch ( This
->node
->type
)
937 case XML_ELEMENT_NODE
:
939 xmlChar
*content
= xmlNodeGetContent(This
->node
);
940 V_VT(typedValue
) = VT_BSTR
;
941 V_BSTR(typedValue
) = bstr_from_xmlChar( content
);
947 r
= xmlnode_get_nodeValue(iface
, typedValue
);
953 static HRESULT WINAPI
xmlnode_put_nodeTypedValue(
961 static HRESULT WINAPI
xmlnode_get_dataType(
963 VARIANT
* dataTypeName
)
965 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
968 TRACE("iface %p\n", iface
);
973 /* Attribute, CDATA Section, Comment, Document, Document Fragment,
974 Entity, Notation, PI, and Text Node are non-typed. */
975 V_BSTR(dataTypeName
) = NULL
;
976 V_VT(dataTypeName
) = VT_NULL
;
978 switch ( This
->node
->type
)
980 case XML_ELEMENT_NODE
:
981 pVal
= xmlGetNsProp(This
->node
, (xmlChar
*)"dt",
982 (xmlChar
*)"urn:schemas-microsoft-com:datatypes");
985 V_VT(dataTypeName
) = VT_BSTR
;
986 V_BSTR(dataTypeName
) = bstr_from_xmlChar( pVal
);
990 case XML_ENTITY_REF_NODE
:
991 FIXME("XML_ENTITY_REF_NODE should return a valid value.\n");
994 TRACE("Type %d returning NULL\n", This
->node
->type
);
997 /* non-typed nodes return S_FALSE */
998 if(V_VT(dataTypeName
) == VT_NULL
)
1006 static HRESULT WINAPI
xmlnode_put_dataType(
1010 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
1011 HRESULT hr
= E_FAIL
;
1013 TRACE("iface %p\n", iface
);
1015 if(dataTypeName
== NULL
)
1016 return E_INVALIDARG
;
1018 /* An example of this is. The Text in the node needs to be a 0 or 1 for a boolean type.
1019 This applies to changing types (string->bool) or setting a new one
1021 FIXME("Need to Validate the data before allowing a type to be set.\n");
1023 /* Check all supported types. */
1024 if(lstrcmpiW(dataTypeName
,szString
) == 0 ||
1025 lstrcmpiW(dataTypeName
,szNumber
) == 0 ||
1026 lstrcmpiW(dataTypeName
,szUUID
) == 0 ||
1027 lstrcmpiW(dataTypeName
,szInt
) == 0 ||
1028 lstrcmpiW(dataTypeName
,szI4
) == 0 ||
1029 lstrcmpiW(dataTypeName
,szFixed
) == 0 ||
1030 lstrcmpiW(dataTypeName
,szBoolean
) == 0 ||
1031 lstrcmpiW(dataTypeName
,szDateTime
) == 0 ||
1032 lstrcmpiW(dataTypeName
,szDateTimeTZ
) == 0 ||
1033 lstrcmpiW(dataTypeName
,szDate
) == 0 ||
1034 lstrcmpiW(dataTypeName
,szTime
) == 0 ||
1035 lstrcmpiW(dataTypeName
,szTimeTZ
) == 0 ||
1036 lstrcmpiW(dataTypeName
,szI1
) == 0 ||
1037 lstrcmpiW(dataTypeName
,szI2
) == 0 ||
1038 lstrcmpiW(dataTypeName
,szIU1
) == 0 ||
1039 lstrcmpiW(dataTypeName
,szIU2
) == 0 ||
1040 lstrcmpiW(dataTypeName
,szIU4
) == 0 ||
1041 lstrcmpiW(dataTypeName
,szR4
) == 0 ||
1042 lstrcmpiW(dataTypeName
,szR8
) == 0 ||
1043 lstrcmpiW(dataTypeName
,szFloat
) == 0 ||
1044 lstrcmpiW(dataTypeName
,szBinHex
) == 0 ||
1045 lstrcmpiW(dataTypeName
,szBinBase64
) == 0)
1047 xmlNsPtr pNS
= NULL
;
1048 xmlAttrPtr pAttr
= NULL
;
1049 xmlChar
* str
= xmlChar_from_wchar(dataTypeName
);
1051 pAttr
= xmlHasNsProp(This
->node
, (xmlChar
*)"dt",
1052 (xmlChar
*)"urn:schemas-microsoft-com:datatypes");
1055 pAttr
= xmlSetNsProp(This
->node
, pAttr
->ns
, (xmlChar
*)"dt", str
);
1061 pNS
= xmlNewNs(This
->node
, (xmlChar
*)"urn:schemas-microsoft-com:datatypes", (xmlChar
*)"dt");
1064 pAttr
= xmlNewNsProp(This
->node
, pNS
, (xmlChar
*)"dt", str
);
1067 xmlAddChild(This
->node
, (xmlNodePtr
)pAttr
);
1072 ERR("Failed to create Attribute\n");
1075 ERR("Failed to Create Namepsace\n");
1077 HeapFree( GetProcessHeap(), 0, str
);
1083 static BSTR
EnsureCorrectEOL(BSTR sInput
)
1085 static const WCHAR SZ_RETURN
[] = {'\n',0};
1086 static const WCHAR SZ_LINEFEED
[] = {'\r',0};
1092 nLen
= lstrlenW(sInput
);
1093 /* Count line endings */
1094 for(i
=0; i
< nLen
; i
++)
1096 if(sInput
[i
] == SZ_RETURN
[0])
1100 TRACE("len=%d, num=%d\n", nLen
, nNum
);
1102 /* Add linefeed as needed */
1106 sNew
= SysAllocStringLen(NULL
, nLen
+ nNum
+1);
1107 for(i
=0; i
< nLen
; i
++)
1109 if(sInput
[i
] == SZ_RETURN
[0])
1111 sNew
[i
+nPlace
] = SZ_LINEFEED
[0];
1114 sNew
[i
+nPlace
] = sInput
[i
];
1117 SysFreeString(sInput
);
1124 TRACE("len %d\n", lstrlenW(sNew
));
1129 /* Removes encoding information and last character (nullbyte) */
1130 static BSTR
EnsureNoEncoding(BSTR sInput
)
1132 static const WCHAR wszEncoding
[] = {'e','n','c','o','d','i','n','g','='};
1137 while(*pBeg
!= '\n' && memcmp(pBeg
, wszEncoding
, sizeof(wszEncoding
)))
1142 SysReAllocStringLen(&sInput
, sInput
, SysStringLen(sInput
)-1);
1147 pEnd
= pBeg
+ sizeof(wszEncoding
)/sizeof(WCHAR
) + 2;
1148 while(*pEnd
!= '\"') pEnd
++;
1151 sNew
= SysAllocStringLen(NULL
,
1152 pBeg
-sInput
+ SysStringLen(sInput
)-(pEnd
-sInput
)-1);
1153 memcpy(sNew
, sInput
, (pBeg
-sInput
)*sizeof(WCHAR
));
1154 memcpy(&sNew
[pBeg
-sInput
], pEnd
, (SysStringLen(sInput
)-(pEnd
-sInput
)-1)*sizeof(WCHAR
));
1156 SysFreeString(sInput
);
1161 * We are trying to replicate the same behaviour as msxml by converting
1162 * line endings to \r\n and using idents as \t. The problem is that msxml
1163 * only formats nodes that have a line ending. Using libxml we cannot
1164 * reproduce behaviour exactly.
1167 static HRESULT WINAPI
xmlnode_get_xml(
1171 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
1172 xmlBufferPtr pXmlBuf
;
1175 TRACE("iface %p %d\n", iface
, This
->node
->type
);
1178 return E_INVALIDARG
;
1182 pXmlBuf
= xmlBufferCreate();
1185 nSize
= xmlNodeDump(pXmlBuf
, This
->node
->doc
, This
->node
, 0, 1);
1188 const xmlChar
*pContent
;
1191 /* Attribute Nodes return a space in front of their name */
1192 pContent
= xmlBufferContent(pXmlBuf
);
1193 if( ((char*)pContent
)[0] == ' ')
1194 bstrContent
= bstr_from_xmlChar(pContent
+1);
1196 bstrContent
= bstr_from_xmlChar(pContent
);
1198 switch(This
->node
->type
)
1200 case XML_ELEMENT_NODE
:
1201 *xmlString
= EnsureCorrectEOL(bstrContent
);
1203 case XML_DOCUMENT_NODE
:
1204 *xmlString
= EnsureCorrectEOL(bstrContent
);
1205 *xmlString
= EnsureNoEncoding(*xmlString
);
1208 *xmlString
= bstrContent
;
1212 xmlBufferFree(pXmlBuf
);
1215 /* Always returns a string. */
1216 if(*xmlString
== NULL
) *xmlString
= SysAllocStringLen( NULL
, 0 );
1221 static HRESULT WINAPI
xmlnode_transformNode(
1223 IXMLDOMNode
* styleSheet
,
1226 #ifdef SONAME_LIBXSLT
1227 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
1228 xmlnode
*pStyleSheet
= NULL
;
1229 xsltStylesheetPtr xsltSS
= NULL
;
1230 xmlDocPtr result
= NULL
;
1233 TRACE("%p %p %p\n", This
, styleSheet
, xmlString
);
1235 if (!libxslt_handle
)
1237 if(!styleSheet
|| !xmlString
)
1238 return E_INVALIDARG
;
1242 if(IXMLDOMNode_QueryInterface(styleSheet
, &IID_IXMLDOMNode
, (LPVOID
)&ssNew
) == S_OK
)
1244 pStyleSheet
= impl_from_IXMLDOMNode( ssNew
);
1246 xsltSS
= pxsltParseStylesheetDoc( pStyleSheet
->node
->doc
);
1249 result
= pxsltApplyStylesheet(xsltSS
, This
->node
->doc
, NULL
);
1252 const xmlChar
*pContent
;
1254 if(result
->type
== XML_HTML_DOCUMENT_NODE
)
1256 xmlOutputBufferPtr pOutput
= xmlAllocOutputBuffer(NULL
);
1259 htmlDocContentDumpOutput(pOutput
, result
->doc
, NULL
);
1260 pContent
= xmlBufferContent(pOutput
->buffer
);
1261 *xmlString
= bstr_from_xmlChar(pContent
);
1262 xmlOutputBufferClose(pOutput
);
1267 xmlBufferPtr pXmlBuf
;
1270 pXmlBuf
= xmlBufferCreate();
1273 nSize
= xmlNodeDump(pXmlBuf
, NULL
, (xmlNodePtr
)result
, 0, 0);
1276 pContent
= xmlBufferContent(pXmlBuf
);
1277 *xmlString
= bstr_from_xmlChar(pContent
);
1279 xmlBufferFree(pXmlBuf
);
1284 /* libxslt "helpfully" frees the XML document the stylesheet was
1285 generated from, too */
1287 pxsltFreeStylesheet(xsltSS
);
1290 IXMLDOMNode_Release(ssNew
);
1293 if(*xmlString
== NULL
)
1294 *xmlString
= SysAllocStringLen(NULL
, 0);
1298 FIXME("libxslt headers were not found at compile time\n");
1303 static HRESULT WINAPI
xmlnode_selectNodes(
1306 IXMLDOMNodeList
** resultList
)
1308 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
1310 TRACE("%p %s %p\n", This
, debugstr_w(queryString
), resultList
);
1312 return queryresult_create( This
->node
, queryString
, resultList
);
1315 static HRESULT WINAPI
xmlnode_selectSingleNode(
1318 IXMLDOMNode
** resultNode
)
1320 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
1321 IXMLDOMNodeList
*list
;
1324 TRACE("%p %s %p\n", This
, debugstr_w(queryString
), resultNode
);
1327 r
= IXMLDOMNode_selectNodes(iface
, queryString
, &list
);
1330 r
= IXMLDOMNodeList_nextNode(list
, resultNode
);
1331 IXMLDOMNodeList_Release(list
);
1336 static HRESULT WINAPI
xmlnode_get_parsed(
1338 VARIANT_BOOL
* isParsed
)
1344 static HRESULT WINAPI
xmlnode_get_namespaceURI(
1348 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
1349 HRESULT hr
= S_FALSE
;
1352 TRACE("%p %p\n", This
, namespaceURI
);
1355 return E_INVALIDARG
;
1357 *namespaceURI
= NULL
;
1359 pNSList
= xmlGetNsList(This
->node
->doc
, This
->node
);
1362 *namespaceURI
= bstr_from_xmlChar( pNSList
[0]->href
);
1371 static HRESULT WINAPI
xmlnode_get_prefix(
1375 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
1376 HRESULT hr
= S_FALSE
;
1379 TRACE("%p %p\n", This
, prefixString
);
1382 return E_INVALIDARG
;
1384 *prefixString
= NULL
;
1386 pNSList
= xmlGetNsList(This
->node
->doc
, This
->node
);
1389 *prefixString
= bstr_from_xmlChar( pNSList
[0]->prefix
);
1398 static HRESULT WINAPI
xmlnode_get_baseName(
1402 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
1404 HRESULT r
= S_FALSE
;
1406 TRACE("%p %p\n", This
, nameString
);
1409 return E_INVALIDARG
;
1411 switch ( This
->node
->type
)
1413 case XML_ELEMENT_NODE
:
1414 case XML_ATTRIBUTE_NODE
:
1415 str
= bstr_from_xmlChar( This
->node
->name
);
1421 ERR("Unhandled type %d\n", This
->node
->type
);
1425 TRACE("returning %08x str = %s\n", r
, debugstr_w( str
) );
1431 static HRESULT WINAPI
xmlnode_transformNodeToObject(
1433 IXMLDOMNode
* stylesheet
,
1434 VARIANT outputObject
)
1440 static const struct IXMLDOMNodeVtbl xmlnode_vtbl
=
1442 xmlnode_QueryInterface
,
1445 xmlnode_GetTypeInfoCount
,
1446 xmlnode_GetTypeInfo
,
1447 xmlnode_GetIDsOfNames
,
1449 xmlnode_get_nodeName
,
1450 xmlnode_get_nodeValue
,
1451 xmlnode_put_nodeValue
,
1452 xmlnode_get_nodeType
,
1453 xmlnode_get_parentNode
,
1454 xmlnode_get_childNodes
,
1455 xmlnode_get_firstChild
,
1456 xmlnode_get_lastChild
,
1457 xmlnode_get_previousSibling
,
1458 xmlnode_get_nextSibling
,
1459 xmlnode_get_attributes
,
1460 xmlnode_insertBefore
,
1461 xmlnode_replaceChild
,
1462 xmlnode_removeChild
,
1463 xmlnode_appendChild
,
1464 xmlnode_hasChildNodes
,
1465 xmlnode_get_ownerDocument
,
1467 xmlnode_get_nodeTypeString
,
1470 xmlnode_get_specified
,
1471 xmlnode_get_definition
,
1472 xmlnode_get_nodeTypedValue
,
1473 xmlnode_put_nodeTypedValue
,
1474 xmlnode_get_dataType
,
1475 xmlnode_put_dataType
,
1477 xmlnode_transformNode
,
1478 xmlnode_selectNodes
,
1479 xmlnode_selectSingleNode
,
1481 xmlnode_get_namespaceURI
,
1483 xmlnode_get_baseName
,
1484 xmlnode_transformNodeToObject
,
1487 static HRESULT WINAPI
Internal_QueryInterface(
1492 xmlnode
*This
= impl_from_InternalUnknown( iface
);
1494 TRACE("%p %s %p\n", iface
, debugstr_guid(riid
), ppvObject
);
1497 if ( IsEqualGUID( riid
, &IID_IUnknown
))
1499 else if ( IsEqualGUID( riid
, &IID_IDispatch
) ||
1500 IsEqualGUID( riid
, &IID_IXMLDOMNode
) )
1501 *ppvObject
= &This
->lpVtbl
;
1504 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
1506 return E_NOINTERFACE
;
1509 IUnknown_AddRef( (IUnknown
*)*ppvObject
);
1514 static ULONG WINAPI
Internal_AddRef(
1517 xmlnode
*This
= impl_from_InternalUnknown( iface
);
1518 return InterlockedIncrement( &This
->ref
);
1521 static ULONG WINAPI
Internal_Release(
1524 xmlnode
*This
= impl_from_InternalUnknown( iface
);
1527 ref
= InterlockedDecrement( &This
->ref
);
1531 xmldoc_release( This
->node
->doc
);
1532 HeapFree( GetProcessHeap(), 0, This
);
1538 static const struct IUnknownVtbl internal_unk_vtbl
=
1540 Internal_QueryInterface
,
1545 xmlnode
*create_basic_node( xmlNodePtr node
, IUnknown
*pUnkOuter
, dispex_static_data_t
*dispex_data
)
1549 This
= HeapAlloc( GetProcessHeap(), 0, sizeof *This
);
1554 xmldoc_add_ref( node
->doc
);
1556 This
->lpVtbl
= &xmlnode_vtbl
;
1557 This
->lpInternalUnkVtbl
= &internal_unk_vtbl
;
1560 This
->pUnkOuter
= pUnkOuter
; /* Don't take a ref on outer Unknown */
1562 This
->pUnkOuter
= (IUnknown
*)&This
->lpInternalUnkVtbl
;
1565 init_dispex(&This
->dispex
, This
->pUnkOuter
, dispex_data
);
1573 IXMLDOMNode
*create_node( xmlNodePtr node
)
1582 TRACE("type %d\n", node
->type
);
1585 case XML_ELEMENT_NODE
:
1586 pUnk
= create_element( node
);
1588 case XML_ATTRIBUTE_NODE
:
1589 pUnk
= create_attribute( node
);
1592 pUnk
= create_text( node
);
1594 case XML_CDATA_SECTION_NODE
:
1595 pUnk
= create_cdata( node
);
1597 case XML_COMMENT_NODE
:
1598 pUnk
= create_comment( node
);
1600 case XML_DOCUMENT_NODE
:
1601 pUnk
= create_domdoc( node
);
1604 FIXME("only creating basic node for type %d\n", node
->type
);
1605 pUnk
= (IUnknown
*)&create_basic_node( node
, NULL
, NULL
)->lpInternalUnkVtbl
;
1608 hr
= IUnknown_QueryInterface(pUnk
, &IID_IXMLDOMNode
, (LPVOID
*)&ret
);
1609 IUnknown_Release(pUnk
);
1610 if(FAILED(hr
)) return NULL
;