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((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( NODE_ELEMENT == XML_ELEMENT_NODE );
373 assert( NODE_NOTATION == XML_NOTATION_NODE );
375 *type = This->node->type;
380 static HRESULT get_node(
386 TRACE("%p->%s %p\n", This, name, node );
390 *out = create_node( node );
396 static HRESULT WINAPI xmlnode_get_parentNode(
398 IXMLDOMNode** parent)
400 xmlnode *This = impl_from_IXMLDOMNode( iface );
401 return get_node( This, "parent", This->node->parent, parent );
404 static HRESULT WINAPI xmlnode_get_childNodes(
406 IXMLDOMNodeList** childList)
408 xmlnode *This = impl_from_IXMLDOMNode( iface );
410 TRACE("%p %p\n", This, childList );
415 *childList = create_children_nodelist(This->node);
416 if (*childList == NULL)
417 return E_OUTOFMEMORY;
422 static HRESULT WINAPI xmlnode_get_firstChild(
424 IXMLDOMNode** firstChild)
426 xmlnode *This = impl_from_IXMLDOMNode( iface );
427 return get_node( This, "firstChild", This->node->children, firstChild );
430 static HRESULT WINAPI xmlnode_get_lastChild(
432 IXMLDOMNode** lastChild)
434 xmlnode *This = impl_from_IXMLDOMNode( iface );
436 TRACE("%p\n", This );
441 switch( This->node->type )
443 /* CDATASection, Comment, PI and Text Nodes do not support lastChild */
445 case XML_CDATA_SECTION_NODE:
447 case XML_COMMENT_NODE:
451 return get_node( This, "lastChild", This->node->last, lastChild );
455 static HRESULT WINAPI xmlnode_get_previousSibling(
457 IXMLDOMNode** previousSibling)
459 xmlnode *This = impl_from_IXMLDOMNode( iface );
461 TRACE("%p\n", This );
463 if (!previousSibling)
466 switch( This->node->type )
468 /* Attribute, Document and Document Fragment Nodes do not support previousSibling */
469 case XML_DOCUMENT_NODE:
470 case XML_DOCUMENT_FRAG_NODE:
471 case XML_ATTRIBUTE_NODE:
472 *previousSibling = NULL;
475 return get_node( This, "previous", This->node->prev, previousSibling );
479 static HRESULT WINAPI xmlnode_get_nextSibling(
481 IXMLDOMNode** nextSibling)
483 xmlnode *This = impl_from_IXMLDOMNode( iface );
485 TRACE("%p\n", This );
490 switch( This->node->type )
492 /* Attribute, Document and Document Fragment Nodes do not support nextSibling */
493 case XML_DOCUMENT_NODE:
494 case XML_DOCUMENT_FRAG_NODE:
495 case XML_ATTRIBUTE_NODE:
499 return get_node( This, "next", This->node->next, nextSibling );
503 static HRESULT WINAPI xmlnode_get_attributes(
505 IXMLDOMNamedNodeMap** attributeMap)
507 xmlnode *This = impl_from_IXMLDOMNode( iface );
513 switch( This->node->type )
515 /* Attribute, CDataSection, Comment, Documents, Documents Fragments,
516 Entity and Text Nodes does not support get_attributes */
517 case XML_ATTRIBUTE_NODE:
518 case XML_CDATA_SECTION_NODE:
519 case XML_COMMENT_NODE:
520 case XML_DOCUMENT_NODE:
521 case XML_DOCUMENT_FRAG_NODE:
522 case XML_ENTITY_NODE:
523 case XML_ENTITY_REF_NODE:
525 *attributeMap = NULL;
528 *attributeMap = create_nodemap( iface );
533 static HRESULT WINAPI xmlnode_insertBefore(
535 IXMLDOMNode* newChild,
537 IXMLDOMNode** outNewChild)
539 xmlnode *This = impl_from_IXMLDOMNode( iface );
540 xmlNodePtr before_node, new_child_node;
541 IXMLDOMNode *before = NULL, *new;
544 TRACE("(%p)->(%p,var,%p)\n",This,newChild,outNewChild);
549 switch(V_VT(&refChild))
556 hr = IUnknown_QueryInterface(V_UNKNOWN(&refChild), &IID_IXMLDOMNode, (LPVOID)&before);
557 if(FAILED(hr)) return hr;
561 hr = IDispatch_QueryInterface(V_DISPATCH(&refChild), &IID_IXMLDOMNode, (LPVOID)&before);
562 if(FAILED(hr)) return hr;
566 FIXME("refChild var type %x\n", V_VT(&refChild));
570 IXMLDOMNode_QueryInterface(newChild, &IID_IXMLDOMNode, (LPVOID)&new);
571 new_child_node = impl_from_IXMLDOMNode(new)->node;
572 TRACE("new_child_node %p This->node %p\n", new_child_node, This->node);
574 if(!new_child_node->parent)
575 if(xmldoc_remove_orphan(new_child_node->doc, new_child_node) != S_OK)
576 WARN("%p is not an orphan of %p\n", new_child_node, new_child_node->doc);
580 before_node = impl_from_IXMLDOMNode(before)->node;
581 xmlAddPrevSibling(before_node, new_child_node);
582 IXMLDOMNode_Release(before);
586 xmlAddChild(This->node, new_child_node);
589 IXMLDOMNode_Release(new);
590 IXMLDOMNode_AddRef(newChild);
592 *outNewChild = newChild;
598 static HRESULT WINAPI xmlnode_replaceChild(
600 IXMLDOMNode* newChild,
601 IXMLDOMNode* oldChild,
602 IXMLDOMNode** outOldChild)
604 xmlnode *This = impl_from_IXMLDOMNode( iface );
605 xmlNode *old_child_ptr, *new_child_ptr;
606 xmlDocPtr leaving_doc;
607 xmlNode *my_ancestor;
608 IXMLDOMNode *realOldChild;
611 TRACE("%p->(%p,%p,%p)\n",This,newChild,oldChild,outOldChild);
613 /* Do not believe any documentation telling that newChild == NULL
614 means removal. It does certainly *not* apply to msxml3! */
615 if(!newChild || !oldChild)
621 hr = IXMLDOMNode_QueryInterface(oldChild,&IID_IXMLDOMNode,(LPVOID*)&realOldChild);
625 old_child_ptr = impl_from_IXMLDOMNode(realOldChild)->node;
626 IXMLDOMNode_Release(realOldChild);
627 if(old_child_ptr->parent != This->node)
629 WARN("childNode %p is not a child of %p\n", oldChild, iface);
633 new_child_ptr = impl_from_IXMLDOMNode(newChild)->node;
634 my_ancestor = This->node;
637 if(my_ancestor == new_child_ptr)
639 WARN("tried to create loop\n");
642 my_ancestor = my_ancestor->parent;
645 if(!new_child_ptr->parent)
646 if(xmldoc_remove_orphan(new_child_ptr->doc, new_child_ptr) != S_OK)
647 WARN("%p is not an orphan of %p\n", new_child_ptr, new_child_ptr->doc);
649 leaving_doc = new_child_ptr->doc;
650 xmldoc_add_ref(old_child_ptr->doc);
651 xmlReplaceNode(old_child_ptr, new_child_ptr);
652 xmldoc_release(leaving_doc);
654 xmldoc_add_orphan(old_child_ptr->doc, old_child_ptr);
658 IXMLDOMNode_AddRef(oldChild);
659 *outOldChild = oldChild;
665 static HRESULT WINAPI xmlnode_removeChild(
667 IXMLDOMNode* childNode,
668 IXMLDOMNode** oldChild)
670 xmlnode *This = impl_from_IXMLDOMNode( iface );
671 xmlNode *child_node_ptr;
675 TRACE("%p->(%p, %p)\n", This, childNode, oldChild);
677 if(!childNode) return E_INVALIDARG;
682 hr = IXMLDOMNode_QueryInterface(childNode, &IID_IXMLDOMNode, (LPVOID)&child);
686 child_node_ptr = impl_from_IXMLDOMNode(child)->node;
687 if(child_node_ptr->parent != This->node)
689 WARN("childNode %p is not a child of %p\n", childNode, iface);
690 IXMLDOMNode_Release(child);
694 xmlUnlinkNode(child_node_ptr);
696 IXMLDOMNode_Release(child);
700 IXMLDOMNode_AddRef(childNode);
701 *oldChild = childNode;
707 static HRESULT WINAPI xmlnode_appendChild(
709 IXMLDOMNode* newChild,
710 IXMLDOMNode** outNewChild)
712 xmlnode *This = impl_from_IXMLDOMNode( iface );
717 TRACE("(%p)->(%p,%p)\n", This, newChild, outNewChild);
719 hr = IXMLDOMNode_get_nodeType(newChild, &type);
720 if(FAILED(hr) || type == NODE_ATTRIBUTE) {
721 if(outNewChild) *outNewChild = NULL;
726 return IXMLDOMNode_insertBefore(iface, newChild, var, outNewChild);
729 static HRESULT WINAPI xmlnode_hasChildNodes(
731 VARIANT_BOOL* hasChild)
733 xmlnode *This = impl_from_IXMLDOMNode( iface );
739 if (!This->node->children)
741 *hasChild = VARIANT_FALSE;
745 *hasChild = VARIANT_TRUE;
749 static HRESULT WINAPI xmlnode_get_ownerDocument(
751 IXMLDOMDocument** DOMDocument)
753 xmlnode *This = impl_from_IXMLDOMNode( iface );
755 TRACE("%p (%p)\n", This, DOMDocument);
757 return DOMDocument_create_from_xmldoc(This->node->doc, (IXMLDOMDocument2**)DOMDocument);
760 static HRESULT WINAPI xmlnode_cloneNode(
763 IXMLDOMNode** cloneRoot)
765 xmlnode *This = impl_from_IXMLDOMNode( iface );
766 xmlNodePtr pClone = NULL;
767 IXMLDOMNode *pNode = NULL;
769 TRACE("%p (%d)\n", This, deep);
774 pClone = xmlCopyNode(This->node, deep ? 1 : 2);
777 pClone->doc = This->node->doc;
778 xmldoc_add_orphan(pClone->doc, pClone);
780 pNode = create_node(pClone);
783 ERR("Copy failed\n");
791 ERR("Copy failed\n");
798 static HRESULT WINAPI xmlnode_get_nodeTypeString(
802 xmlnode *This = impl_from_IXMLDOMNode( iface );
805 TRACE("%p\n", This );
813 switch( This->node->type )
815 case XML_ATTRIBUTE_NODE:
816 str = (const xmlChar*) "attribute";
818 case XML_CDATA_SECTION_NODE:
819 str = (const xmlChar*) "cdatasection";
821 case XML_COMMENT_NODE:
822 str = (const xmlChar*) "comment";
824 case XML_DOCUMENT_NODE:
825 str = (const xmlChar*) "document";
827 case XML_DOCUMENT_FRAG_NODE:
828 str = (const xmlChar*) "documentfragment";
830 case XML_ELEMENT_NODE:
831 str = (const xmlChar*) "element";
833 case XML_ENTITY_NODE:
834 str = (const xmlChar*) "entity";
836 case XML_ENTITY_REF_NODE:
837 str = (const xmlChar*) "entityreference";
839 case XML_NOTATION_NODE:
840 str = (const xmlChar*) "notation";
843 str = (const xmlChar*) "processinginstruction";
846 str = (const xmlChar*) "text";
849 FIXME("Unknown node type (%d)\n", This->node->type);
850 str = This->node->name;
854 *xmlnodeType = bstr_from_xmlChar( str );
861 static HRESULT WINAPI xmlnode_get_text(
865 xmlnode *This = impl_from_IXMLDOMNode( iface );
873 switch(This->node->type)
875 case XML_ELEMENT_NODE:
876 case XML_ATTRIBUTE_NODE:
878 xmlNodePtr child = This->node->children;
879 if ( child && child->type == XML_TEXT_NODE )
880 str = bstr_from_xmlChar( child->content );
885 case XML_CDATA_SECTION_NODE:
887 case XML_COMMENT_NODE:
888 str = bstr_from_xmlChar( This->node->content );
892 FIXME("Unhandled node type %d\n", This->node->type);
895 /* Always return a string. */
896 if (!str) str = SysAllocStringLen( NULL, 0 );
898 TRACE("%p %s\n", This, debugstr_w(str) );
904 static HRESULT WINAPI xmlnode_put_text(
908 xmlnode *This = impl_from_IXMLDOMNode( iface );
913 switch(This->node->type)
915 case XML_DOCUMENT_NODE:
921 str = xmlChar_from_wchar((WCHAR*)text);
923 /* Escape the string. */
924 str2 = xmlEncodeEntitiesReentrant(This->node->doc, str);
925 HeapFree(GetProcessHeap(), 0, str);
927 xmlNodeSetContent(This->node, str2);
933 static HRESULT WINAPI xmlnode_get_specified(
935 VARIANT_BOOL* isSpecified)
941 static HRESULT WINAPI xmlnode_get_definition(
943 IXMLDOMNode** definitionNode)
949 static HRESULT WINAPI xmlnode_get_nodeTypedValue(
953 xmlnode *This = impl_from_IXMLDOMNode( iface );
956 FIXME("ignoring data type %p %p\n", This, typedValue);
961 V_VT(typedValue) = VT_NULL;
963 switch ( This->node->type )
965 case XML_ELEMENT_NODE:
967 xmlChar *content = xmlNodeGetContent(This->node);
968 V_VT(typedValue) = VT_BSTR;
969 V_BSTR(typedValue) = bstr_from_xmlChar( content );
975 r = xmlnode_get_nodeValue(iface, typedValue);
981 static HRESULT WINAPI xmlnode_put_nodeTypedValue(
989 static HRESULT WINAPI xmlnode_get_dataType(
991 VARIANT* dataTypeName)
993 xmlnode *This = impl_from_IXMLDOMNode( iface );
996 TRACE("iface %p\n", iface);
1001 /* Attribute, CDATA Section, Comment, Document, Document Fragment,
1002 Entity, Notation, PI, and Text Node are non-typed. */
1003 V_BSTR(dataTypeName) = NULL;
1004 V_VT(dataTypeName) = VT_NULL;
1006 switch ( This->node->type )
1008 case XML_ELEMENT_NODE:
1009 pVal = xmlGetNsProp(This->node, (xmlChar*)"dt",
1010 (xmlChar*)"urn:schemas-microsoft-com:datatypes");
1013 V_VT(dataTypeName) = VT_BSTR;
1014 V_BSTR(dataTypeName) = bstr_from_xmlChar( pVal );
1018 case XML_ENTITY_REF_NODE:
1019 FIXME("XML_ENTITY_REF_NODE should return a valid value.\n");
1022 TRACE("Type %d returning NULL\n", This->node->type);
1025 /* non-typed nodes return S_FALSE */
1026 if(V_VT(dataTypeName) == VT_NULL)
1034 static HRESULT WINAPI xmlnode_put_dataType(
1038 xmlnode *This = impl_from_IXMLDOMNode( iface );
1039 HRESULT hr = E_FAIL;
1041 TRACE("iface %p\n", iface);
1043 if(dataTypeName == NULL)
1044 return E_INVALIDARG;
1046 /* An example of this is. The Text in the node needs to be a 0 or 1 for a boolean type.
1047 This applies to changing types (string->bool) or setting a new one
1049 FIXME("Need to Validate the data before allowing a type to be set.\n");
1051 /* Check all supported types. */
1052 if(lstrcmpiW(dataTypeName,szString) == 0 ||
1053 lstrcmpiW(dataTypeName,szNumber) == 0 ||
1054 lstrcmpiW(dataTypeName,szUUID) == 0 ||
1055 lstrcmpiW(dataTypeName,szInt) == 0 ||
1056 lstrcmpiW(dataTypeName,szI4) == 0 ||
1057 lstrcmpiW(dataTypeName,szFixed) == 0 ||
1058 lstrcmpiW(dataTypeName,szBoolean) == 0 ||
1059 lstrcmpiW(dataTypeName,szDateTime) == 0 ||
1060 lstrcmpiW(dataTypeName,szDateTimeTZ) == 0 ||
1061 lstrcmpiW(dataTypeName,szDate) == 0 ||
1062 lstrcmpiW(dataTypeName,szTime) == 0 ||
1063 lstrcmpiW(dataTypeName,szTimeTZ) == 0 ||
1064 lstrcmpiW(dataTypeName,szI1) == 0 ||
1065 lstrcmpiW(dataTypeName,szI2) == 0 ||
1066 lstrcmpiW(dataTypeName,szIU1) == 0 ||
1067 lstrcmpiW(dataTypeName,szIU2) == 0 ||
1068 lstrcmpiW(dataTypeName,szIU4) == 0 ||
1069 lstrcmpiW(dataTypeName,szR4) == 0 ||
1070 lstrcmpiW(dataTypeName,szR8) == 0 ||
1071 lstrcmpiW(dataTypeName,szFloat) == 0 ||
1072 lstrcmpiW(dataTypeName,szBinHex) == 0 ||
1073 lstrcmpiW(dataTypeName,szBinBase64) == 0)
1075 xmlNsPtr pNS = NULL;
1076 xmlAttrPtr pAttr = NULL;
1077 xmlChar* str = xmlChar_from_wchar((WCHAR*)dataTypeName);
1079 pAttr = xmlHasNsProp(This->node, (xmlChar*)"dt",
1080 (xmlChar*)"urn:schemas-microsoft-com:datatypes");
1083 pAttr = xmlSetNsProp(This->node, pAttr->ns, (xmlChar*)"dt", str);
1089 pNS = xmlNewNs(This->node, (xmlChar*)"urn:schemas-microsoft-com:datatypes", (xmlChar*)"dt");
1092 pAttr = xmlNewNsProp(This->node, pNS, (xmlChar*)"dt", str);
1095 xmlAddChild(This->node, (xmlNodePtr)pAttr);
1100 ERR("Failed to create Attribute\n");
1103 ERR("Failed to Create Namepsace\n");
1105 HeapFree( GetProcessHeap(), 0, str );
1111 static BSTR EnsureCorrectEOL(BSTR sInput)
1113 static const WCHAR SZ_RETURN[] = {'\n',0};
1114 static const WCHAR SZ_LINEFEED[] = {'\r',0};
1120 nLen = lstrlenW(sInput);
1121 /* Count line endings */
1122 for(i=0; i < nLen; i++)
1124 if(sInput[i] == SZ_RETURN[0])
1128 TRACE("len=%d, num=%d\n", nLen, nNum);
1130 /* Add linefeed as needed */
1134 sNew = SysAllocStringLen(NULL, nLen + nNum+1);
1135 for(i=0; i < nLen; i++)
1137 if(sInput[i] == SZ_RETURN[0])
1139 sNew[i+nPlace] = SZ_LINEFEED[0];
1142 sNew[i+nPlace] = sInput[i];
1145 SysFreeString(sInput);
1152 TRACE("len %d\n", lstrlenW(sNew));
1157 /* Removes encoding information and last character (nullbyte) */
1158 static BSTR EnsureNoEncoding(BSTR sInput)
1160 static const WCHAR wszEncoding[] = {'e','n','c','o','d','i','n','g','='};
1165 while(*pBeg != '\n' && memcmp(pBeg, wszEncoding, sizeof(wszEncoding)))
1170 SysReAllocStringLen(&sInput, sInput, SysStringLen(sInput)-1);
1175 pEnd = pBeg + sizeof(wszEncoding)/sizeof(WCHAR) + 2;
1176 while(*pEnd != '\"') pEnd++;
1179 sNew = SysAllocStringLen(NULL,
1180 pBeg-sInput + SysStringLen(sInput)-(pEnd-sInput)-1);
1181 memcpy(sNew, sInput, (pBeg-sInput)*sizeof(WCHAR));
1182 memcpy(&sNew[pBeg-sInput], pEnd, (SysStringLen(sInput)-(pEnd-sInput)-1)*sizeof(WCHAR));
1184 SysFreeString(sInput);
1189 * We are trying to replicate the same behaviour as msxml by converting
1190 * line endings to \r\n and using idents as \t. The problem is that msxml
1191 * only formats nodes that have a line ending. Using libxml we cannot
1192 * reproduce behaviour exactly.
1195 static HRESULT WINAPI xmlnode_get_xml(
1199 xmlnode *This = impl_from_IXMLDOMNode( iface );
1200 xmlBufferPtr pXmlBuf;
1203 TRACE("iface %p %d\n", iface, This->node->type);
1206 return E_INVALIDARG;
1210 pXmlBuf = xmlBufferCreate();
1213 nSize = xmlNodeDump(pXmlBuf, This->node->doc, This->node, 0, 1);
1216 const xmlChar *pContent;
1219 /* Attribute Nodes return a space in front of their name */
1220 pContent = xmlBufferContent(pXmlBuf);
1221 if( ((char*)pContent)[0] == ' ')
1222 bstrContent = bstr_from_xmlChar(pContent+1);
1224 bstrContent = bstr_from_xmlChar(pContent);
1226 switch(This->node->type)
1228 case XML_ELEMENT_NODE:
1229 *xmlString = EnsureCorrectEOL(bstrContent);
1231 case XML_DOCUMENT_NODE:
1232 *xmlString = EnsureCorrectEOL(bstrContent);
1233 *xmlString = EnsureNoEncoding(*xmlString);
1236 *xmlString = bstrContent;
1240 xmlBufferFree(pXmlBuf);
1243 /* Always returns a string. */
1244 if(*xmlString == NULL) *xmlString = SysAllocStringLen( NULL, 0 );
1249 static HRESULT WINAPI xmlnode_transformNode(
1251 IXMLDOMNode* styleSheet,
1254 #ifdef SONAME_LIBXSLT
1255 xmlnode *This = impl_from_IXMLDOMNode( iface );
1256 xmlnode *pStyleSheet = NULL;
1257 xsltStylesheetPtr xsltSS = NULL;
1258 xmlDocPtr result = NULL;
1261 TRACE("%p %p %p\n", This, styleSheet, xmlString);
1263 if (!libxslt_handle)
1265 if(!styleSheet || !xmlString)
1266 return E_INVALIDARG;
1270 if(IXMLDOMNode_QueryInterface(styleSheet, &IID_IXMLDOMNode, (LPVOID)&ssNew) == S_OK)
1272 pStyleSheet = impl_from_IXMLDOMNode( ssNew );
1274 xsltSS = pxsltParseStylesheetDoc( pStyleSheet->node->doc);
1277 result = pxsltApplyStylesheet(xsltSS, This->node->doc, NULL);
1280 const xmlChar *pContent;
1282 if(result->type == XML_HTML_DOCUMENT_NODE)
1284 xmlOutputBufferPtr pOutput = xmlAllocOutputBuffer(NULL);
1287 htmlDocContentDumpOutput(pOutput, result->doc, NULL);
1288 pContent = xmlBufferContent(pOutput->buffer);
1289 *xmlString = bstr_from_xmlChar(pContent);
1290 xmlOutputBufferClose(pOutput);
1295 xmlBufferPtr pXmlBuf;
1298 pXmlBuf = xmlBufferCreate();
1301 nSize = xmlNodeDump(pXmlBuf, NULL, (xmlNodePtr)result, 0, 0);
1304 pContent = xmlBufferContent(pXmlBuf);
1305 *xmlString = bstr_from_xmlChar(pContent);
1307 xmlBufferFree(pXmlBuf);
1312 /* libxslt "helpfully" frees the XML document the stylesheet was
1313 generated from, too */
1315 pxsltFreeStylesheet(xsltSS);
1318 IXMLDOMNode_Release(ssNew);
1321 if(*xmlString == NULL)
1322 *xmlString = SysAllocStringLen(NULL, 0);
1326 FIXME("libxslt headers were not found at compile time\n");
1331 static HRESULT WINAPI xmlnode_selectNodes(
1334 IXMLDOMNodeList** resultList)
1336 xmlnode *This = impl_from_IXMLDOMNode( iface );
1338 TRACE("%p %s %p\n", This, debugstr_w(queryString), resultList );
1340 return queryresult_create( This->node, queryString, resultList );
1343 static HRESULT WINAPI xmlnode_selectSingleNode(
1346 IXMLDOMNode** resultNode)
1348 xmlnode *This = impl_from_IXMLDOMNode( iface );
1349 IXMLDOMNodeList *list;
1352 TRACE("%p %s %p\n", This, debugstr_w(queryString), resultNode );
1355 r = IXMLDOMNode_selectNodes(iface, queryString, &list);
1358 r = IXMLDOMNodeList_nextNode(list, resultNode);
1359 IXMLDOMNodeList_Release(list);
1364 static HRESULT WINAPI xmlnode_get_parsed(
1366 VARIANT_BOOL* isParsed)
1372 static HRESULT WINAPI xmlnode_get_namespaceURI(
1376 xmlnode *This = impl_from_IXMLDOMNode( iface );
1377 HRESULT hr = S_FALSE;
1380 TRACE("%p %p\n", This, namespaceURI );
1383 return E_INVALIDARG;
1385 *namespaceURI = NULL;
1387 pNSList = xmlGetNsList(This->node->doc, This->node);
1390 *namespaceURI = bstr_from_xmlChar( pNSList[0]->href );
1399 static HRESULT WINAPI xmlnode_get_prefix(
1403 xmlnode *This = impl_from_IXMLDOMNode( iface );
1404 HRESULT hr = S_FALSE;
1407 TRACE("%p %p\n", This, prefixString );
1410 return E_INVALIDARG;
1412 *prefixString = NULL;
1414 pNSList = xmlGetNsList(This->node->doc, This->node);
1417 *prefixString = bstr_from_xmlChar( pNSList[0]->prefix );
1426 static HRESULT WINAPI xmlnode_get_baseName(
1430 xmlnode *This = impl_from_IXMLDOMNode( iface );
1432 HRESULT r = S_FALSE;
1434 TRACE("%p %p\n", This, nameString );
1437 return E_INVALIDARG;
1439 switch ( This->node->type )
1441 case XML_ELEMENT_NODE:
1442 case XML_ATTRIBUTE_NODE:
1443 str = bstr_from_xmlChar( This->node->name );
1449 ERR("Unhandled type %d\n", This->node->type );
1453 TRACE("returning %08x str = %s\n", r, debugstr_w( str ) );
1459 static HRESULT WINAPI xmlnode_transformNodeToObject(
1461 IXMLDOMNode* stylesheet,
1462 VARIANT outputObject)
1468 static const struct IXMLDOMNodeVtbl xmlnode_vtbl =
1470 xmlnode_QueryInterface,
1473 xmlnode_GetTypeInfoCount,
1474 xmlnode_GetTypeInfo,
1475 xmlnode_GetIDsOfNames,
1477 xmlnode_get_nodeName,
1478 xmlnode_get_nodeValue,
1479 xmlnode_put_nodeValue,
1480 xmlnode_get_nodeType,
1481 xmlnode_get_parentNode,
1482 xmlnode_get_childNodes,
1483 xmlnode_get_firstChild,
1484 xmlnode_get_lastChild,
1485 xmlnode_get_previousSibling,
1486 xmlnode_get_nextSibling,
1487 xmlnode_get_attributes,
1488 xmlnode_insertBefore,
1489 xmlnode_replaceChild,
1490 xmlnode_removeChild,
1491 xmlnode_appendChild,
1492 xmlnode_hasChildNodes,
1493 xmlnode_get_ownerDocument,
1495 xmlnode_get_nodeTypeString,
1498 xmlnode_get_specified,
1499 xmlnode_get_definition,
1500 xmlnode_get_nodeTypedValue,
1501 xmlnode_put_nodeTypedValue,
1502 xmlnode_get_dataType,
1503 xmlnode_put_dataType,
1505 xmlnode_transformNode,
1506 xmlnode_selectNodes,
1507 xmlnode_selectSingleNode,
1509 xmlnode_get_namespaceURI,
1511 xmlnode_get_baseName,
1512 xmlnode_transformNodeToObject,
1515 static HRESULT WINAPI Internal_QueryInterface(
1520 xmlnode *This = impl_from_InternalUnknown( iface );
1522 TRACE("%p %s %p\n", iface, debugstr_guid(riid), ppvObject);
1525 if ( IsEqualGUID( riid, &IID_IUnknown ))
1527 else if ( IsEqualGUID( riid, &IID_IDispatch ) ||
1528 IsEqualGUID( riid, &IID_IXMLDOMNode ) )
1529 *ppvObject = &This->lpVtbl;
1532 FIXME("interface %s not implemented\n", debugstr_guid(riid));
1534 return E_NOINTERFACE;
1537 IUnknown_AddRef( (IUnknown*)*ppvObject );
1542 static ULONG WINAPI Internal_AddRef(
1545 xmlnode *This = impl_from_InternalUnknown( iface );
1546 return InterlockedIncrement( &This->ref );
1549 static ULONG WINAPI Internal_Release(
1552 xmlnode *This = impl_from_InternalUnknown( iface );
1555 ref = InterlockedDecrement( &This->ref );
1559 xmldoc_release( This->node->doc );
1560 HeapFree( GetProcessHeap(), 0, This );
1566 static const struct IUnknownVtbl internal_unk_vtbl =
1568 Internal_QueryInterface,
1573 IUnknown *create_basic_node( xmlNodePtr node, IUnknown *pUnkOuter )
1577 This = HeapAlloc( GetProcessHeap(), 0, sizeof *This );
1582 xmldoc_add_ref( node->doc );
1584 This->lpVtbl = &xmlnode_vtbl;
1585 This->lpInternalUnkVtbl = &internal_unk_vtbl;
1588 This->pUnkOuter = pUnkOuter; /* Don't take a ref on outer Unknown */
1590 This->pUnkOuter = (IUnknown *)&This->lpInternalUnkVtbl;
1595 return (IUnknown*)&This->lpInternalUnkVtbl;
1598 IXMLDOMNode *create_node( xmlNodePtr node )
1607 TRACE("type %d\n", node->type);
1610 case XML_ELEMENT_NODE:
1611 pUnk = create_element( node, NULL );
1613 case XML_ATTRIBUTE_NODE:
1614 pUnk = create_attribute( node );
1617 pUnk = create_text( node );
1619 case XML_CDATA_SECTION_NODE:
1620 pUnk = create_cdata( node );
1622 case XML_COMMENT_NODE:
1623 pUnk = create_comment( node );
1625 case XML_DOCUMENT_NODE:
1626 pUnk = create_domdoc( node );
1629 FIXME("only creating basic node for type %d\n", node->type);
1630 pUnk = create_basic_node( node, NULL );
1633 hr = IUnknown_QueryInterface(pUnk, &IID_IXMLDOMNode, (LPVOID*)&ret);
1634 IUnknown_Release(pUnk);
1635 if(FAILED(hr)) return NULL;