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 # ifdef HAVE_LIBXSLT_PATTERN_H
38 # include <libxslt/pattern.h>
40 # ifdef HAVE_LIBXSLT_TRANSFORM_H
41 # include <libxslt/transform.h>
43 # include <libxslt/xsltutils.h>
44 # include <libxslt/xsltInternals.h>
48 # include <libxml/HTMLtree.h>
51 #include "wine/debug.h"
53 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
57 static const WCHAR szBinBase64[] = {'b','i','n','.','b','a','s','e','6','4',0};
58 static const WCHAR szString[] = {'s','t','r','i','n','g',0};
59 static const WCHAR szNumber[] = {'n','u','m','b','e','r',0};
60 static const WCHAR szInt[] = {'I','n','t',0};
61 static const WCHAR szFixed[] = {'F','i','x','e','d','.','1','4','.','4',0};
62 static const WCHAR szBoolean[] = {'B','o','o','l','e','a','n',0};
63 static const WCHAR szDateTime[] = {'d','a','t','e','T','i','m','e',0};
64 static const WCHAR szDateTimeTZ[] = {'d','a','t','e','T','i','m','e','.','t','z',0};
65 static const WCHAR szDate[] = {'D','a','t','e',0};
66 static const WCHAR szTime[] = {'T','i','m','e',0};
67 static const WCHAR szTimeTZ[] = {'T','i','m','e','.','t','z',0};
68 static const WCHAR szI1[] = {'i','1',0};
69 static const WCHAR szI2[] = {'i','2',0};
70 static const WCHAR szI4[] = {'i','4',0};
71 static const WCHAR szIU1[] = {'u','i','1',0};
72 static const WCHAR szIU2[] = {'u','i','2',0};
73 static const WCHAR szIU4[] = {'u','i','4',0};
74 static const WCHAR szR4[] = {'r','4',0};
75 static const WCHAR szR8[] = {'r','8',0};
76 static const WCHAR szFloat[] = {'f','l','o','a','t',0};
77 static const WCHAR szUUID[] = {'u','u','i','d',0};
78 static const WCHAR szBinHex[] = {'b','i','n','.','h','e','x',0};
80 static inline xmlnode *impl_from_InternalUnknown( IUnknown *iface )
82 return (xmlnode *)((char*)iface - FIELD_OFFSET(xmlnode, lpInternalUnkVtbl));
85 xmlNodePtr xmlNodePtr_from_domnode( IXMLDOMNode *iface, xmlElementType type )
91 This = impl_from_IXMLDOMNode( iface );
94 if ( type && This->node->type != type )
99 void attach_xmlnode( IXMLDOMNode *node, xmlNodePtr xml )
101 xmlnode *This = impl_from_IXMLDOMNode( node );
104 xmldoc_release(This->node->doc);
108 xmldoc_add_ref(This->node->doc);
113 static HRESULT WINAPI xmlnode_QueryInterface(
118 xmlnode *This = impl_from_IXMLDOMNode( iface );
119 TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
121 return IUnknown_QueryInterface(This->pUnkOuter, riid, ppvObject);
124 static ULONG WINAPI xmlnode_AddRef(
127 xmlnode *This = impl_from_IXMLDOMNode( iface );
128 return IUnknown_AddRef(This->pUnkOuter);
131 static ULONG WINAPI xmlnode_Release(
134 xmlnode *This = impl_from_IXMLDOMNode( iface );
135 return IUnknown_Release(This->pUnkOuter);
138 static HRESULT WINAPI xmlnode_GetTypeInfoCount(
142 xmlnode *This = impl_from_IXMLDOMNode( iface );
144 TRACE("(%p)->(%p)\n", This, pctinfo);
151 static HRESULT WINAPI xmlnode_GetTypeInfo(
155 ITypeInfo** ppTInfo )
157 xmlnode *This = impl_from_IXMLDOMNode( iface );
160 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
162 hr = get_typeinfo(IXMLDOMNode_tid, ppTInfo);
167 static HRESULT WINAPI xmlnode_GetIDsOfNames(
175 xmlnode *This = impl_from_IXMLDOMNode( iface );
180 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
183 if(!rgszNames || cNames == 0 || !rgDispId)
186 hr = get_typeinfo(IXMLDOMNode_tid, &typeinfo);
189 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
190 ITypeInfo_Release(typeinfo);
196 static HRESULT WINAPI xmlnode_Invoke(
202 DISPPARAMS* pDispParams,
204 EXCEPINFO* pExcepInfo,
207 xmlnode *This = impl_from_IXMLDOMNode( iface );
211 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
212 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
214 hr = get_typeinfo(IXMLDOMNode_tid, &typeinfo);
217 hr = ITypeInfo_Invoke(typeinfo, &(This->lpVtbl), dispIdMember, wFlags, pDispParams,
218 pVarResult, pExcepInfo, puArgErr);
219 ITypeInfo_Release(typeinfo);
225 static HRESULT WINAPI xmlnode_get_nodeName(
229 xmlnode *This = impl_from_IXMLDOMNode( iface );
232 TRACE("%p\n", This );
240 switch( This->node->type )
242 case XML_CDATA_SECTION_NODE:
243 str = (const xmlChar*) "#cdata-section";
245 case XML_COMMENT_NODE:
246 str = (const xmlChar*) "#comment";
248 case XML_DOCUMENT_FRAG_NODE:
249 str = (const xmlChar*) "#document-fragment";
252 str = (const xmlChar*) "#text";
254 case XML_DOCUMENT_NODE:
255 str = (const xmlChar*) "#document";
257 case XML_ATTRIBUTE_NODE:
258 case XML_ELEMENT_NODE:
260 str = This->node->name;
263 FIXME("nodeName not mapped correctly (%d)\n", This->node->type);
264 str = This->node->name;
268 *name = bstr_from_xmlChar( str );
275 BSTR bstr_from_xmlChar( const xmlChar *buf )
284 len = MultiByteToWideChar( CP_UTF8, 0, (LPCSTR) buf, -1, NULL, 0 );
285 str = (LPWSTR) HeapAlloc( GetProcessHeap(), 0, len * sizeof (WCHAR) );
288 MultiByteToWideChar( CP_UTF8, 0, (LPCSTR) buf, -1, str, len );
289 bstr = SysAllocString( str );
290 HeapFree( GetProcessHeap(), 0, str );
294 static HRESULT WINAPI xmlnode_get_nodeValue(
298 xmlnode *This = impl_from_IXMLDOMNode( iface );
301 TRACE("%p %p\n", This, value);
306 V_BSTR(value) = NULL;
307 V_VT(value) = VT_NULL;
309 switch ( This->node->type )
311 case XML_CDATA_SECTION_NODE:
312 case XML_COMMENT_NODE:
314 case XML_ATTRIBUTE_NODE:
316 xmlChar *content = xmlNodeGetContent(This->node);
317 V_VT(value) = VT_BSTR;
318 V_BSTR(value) = bstr_from_xmlChar( content );
324 V_VT(value) = VT_BSTR;
325 V_BSTR(value) = bstr_from_xmlChar( This->node->content );
328 case XML_ELEMENT_NODE:
329 case XML_DOCUMENT_NODE:
330 /* these seem to return NULL */
334 FIXME("node %p type %d\n", This, This->node->type);
337 TRACE("%p returned %s\n", This, debugstr_w( V_BSTR(value) ) );
342 static HRESULT WINAPI xmlnode_put_nodeValue(
346 xmlnode *This = impl_from_IXMLDOMNode( iface );
347 HRESULT hr = S_FALSE;
350 TRACE("%p type(%d)\n", This, This->node->type);
352 /* Document, Document Fragment, Document Type, Element,
353 Entity, Entity Reference, Notation aren't supported. */
354 switch ( This->node->type )
356 case XML_ATTRIBUTE_NODE:
357 case XML_CDATA_SECTION_NODE:
358 case XML_COMMENT_NODE:
362 str = xmlChar_from_wchar((WCHAR*)V_BSTR(&value));
364 xmlNodeSetContent(This->node, str);
369 /* Do nothing for unsupported types. */
376 static HRESULT WINAPI xmlnode_get_nodeType(
380 xmlnode *This = impl_from_IXMLDOMNode( iface );
382 TRACE("%p %p\n", This, type);
384 assert( NODE_ELEMENT == XML_ELEMENT_NODE );
385 assert( NODE_NOTATION == XML_NOTATION_NODE );
387 *type = This->node->type;
392 static HRESULT get_node(
398 TRACE("%p->%s %p\n", This, name, node );
402 *out = create_node( node );
408 static HRESULT WINAPI xmlnode_get_parentNode(
410 IXMLDOMNode** parent)
412 xmlnode *This = impl_from_IXMLDOMNode( iface );
413 return get_node( This, "parent", This->node->parent, parent );
416 static HRESULT WINAPI xmlnode_get_childNodes(
418 IXMLDOMNodeList** childList)
420 xmlnode *This = impl_from_IXMLDOMNode( iface );
422 TRACE("%p %p\n", This, childList );
427 *childList = create_children_nodelist(This->node);
428 if (*childList == NULL)
429 return E_OUTOFMEMORY;
434 static HRESULT WINAPI xmlnode_get_firstChild(
436 IXMLDOMNode** firstChild)
438 xmlnode *This = impl_from_IXMLDOMNode( iface );
439 return get_node( This, "firstChild", This->node->children, firstChild );
442 static HRESULT WINAPI xmlnode_get_lastChild(
444 IXMLDOMNode** lastChild)
446 xmlnode *This = impl_from_IXMLDOMNode( iface );
448 TRACE("%p\n", This );
453 switch( This->node->type )
455 /* CDATASection, Comment, PI and Text Nodes do not support lastChild */
457 case XML_CDATA_SECTION_NODE:
459 case XML_COMMENT_NODE:
463 return get_node( This, "lastChild", This->node->last, lastChild );
467 static HRESULT WINAPI xmlnode_get_previousSibling(
469 IXMLDOMNode** previousSibling)
471 xmlnode *This = impl_from_IXMLDOMNode( iface );
473 TRACE("%p\n", This );
475 if (!previousSibling)
478 switch( This->node->type )
480 /* Attribute, Document and Document Fragment Nodes do not support previousSibling */
481 case XML_DOCUMENT_NODE:
482 case XML_DOCUMENT_FRAG_NODE:
483 case XML_ATTRIBUTE_NODE:
484 *previousSibling = NULL;
487 return get_node( This, "previous", This->node->prev, previousSibling );
491 static HRESULT WINAPI xmlnode_get_nextSibling(
493 IXMLDOMNode** nextSibling)
495 xmlnode *This = impl_from_IXMLDOMNode( iface );
497 TRACE("%p\n", This );
502 switch( This->node->type )
504 /* Attribute, Document and Document Fragment Nodes do not support nextSibling */
505 case XML_DOCUMENT_NODE:
506 case XML_DOCUMENT_FRAG_NODE:
507 case XML_ATTRIBUTE_NODE:
511 return get_node( This, "next", This->node->next, nextSibling );
515 static HRESULT WINAPI xmlnode_get_attributes(
517 IXMLDOMNamedNodeMap** attributeMap)
519 xmlnode *This = impl_from_IXMLDOMNode( iface );
525 switch( This->node->type )
527 /* Attribute, CDataSection, Comment, Documents, Documents Fragments,
528 Entity and Text Nodes does not support get_attributes */
529 case XML_ATTRIBUTE_NODE:
530 case XML_CDATA_SECTION_NODE:
531 case XML_COMMENT_NODE:
532 case XML_DOCUMENT_NODE:
533 case XML_DOCUMENT_FRAG_NODE:
534 case XML_ENTITY_NODE:
535 case XML_ENTITY_REF_NODE:
537 *attributeMap = NULL;
540 *attributeMap = create_nodemap( iface );
545 static HRESULT WINAPI xmlnode_insertBefore(
547 IXMLDOMNode* newChild,
549 IXMLDOMNode** outNewChild)
551 xmlnode *This = impl_from_IXMLDOMNode( iface );
552 xmlNodePtr before_node, new_child_node;
553 IXMLDOMNode *before = NULL, *new;
556 TRACE("(%p)->(%p,var,%p)\n",This,newChild,outNewChild);
561 switch(V_VT(&refChild))
568 hr = IUnknown_QueryInterface(V_UNKNOWN(&refChild), &IID_IXMLDOMNode, (LPVOID)&before);
569 if(FAILED(hr)) return hr;
573 hr = IDispatch_QueryInterface(V_DISPATCH(&refChild), &IID_IXMLDOMNode, (LPVOID)&before);
574 if(FAILED(hr)) return hr;
578 FIXME("refChild var type %x\n", V_VT(&refChild));
582 IXMLDOMNode_QueryInterface(newChild, &IID_IXMLDOMNode, (LPVOID)&new);
583 new_child_node = impl_from_IXMLDOMNode(new)->node;
584 TRACE("new_child_node %p This->node %p\n", new_child_node, This->node);
588 before_node = impl_from_IXMLDOMNode(before)->node;
589 xmlAddPrevSibling(before_node, new_child_node);
590 IXMLDOMNode_Release(before);
594 xmlAddChild(This->node, new_child_node);
597 IXMLDOMNode_Release(new);
598 IXMLDOMNode_AddRef(newChild);
600 *outNewChild = newChild;
606 static HRESULT WINAPI xmlnode_replaceChild(
608 IXMLDOMNode* newChild,
609 IXMLDOMNode* oldChild,
610 IXMLDOMNode** outOldChild)
612 xmlnode *This = impl_from_IXMLDOMNode( iface );
613 xmlNode *old_child_ptr, *new_child_ptr;
614 xmlDocPtr leaving_doc;
615 xmlNode *my_ancestor;
617 TRACE("%p->(%p,%p,%p)\n",This,newChild,oldChild,outOldChild);
619 /* Do not believe any documentation telling that newChild == NULL
620 means removal. It does certainly *not* apply to msxml3! */
621 if(!newChild || !oldChild)
627 old_child_ptr = impl_from_IXMLDOMNode(oldChild)->node;
628 if(old_child_ptr->parent != This->node)
630 WARN("childNode %p is not a child of %p\n", oldChild, iface);
634 new_child_ptr = impl_from_IXMLDOMNode(newChild)->node;
635 my_ancestor = This->node;
638 if(my_ancestor == new_child_ptr)
640 WARN("tried to create loop\n");
643 my_ancestor = my_ancestor->parent;
646 leaving_doc = new_child_ptr->doc;
647 xmldoc_add_ref(old_child_ptr->doc);
648 xmlReplaceNode(old_child_ptr, new_child_ptr);
649 xmldoc_release(leaving_doc);
653 IXMLDOMNode_AddRef(oldChild);
654 *outOldChild = oldChild;
660 static HRESULT WINAPI xmlnode_removeChild(
662 IXMLDOMNode* childNode,
663 IXMLDOMNode** oldChild)
665 xmlnode *This = impl_from_IXMLDOMNode( iface );
666 xmlNode *child_node_ptr;
668 TRACE("%p->(%p, %p)\n", This, childNode, oldChild);
670 if(!childNode) return E_INVALIDARG;
675 child_node_ptr = impl_from_IXMLDOMNode(childNode)->node;
676 if(child_node_ptr->parent != This->node)
678 WARN("childNode %p is not a child of %p\n", childNode, iface);
682 xmlUnlinkNode(child_node_ptr);
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;
765 pNode = create_node(pClone);
768 ERR("Copy failed\n");
776 ERR("Copy failed\n");
783 static HRESULT WINAPI xmlnode_get_nodeTypeString(
787 xmlnode *This = impl_from_IXMLDOMNode( iface );
790 TRACE("%p\n", This );
798 switch( This->node->type )
800 case XML_ATTRIBUTE_NODE:
801 str = (const xmlChar*) "attribute";
803 case XML_CDATA_SECTION_NODE:
804 str = (const xmlChar*) "cdatasection";
806 case XML_COMMENT_NODE:
807 str = (const xmlChar*) "comment";
809 case XML_DOCUMENT_NODE:
810 str = (const xmlChar*) "document";
812 case XML_DOCUMENT_FRAG_NODE:
813 str = (const xmlChar*) "documentfragment";
815 case XML_ELEMENT_NODE:
816 str = (const xmlChar*) "element";
818 case XML_ENTITY_NODE:
819 str = (const xmlChar*) "entity";
821 case XML_ENTITY_REF_NODE:
822 str = (const xmlChar*) "entityreference";
824 case XML_NOTATION_NODE:
825 str = (const xmlChar*) "notation";
828 str = (const xmlChar*) "processinginstruction";
831 str = (const xmlChar*) "text";
834 FIXME("Unknown node type (%d)\n", This->node->type);
835 str = This->node->name;
839 *xmlnodeType = bstr_from_xmlChar( str );
846 static HRESULT WINAPI xmlnode_get_text(
850 xmlnode *This = impl_from_IXMLDOMNode( iface );
858 switch(This->node->type)
860 case XML_ELEMENT_NODE:
861 case XML_ATTRIBUTE_NODE:
863 xmlNodePtr child = This->node->children;
864 if ( child && child->type == XML_TEXT_NODE )
865 str = bstr_from_xmlChar( child->content );
870 case XML_CDATA_SECTION_NODE:
872 case XML_COMMENT_NODE:
873 str = bstr_from_xmlChar( This->node->content );
877 FIXME("Unhandled node type %d\n", This->node->type);
880 /* Always return a string. */
881 if (!str) str = SysAllocStringLen( NULL, 0 );
883 TRACE("%p %s\n", This, debugstr_w(str) );
889 static HRESULT WINAPI xmlnode_put_text(
893 xmlnode *This = impl_from_IXMLDOMNode( iface );
898 switch(This->node->type)
900 case XML_DOCUMENT_NODE:
906 str = xmlChar_from_wchar((WCHAR*)text);
908 /* Escape the string. */
909 str = xmlEncodeEntitiesReentrant(This->node->doc, str);
910 str = xmlEncodeSpecialChars(This->node->doc, str);
912 xmlNodeSetContent(This->node, str);
918 static HRESULT WINAPI xmlnode_get_specified(
920 VARIANT_BOOL* isSpecified)
926 static HRESULT WINAPI xmlnode_get_definition(
928 IXMLDOMNode** definitionNode)
934 static HRESULT WINAPI xmlnode_get_nodeTypedValue(
938 FIXME("ignoring data type\n");
939 return xmlnode_get_nodeValue(iface, typedValue);
942 static HRESULT WINAPI xmlnode_put_nodeTypedValue(
950 static HRESULT WINAPI xmlnode_get_dataType(
952 VARIANT* dataTypeName)
954 xmlnode *This = impl_from_IXMLDOMNode( iface );
957 TRACE("iface %p\n", iface);
962 /* Attribute, CDATA Section, Comment, Document, Document Fragment,
963 Entity, Notation, PI, and Text Node are non-typed. */
964 V_BSTR(dataTypeName) = NULL;
965 V_VT(dataTypeName) = VT_NULL;
967 switch ( This->node->type )
969 case XML_ELEMENT_NODE:
970 pVal = xmlGetNsProp(This->node, (xmlChar*)"dt",
971 (xmlChar*)"urn:schemas-microsoft-com:datatypes");
974 V_VT(dataTypeName) = VT_BSTR;
975 V_BSTR(dataTypeName) = bstr_from_xmlChar( pVal );
979 case XML_ENTITY_REF_NODE:
980 FIXME("XML_ENTITY_REF_NODE should return a valid value.\n");
983 TRACE("Type %d returning NULL\n", This->node->type);
986 /* non-typed nodes return S_FALSE */
987 if(V_VT(dataTypeName) == VT_NULL)
995 static HRESULT WINAPI xmlnode_put_dataType(
999 xmlnode *This = impl_from_IXMLDOMNode( iface );
1000 HRESULT hr = E_FAIL;
1002 TRACE("iface %p\n", iface);
1004 if(dataTypeName == NULL)
1005 return E_INVALIDARG;
1007 /* An example of this is. The Text in the node needs to be a 0 or 1 for a boolean type.
1008 This applies to changing types (string->bool) or setting a new one
1010 FIXME("Need to Validate the data before allowing a type to be set.\n");
1012 /* Check all supported types. */
1013 if(lstrcmpiW(dataTypeName,szString) == 0 ||
1014 lstrcmpiW(dataTypeName,szNumber) == 0 ||
1015 lstrcmpiW(dataTypeName,szUUID) == 0 ||
1016 lstrcmpiW(dataTypeName,szInt) == 0 ||
1017 lstrcmpiW(dataTypeName,szI4) == 0 ||
1018 lstrcmpiW(dataTypeName,szFixed) == 0 ||
1019 lstrcmpiW(dataTypeName,szBoolean) == 0 ||
1020 lstrcmpiW(dataTypeName,szDateTime) == 0 ||
1021 lstrcmpiW(dataTypeName,szDateTimeTZ) == 0 ||
1022 lstrcmpiW(dataTypeName,szDate) == 0 ||
1023 lstrcmpiW(dataTypeName,szTime) == 0 ||
1024 lstrcmpiW(dataTypeName,szTimeTZ) == 0 ||
1025 lstrcmpiW(dataTypeName,szI1) == 0 ||
1026 lstrcmpiW(dataTypeName,szI2) == 0 ||
1027 lstrcmpiW(dataTypeName,szIU1) == 0 ||
1028 lstrcmpiW(dataTypeName,szIU2) == 0 ||
1029 lstrcmpiW(dataTypeName,szIU4) == 0 ||
1030 lstrcmpiW(dataTypeName,szR4) == 0 ||
1031 lstrcmpiW(dataTypeName,szR8) == 0 ||
1032 lstrcmpiW(dataTypeName,szFloat) == 0 ||
1033 lstrcmpiW(dataTypeName,szBinHex) == 0 ||
1034 lstrcmpiW(dataTypeName,szBinBase64) == 0)
1036 xmlNsPtr pNS = NULL;
1037 xmlAttrPtr pAttr = NULL;
1038 xmlChar* str = xmlChar_from_wchar((WCHAR*)dataTypeName);
1040 pAttr = xmlHasNsProp(This->node, (xmlChar*)"dt",
1041 (xmlChar*)"urn:schemas-microsoft-com:datatypes");
1044 pAttr = xmlSetNsProp(This->node, pAttr->ns, (xmlChar*)"dt", str);
1050 pNS = xmlNewNs(This->node, (xmlChar*)"urn:schemas-microsoft-com:datatypes", (xmlChar*)"dt");
1053 pAttr = xmlNewNsProp(This->node, pNS, (xmlChar*)"dt", str);
1056 xmlAddChild(This->node, (xmlNodePtr)pAttr);
1061 ERR("Failed to create Attribute\n");
1064 ERR("Failed to Create Namepsace\n");
1071 static BSTR EnsureCorrectEOL(BSTR sInput)
1073 static const WCHAR SZ_RETURN[] = {'\n',0};
1074 static const WCHAR SZ_LINEFEED[] = {'\r',0};
1080 nLen = lstrlenW(sInput);
1081 /* Count line endings */
1082 for(i=0; i < nLen; i++)
1084 if(sInput[i] == SZ_RETURN[0])
1088 TRACE("len=%d, num=%d\n", nLen, nNum);
1090 /* Add linefeed as needed */
1094 sNew = SysAllocStringLen(NULL, nLen + nNum+1);
1095 for(i=0; i < nLen; i++)
1097 if(sInput[i] == SZ_RETURN[0])
1099 sNew[i+nPlace] = SZ_LINEFEED[0];
1102 sNew[i+nPlace] = sInput[i];
1105 SysFreeString(sInput);
1112 TRACE("len %d\n", lstrlenW(sNew));
1117 /* Removes encoding information and last character (nullbyte) */
1118 static BSTR EnsureNoEncoding(BSTR sInput)
1120 static const WCHAR wszEncoding[] = {'e','n','c','o','d','i','n','g','='};
1125 while(*pBeg != '\n' && memcmp(pBeg, wszEncoding, sizeof(wszEncoding)))
1130 SysReAllocStringLen(&sInput, sInput, SysStringLen(sInput)-1);
1135 pEnd = pBeg + sizeof(wszEncoding)/sizeof(WCHAR) + 2;
1136 while(*pEnd != '\"') pEnd++;
1139 sNew = SysAllocStringLen(NULL,
1140 pBeg-sInput + SysStringLen(sInput)-(pEnd-sInput)-1);
1141 memcpy(sNew, sInput, (pBeg-sInput)*sizeof(WCHAR));
1142 memcpy(&sNew[pBeg-sInput], pEnd, (SysStringLen(sInput)-(pEnd-sInput)-1)*sizeof(WCHAR));
1144 SysFreeString(sInput);
1149 * We are trying to replicate the same behaviour as msxml by converting
1150 * line endings to \r\n and using idents as \t. The problem is that msxml
1151 * only formats nodes that have a line ending. Using libxml we cannot
1152 * reproduce behaviour exactly.
1155 static HRESULT WINAPI xmlnode_get_xml(
1159 xmlnode *This = impl_from_IXMLDOMNode( iface );
1160 xmlBufferPtr pXmlBuf;
1163 TRACE("iface %p %d\n", iface, This->node->type);
1166 return E_INVALIDARG;
1170 pXmlBuf = xmlBufferCreate();
1173 nSize = xmlNodeDump(pXmlBuf, This->node->doc, This->node, 0, 1);
1176 const xmlChar *pContent;
1179 /* Attribute Nodes return a space in front of their name */
1180 pContent = xmlBufferContent(pXmlBuf);
1181 if( ((char*)pContent)[0] == ' ')
1182 bstrContent = bstr_from_xmlChar(pContent+1);
1184 bstrContent = bstr_from_xmlChar(pContent);
1186 switch(This->node->type)
1188 case XML_ELEMENT_NODE:
1189 *xmlString = EnsureCorrectEOL(bstrContent);
1191 case XML_DOCUMENT_NODE:
1192 *xmlString = EnsureCorrectEOL(bstrContent);
1193 *xmlString = EnsureNoEncoding(*xmlString);
1196 *xmlString = bstrContent;
1200 xmlBufferFree(pXmlBuf);
1203 /* Always returns a string. */
1204 if(*xmlString == NULL) *xmlString = SysAllocStringLen( NULL, 0 );
1209 static HRESULT WINAPI xmlnode_transformNode(
1211 IXMLDOMNode* styleSheet,
1215 xmlnode *This = impl_from_IXMLDOMNode( iface );
1216 xmlnode *pStyleSheet = NULL;
1217 xsltStylesheetPtr xsltSS = NULL;
1218 xmlDocPtr result = NULL;
1221 TRACE("%p %p %p\n", This, styleSheet, xmlString);
1223 if(!styleSheet || !xmlString)
1224 return E_INVALIDARG;
1228 if(IXMLDOMNode_QueryInterface(styleSheet, &IID_IXMLDOMNode, (LPVOID)&ssNew) == S_OK)
1230 pStyleSheet = impl_from_IXMLDOMNode( ssNew );
1232 xsltSS = xsltParseStylesheetDoc( pStyleSheet->node->doc);
1235 result = xsltApplyStylesheet(xsltSS, This->node->doc, NULL);
1238 const xmlChar *pContent;
1240 if(result->type == XML_HTML_DOCUMENT_NODE)
1242 xmlOutputBufferPtr pOutput = xmlAllocOutputBuffer(NULL);
1245 htmlDocContentDumpOutput(pOutput, result->doc, NULL);
1248 pContent = xmlBufferContent(pOutput->buffer);
1249 *xmlString = bstr_from_xmlChar(pContent);
1252 xmlOutputBufferClose(pOutput);
1257 xmlBufferPtr pXmlBuf;
1260 pXmlBuf = xmlBufferCreate();
1263 nSize = xmlNodeDump(pXmlBuf, NULL, (xmlNodePtr)result, 0, 0);
1266 pContent = xmlBufferContent(pXmlBuf);
1267 *xmlString = bstr_from_xmlChar(pContent);
1269 xmlBufferFree(pXmlBuf);
1276 IXMLDOMNode_Release(ssNew);
1279 if(*xmlString == NULL)
1280 *xmlString = SysAllocStringLen(NULL, 0);
1284 FIXME("libxslt headers were not found at compile time\n");
1289 static HRESULT WINAPI xmlnode_selectNodes(
1292 IXMLDOMNodeList** resultList)
1294 xmlnode *This = impl_from_IXMLDOMNode( iface );
1296 TRACE("%p %s %p\n", This, debugstr_w(queryString), resultList );
1298 return queryresult_create( This->node, queryString, resultList );
1301 static HRESULT WINAPI xmlnode_selectSingleNode(
1304 IXMLDOMNode** resultNode)
1306 xmlnode *This = impl_from_IXMLDOMNode( iface );
1307 IXMLDOMNodeList *list;
1310 TRACE("%p %s %p\n", This, debugstr_w(queryString), resultNode );
1313 r = IXMLDOMNode_selectNodes(iface, queryString, &list);
1316 r = IXMLDOMNodeList_nextNode(list, resultNode);
1317 IXMLDOMNodeList_Release(list);
1322 static HRESULT WINAPI xmlnode_get_parsed(
1324 VARIANT_BOOL* isParsed)
1330 static HRESULT WINAPI xmlnode_get_namespaceURI(
1334 xmlnode *This = impl_from_IXMLDOMNode( iface );
1335 HRESULT hr = S_FALSE;
1338 TRACE("%p %p\n", This, namespaceURI );
1341 return E_INVALIDARG;
1343 *namespaceURI = NULL;
1345 pNSList = xmlGetNsList(This->node->doc, This->node);
1348 *namespaceURI = bstr_from_xmlChar( pNSList[0]->href );
1356 static HRESULT WINAPI xmlnode_get_prefix(
1360 xmlnode *This = impl_from_IXMLDOMNode( iface );
1361 HRESULT hr = S_FALSE;
1364 TRACE("%p %p\n", This, prefixString );
1367 return E_INVALIDARG;
1369 *prefixString = NULL;
1371 pNSList = xmlGetNsList(This->node->doc, This->node);
1374 *prefixString = bstr_from_xmlChar( pNSList[0]->prefix );
1382 static HRESULT WINAPI xmlnode_get_baseName(
1386 xmlnode *This = impl_from_IXMLDOMNode( iface );
1388 HRESULT r = S_FALSE;
1390 TRACE("%p %p\n", This, nameString );
1393 return E_INVALIDARG;
1395 switch ( This->node->type )
1397 case XML_ELEMENT_NODE:
1398 case XML_ATTRIBUTE_NODE:
1399 str = bstr_from_xmlChar( This->node->name );
1405 ERR("Unhandled type %d\n", This->node->type );
1409 TRACE("returning %08x str = %s\n", r, debugstr_w( str ) );
1415 static HRESULT WINAPI xmlnode_transformNodeToObject(
1417 IXMLDOMNode* stylesheet,
1418 VARIANT outputObject)
1424 static const struct IXMLDOMNodeVtbl xmlnode_vtbl =
1426 xmlnode_QueryInterface,
1429 xmlnode_GetTypeInfoCount,
1430 xmlnode_GetTypeInfo,
1431 xmlnode_GetIDsOfNames,
1433 xmlnode_get_nodeName,
1434 xmlnode_get_nodeValue,
1435 xmlnode_put_nodeValue,
1436 xmlnode_get_nodeType,
1437 xmlnode_get_parentNode,
1438 xmlnode_get_childNodes,
1439 xmlnode_get_firstChild,
1440 xmlnode_get_lastChild,
1441 xmlnode_get_previousSibling,
1442 xmlnode_get_nextSibling,
1443 xmlnode_get_attributes,
1444 xmlnode_insertBefore,
1445 xmlnode_replaceChild,
1446 xmlnode_removeChild,
1447 xmlnode_appendChild,
1448 xmlnode_hasChildNodes,
1449 xmlnode_get_ownerDocument,
1451 xmlnode_get_nodeTypeString,
1454 xmlnode_get_specified,
1455 xmlnode_get_definition,
1456 xmlnode_get_nodeTypedValue,
1457 xmlnode_put_nodeTypedValue,
1458 xmlnode_get_dataType,
1459 xmlnode_put_dataType,
1461 xmlnode_transformNode,
1462 xmlnode_selectNodes,
1463 xmlnode_selectSingleNode,
1465 xmlnode_get_namespaceURI,
1467 xmlnode_get_baseName,
1468 xmlnode_transformNodeToObject,
1471 static HRESULT WINAPI Internal_QueryInterface(
1476 xmlnode *This = impl_from_InternalUnknown( iface );
1478 TRACE("%p %s %p\n", iface, debugstr_guid(riid), ppvObject);
1481 if ( IsEqualGUID( riid, &IID_IUnknown ))
1483 else if ( IsEqualGUID( riid, &IID_IDispatch ) ||
1484 IsEqualGUID( riid, &IID_IXMLDOMNode ) )
1485 *ppvObject = &This->lpVtbl;
1488 FIXME("interface %s not implemented\n", debugstr_guid(riid));
1490 return E_NOINTERFACE;
1493 IUnknown_AddRef( (IUnknown*)*ppvObject );
1498 static ULONG WINAPI Internal_AddRef(
1501 xmlnode *This = impl_from_InternalUnknown( iface );
1502 return InterlockedIncrement( &This->ref );
1505 static ULONG WINAPI Internal_Release(
1508 xmlnode *This = impl_from_InternalUnknown( iface );
1511 ref = InterlockedDecrement( &This->ref );
1515 xmldoc_release( This->node->doc );
1516 HeapFree( GetProcessHeap(), 0, This );
1522 static const struct IUnknownVtbl internal_unk_vtbl =
1524 Internal_QueryInterface,
1529 IUnknown *create_basic_node( xmlNodePtr node, IUnknown *pUnkOuter )
1533 This = HeapAlloc( GetProcessHeap(), 0, sizeof *This );
1538 xmldoc_add_ref( node->doc );
1540 This->lpVtbl = &xmlnode_vtbl;
1541 This->lpInternalUnkVtbl = &internal_unk_vtbl;
1544 This->pUnkOuter = pUnkOuter; /* Don't take a ref on outer Unknown */
1546 This->pUnkOuter = (IUnknown *)&This->lpInternalUnkVtbl;
1551 return (IUnknown*)&This->lpInternalUnkVtbl;
1554 IXMLDOMNode *create_node( xmlNodePtr node )
1563 TRACE("type %d\n", node->type);
1566 case XML_ELEMENT_NODE:
1567 pUnk = create_element( node, NULL );
1569 case XML_ATTRIBUTE_NODE:
1570 pUnk = create_attribute( node );
1573 pUnk = create_text( node );
1575 case XML_CDATA_SECTION_NODE:
1576 pUnk = create_cdata( node );
1578 case XML_COMMENT_NODE:
1579 pUnk = create_comment( node );
1581 case XML_DOCUMENT_NODE:
1582 pUnk = create_domdoc( node );
1585 FIXME("only creating basic node for type %d\n", node->type);
1586 pUnk = create_basic_node( node, NULL );
1589 hr = IUnknown_QueryInterface(pUnk, &IID_IXMLDOMNode, (LPVOID*)&ret);
1590 IUnknown_Release(pUnk);
1591 if(FAILED(hr)) return NULL;