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 );
869 TRACE("%p type %d\n", This, This->node->type);
874 pContent = xmlNodeGetContent((xmlNodePtr)This->node);
877 str = bstr_from_xmlChar(pContent);
881 /* Always return a string. */
882 if (!str) str = SysAllocStringLen( NULL, 0 );
884 TRACE("%p %s\n", This, debugstr_w(str) );
890 static HRESULT WINAPI xmlnode_put_text(
894 xmlnode *This = impl_from_IXMLDOMNode( iface );
899 switch(This->node->type)
901 case XML_DOCUMENT_NODE:
907 str = xmlChar_from_wchar((WCHAR*)text);
909 /* Escape the string. */
910 str2 = xmlEncodeEntitiesReentrant(This->node->doc, str);
911 HeapFree(GetProcessHeap(), 0, str);
913 xmlNodeSetContent(This->node, str2);
919 static HRESULT WINAPI xmlnode_get_specified(
921 VARIANT_BOOL* isSpecified)
927 static HRESULT WINAPI xmlnode_get_definition(
929 IXMLDOMNode** definitionNode)
935 static HRESULT WINAPI xmlnode_get_nodeTypedValue(
939 xmlnode *This = impl_from_IXMLDOMNode( iface );
942 FIXME("ignoring data type %p %p\n", This, typedValue);
947 V_VT(typedValue) = VT_NULL;
949 switch ( This->node->type )
951 case XML_ELEMENT_NODE:
953 xmlChar *content = xmlNodeGetContent(This->node);
954 V_VT(typedValue) = VT_BSTR;
955 V_BSTR(typedValue) = bstr_from_xmlChar( content );
961 r = xmlnode_get_nodeValue(iface, typedValue);
967 static HRESULT WINAPI xmlnode_put_nodeTypedValue(
975 static HRESULT WINAPI xmlnode_get_dataType(
977 VARIANT* dataTypeName)
979 xmlnode *This = impl_from_IXMLDOMNode( iface );
982 TRACE("iface %p\n", iface);
987 /* Attribute, CDATA Section, Comment, Document, Document Fragment,
988 Entity, Notation, PI, and Text Node are non-typed. */
989 V_BSTR(dataTypeName) = NULL;
990 V_VT(dataTypeName) = VT_NULL;
992 switch ( This->node->type )
994 case XML_ELEMENT_NODE:
995 pVal = xmlGetNsProp(This->node, (xmlChar*)"dt",
996 (xmlChar*)"urn:schemas-microsoft-com:datatypes");
999 V_VT(dataTypeName) = VT_BSTR;
1000 V_BSTR(dataTypeName) = bstr_from_xmlChar( pVal );
1004 case XML_ENTITY_REF_NODE:
1005 FIXME("XML_ENTITY_REF_NODE should return a valid value.\n");
1008 TRACE("Type %d returning NULL\n", This->node->type);
1011 /* non-typed nodes return S_FALSE */
1012 if(V_VT(dataTypeName) == VT_NULL)
1020 static HRESULT WINAPI xmlnode_put_dataType(
1024 xmlnode *This = impl_from_IXMLDOMNode( iface );
1025 HRESULT hr = E_FAIL;
1027 TRACE("iface %p\n", iface);
1029 if(dataTypeName == NULL)
1030 return E_INVALIDARG;
1032 /* An example of this is. The Text in the node needs to be a 0 or 1 for a boolean type.
1033 This applies to changing types (string->bool) or setting a new one
1035 FIXME("Need to Validate the data before allowing a type to be set.\n");
1037 /* Check all supported types. */
1038 if(lstrcmpiW(dataTypeName,szString) == 0 ||
1039 lstrcmpiW(dataTypeName,szNumber) == 0 ||
1040 lstrcmpiW(dataTypeName,szUUID) == 0 ||
1041 lstrcmpiW(dataTypeName,szInt) == 0 ||
1042 lstrcmpiW(dataTypeName,szI4) == 0 ||
1043 lstrcmpiW(dataTypeName,szFixed) == 0 ||
1044 lstrcmpiW(dataTypeName,szBoolean) == 0 ||
1045 lstrcmpiW(dataTypeName,szDateTime) == 0 ||
1046 lstrcmpiW(dataTypeName,szDateTimeTZ) == 0 ||
1047 lstrcmpiW(dataTypeName,szDate) == 0 ||
1048 lstrcmpiW(dataTypeName,szTime) == 0 ||
1049 lstrcmpiW(dataTypeName,szTimeTZ) == 0 ||
1050 lstrcmpiW(dataTypeName,szI1) == 0 ||
1051 lstrcmpiW(dataTypeName,szI2) == 0 ||
1052 lstrcmpiW(dataTypeName,szIU1) == 0 ||
1053 lstrcmpiW(dataTypeName,szIU2) == 0 ||
1054 lstrcmpiW(dataTypeName,szIU4) == 0 ||
1055 lstrcmpiW(dataTypeName,szR4) == 0 ||
1056 lstrcmpiW(dataTypeName,szR8) == 0 ||
1057 lstrcmpiW(dataTypeName,szFloat) == 0 ||
1058 lstrcmpiW(dataTypeName,szBinHex) == 0 ||
1059 lstrcmpiW(dataTypeName,szBinBase64) == 0)
1061 xmlNsPtr pNS = NULL;
1062 xmlAttrPtr pAttr = NULL;
1063 xmlChar* str = xmlChar_from_wchar((WCHAR*)dataTypeName);
1065 pAttr = xmlHasNsProp(This->node, (xmlChar*)"dt",
1066 (xmlChar*)"urn:schemas-microsoft-com:datatypes");
1069 pAttr = xmlSetNsProp(This->node, pAttr->ns, (xmlChar*)"dt", str);
1075 pNS = xmlNewNs(This->node, (xmlChar*)"urn:schemas-microsoft-com:datatypes", (xmlChar*)"dt");
1078 pAttr = xmlNewNsProp(This->node, pNS, (xmlChar*)"dt", str);
1081 xmlAddChild(This->node, (xmlNodePtr)pAttr);
1086 ERR("Failed to create Attribute\n");
1089 ERR("Failed to Create Namepsace\n");
1091 HeapFree( GetProcessHeap(), 0, str );
1097 static BSTR EnsureCorrectEOL(BSTR sInput)
1099 static const WCHAR SZ_RETURN[] = {'\n',0};
1100 static const WCHAR SZ_LINEFEED[] = {'\r',0};
1106 nLen = lstrlenW(sInput);
1107 /* Count line endings */
1108 for(i=0; i < nLen; i++)
1110 if(sInput[i] == SZ_RETURN[0])
1114 TRACE("len=%d, num=%d\n", nLen, nNum);
1116 /* Add linefeed as needed */
1120 sNew = SysAllocStringLen(NULL, nLen + nNum+1);
1121 for(i=0; i < nLen; i++)
1123 if(sInput[i] == SZ_RETURN[0])
1125 sNew[i+nPlace] = SZ_LINEFEED[0];
1128 sNew[i+nPlace] = sInput[i];
1131 SysFreeString(sInput);
1138 TRACE("len %d\n", lstrlenW(sNew));
1143 /* Removes encoding information and last character (nullbyte) */
1144 static BSTR EnsureNoEncoding(BSTR sInput)
1146 static const WCHAR wszEncoding[] = {'e','n','c','o','d','i','n','g','='};
1151 while(*pBeg != '\n' && memcmp(pBeg, wszEncoding, sizeof(wszEncoding)))
1156 SysReAllocStringLen(&sInput, sInput, SysStringLen(sInput)-1);
1161 pEnd = pBeg + sizeof(wszEncoding)/sizeof(WCHAR) + 2;
1162 while(*pEnd != '\"') pEnd++;
1165 sNew = SysAllocStringLen(NULL,
1166 pBeg-sInput + SysStringLen(sInput)-(pEnd-sInput)-1);
1167 memcpy(sNew, sInput, (pBeg-sInput)*sizeof(WCHAR));
1168 memcpy(&sNew[pBeg-sInput], pEnd, (SysStringLen(sInput)-(pEnd-sInput)-1)*sizeof(WCHAR));
1170 SysFreeString(sInput);
1175 * We are trying to replicate the same behaviour as msxml by converting
1176 * line endings to \r\n and using idents as \t. The problem is that msxml
1177 * only formats nodes that have a line ending. Using libxml we cannot
1178 * reproduce behaviour exactly.
1181 static HRESULT WINAPI xmlnode_get_xml(
1185 xmlnode *This = impl_from_IXMLDOMNode( iface );
1186 xmlBufferPtr pXmlBuf;
1189 TRACE("iface %p %d\n", iface, This->node->type);
1192 return E_INVALIDARG;
1196 pXmlBuf = xmlBufferCreate();
1199 nSize = xmlNodeDump(pXmlBuf, This->node->doc, This->node, 0, 1);
1202 const xmlChar *pContent;
1205 /* Attribute Nodes return a space in front of their name */
1206 pContent = xmlBufferContent(pXmlBuf);
1207 if( ((char*)pContent)[0] == ' ')
1208 bstrContent = bstr_from_xmlChar(pContent+1);
1210 bstrContent = bstr_from_xmlChar(pContent);
1212 switch(This->node->type)
1214 case XML_ELEMENT_NODE:
1215 *xmlString = EnsureCorrectEOL(bstrContent);
1217 case XML_DOCUMENT_NODE:
1218 *xmlString = EnsureCorrectEOL(bstrContent);
1219 *xmlString = EnsureNoEncoding(*xmlString);
1222 *xmlString = bstrContent;
1226 xmlBufferFree(pXmlBuf);
1229 /* Always returns a string. */
1230 if(*xmlString == NULL) *xmlString = SysAllocStringLen( NULL, 0 );
1235 static HRESULT WINAPI xmlnode_transformNode(
1237 IXMLDOMNode* styleSheet,
1240 #ifdef SONAME_LIBXSLT
1241 xmlnode *This = impl_from_IXMLDOMNode( iface );
1242 xmlnode *pStyleSheet = NULL;
1243 xsltStylesheetPtr xsltSS = NULL;
1244 xmlDocPtr result = NULL;
1247 TRACE("%p %p %p\n", This, styleSheet, xmlString);
1249 if (!libxslt_handle)
1251 if(!styleSheet || !xmlString)
1252 return E_INVALIDARG;
1256 if(IXMLDOMNode_QueryInterface(styleSheet, &IID_IXMLDOMNode, (LPVOID)&ssNew) == S_OK)
1258 pStyleSheet = impl_from_IXMLDOMNode( ssNew );
1260 xsltSS = pxsltParseStylesheetDoc( pStyleSheet->node->doc);
1263 result = pxsltApplyStylesheet(xsltSS, This->node->doc, NULL);
1266 const xmlChar *pContent;
1268 if(result->type == XML_HTML_DOCUMENT_NODE)
1270 xmlOutputBufferPtr pOutput = xmlAllocOutputBuffer(NULL);
1273 htmlDocContentDumpOutput(pOutput, result->doc, NULL);
1274 pContent = xmlBufferContent(pOutput->buffer);
1275 *xmlString = bstr_from_xmlChar(pContent);
1276 xmlOutputBufferClose(pOutput);
1281 xmlBufferPtr pXmlBuf;
1284 pXmlBuf = xmlBufferCreate();
1287 nSize = xmlNodeDump(pXmlBuf, NULL, (xmlNodePtr)result, 0, 0);
1290 pContent = xmlBufferContent(pXmlBuf);
1291 *xmlString = bstr_from_xmlChar(pContent);
1293 xmlBufferFree(pXmlBuf);
1298 /* libxslt "helpfully" frees the XML document the stylesheet was
1299 generated from, too */
1301 pxsltFreeStylesheet(xsltSS);
1304 IXMLDOMNode_Release(ssNew);
1307 if(*xmlString == NULL)
1308 *xmlString = SysAllocStringLen(NULL, 0);
1312 FIXME("libxslt headers were not found at compile time\n");
1317 static HRESULT WINAPI xmlnode_selectNodes(
1320 IXMLDOMNodeList** resultList)
1322 xmlnode *This = impl_from_IXMLDOMNode( iface );
1324 TRACE("%p %s %p\n", This, debugstr_w(queryString), resultList );
1326 return queryresult_create( This->node, queryString, resultList );
1329 static HRESULT WINAPI xmlnode_selectSingleNode(
1332 IXMLDOMNode** resultNode)
1334 xmlnode *This = impl_from_IXMLDOMNode( iface );
1335 IXMLDOMNodeList *list;
1338 TRACE("%p %s %p\n", This, debugstr_w(queryString), resultNode );
1341 r = IXMLDOMNode_selectNodes(iface, queryString, &list);
1344 r = IXMLDOMNodeList_nextNode(list, resultNode);
1345 IXMLDOMNodeList_Release(list);
1350 static HRESULT WINAPI xmlnode_get_parsed(
1352 VARIANT_BOOL* isParsed)
1358 static HRESULT WINAPI xmlnode_get_namespaceURI(
1362 xmlnode *This = impl_from_IXMLDOMNode( iface );
1363 HRESULT hr = S_FALSE;
1366 TRACE("%p %p\n", This, namespaceURI );
1369 return E_INVALIDARG;
1371 *namespaceURI = NULL;
1373 pNSList = xmlGetNsList(This->node->doc, This->node);
1376 *namespaceURI = bstr_from_xmlChar( pNSList[0]->href );
1385 static HRESULT WINAPI xmlnode_get_prefix(
1389 xmlnode *This = impl_from_IXMLDOMNode( iface );
1390 HRESULT hr = S_FALSE;
1393 TRACE("%p %p\n", This, prefixString );
1396 return E_INVALIDARG;
1398 *prefixString = NULL;
1400 pNSList = xmlGetNsList(This->node->doc, This->node);
1403 *prefixString = bstr_from_xmlChar( pNSList[0]->prefix );
1412 static HRESULT WINAPI xmlnode_get_baseName(
1416 xmlnode *This = impl_from_IXMLDOMNode( iface );
1418 HRESULT r = S_FALSE;
1420 TRACE("%p %p\n", This, nameString );
1423 return E_INVALIDARG;
1425 switch ( This->node->type )
1427 case XML_ELEMENT_NODE:
1428 case XML_ATTRIBUTE_NODE:
1429 str = bstr_from_xmlChar( This->node->name );
1435 ERR("Unhandled type %d\n", This->node->type );
1439 TRACE("returning %08x str = %s\n", r, debugstr_w( str ) );
1445 static HRESULT WINAPI xmlnode_transformNodeToObject(
1447 IXMLDOMNode* stylesheet,
1448 VARIANT outputObject)
1454 static const struct IXMLDOMNodeVtbl xmlnode_vtbl =
1456 xmlnode_QueryInterface,
1459 xmlnode_GetTypeInfoCount,
1460 xmlnode_GetTypeInfo,
1461 xmlnode_GetIDsOfNames,
1463 xmlnode_get_nodeName,
1464 xmlnode_get_nodeValue,
1465 xmlnode_put_nodeValue,
1466 xmlnode_get_nodeType,
1467 xmlnode_get_parentNode,
1468 xmlnode_get_childNodes,
1469 xmlnode_get_firstChild,
1470 xmlnode_get_lastChild,
1471 xmlnode_get_previousSibling,
1472 xmlnode_get_nextSibling,
1473 xmlnode_get_attributes,
1474 xmlnode_insertBefore,
1475 xmlnode_replaceChild,
1476 xmlnode_removeChild,
1477 xmlnode_appendChild,
1478 xmlnode_hasChildNodes,
1479 xmlnode_get_ownerDocument,
1481 xmlnode_get_nodeTypeString,
1484 xmlnode_get_specified,
1485 xmlnode_get_definition,
1486 xmlnode_get_nodeTypedValue,
1487 xmlnode_put_nodeTypedValue,
1488 xmlnode_get_dataType,
1489 xmlnode_put_dataType,
1491 xmlnode_transformNode,
1492 xmlnode_selectNodes,
1493 xmlnode_selectSingleNode,
1495 xmlnode_get_namespaceURI,
1497 xmlnode_get_baseName,
1498 xmlnode_transformNodeToObject,
1501 static HRESULT WINAPI Internal_QueryInterface(
1506 xmlnode *This = impl_from_InternalUnknown( iface );
1508 TRACE("%p %s %p\n", iface, debugstr_guid(riid), ppvObject);
1511 if ( IsEqualGUID( riid, &IID_IUnknown ))
1513 else if ( IsEqualGUID( riid, &IID_IDispatch ) ||
1514 IsEqualGUID( riid, &IID_IXMLDOMNode ) )
1515 *ppvObject = &This->lpVtbl;
1518 FIXME("interface %s not implemented\n", debugstr_guid(riid));
1520 return E_NOINTERFACE;
1523 IUnknown_AddRef( (IUnknown*)*ppvObject );
1528 static ULONG WINAPI Internal_AddRef(
1531 xmlnode *This = impl_from_InternalUnknown( iface );
1532 return InterlockedIncrement( &This->ref );
1535 static ULONG WINAPI Internal_Release(
1538 xmlnode *This = impl_from_InternalUnknown( iface );
1541 ref = InterlockedDecrement( &This->ref );
1545 xmldoc_release( This->node->doc );
1546 HeapFree( GetProcessHeap(), 0, This );
1552 static const struct IUnknownVtbl internal_unk_vtbl =
1554 Internal_QueryInterface,
1559 IUnknown *create_basic_node( xmlNodePtr node, IUnknown *pUnkOuter )
1563 This = HeapAlloc( GetProcessHeap(), 0, sizeof *This );
1568 xmldoc_add_ref( node->doc );
1570 This->lpVtbl = &xmlnode_vtbl;
1571 This->lpInternalUnkVtbl = &internal_unk_vtbl;
1574 This->pUnkOuter = pUnkOuter; /* Don't take a ref on outer Unknown */
1576 This->pUnkOuter = (IUnknown *)&This->lpInternalUnkVtbl;
1581 return (IUnknown*)&This->lpInternalUnkVtbl;
1584 IXMLDOMNode *create_node( xmlNodePtr node )
1593 TRACE("type %d\n", node->type);
1596 case XML_ELEMENT_NODE:
1597 pUnk = create_element( node, NULL );
1599 case XML_ATTRIBUTE_NODE:
1600 pUnk = create_attribute( node );
1603 pUnk = create_text( node );
1605 case XML_CDATA_SECTION_NODE:
1606 pUnk = create_cdata( node );
1608 case XML_COMMENT_NODE:
1609 pUnk = create_comment( node );
1611 case XML_DOCUMENT_NODE:
1612 pUnk = create_domdoc( node );
1615 FIXME("only creating basic node for type %d\n", node->type);
1616 pUnk = create_basic_node( node, NULL );
1619 hr = IUnknown_QueryInterface(pUnk, &IID_IXMLDOMNode, (LPVOID*)&ret);
1620 IUnknown_Release(pUnk);
1621 if(FAILED(hr)) return NULL;