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"
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(msxml
);
42 static const WCHAR szBinBase64
[] = {'b','i','n','.','b','a','s','e','6','4',0};
43 static const WCHAR szString
[] = {'s','t','r','i','n','g',0};
44 static const WCHAR szNumber
[] = {'n','u','m','b','e','r',0};
45 static const WCHAR szInt
[] = {'I','n','t',0};
46 static const WCHAR szFixed
[] = {'F','i','x','e','d','.','1','4','.','4',0};
47 static const WCHAR szBoolean
[] = {'B','o','o','l','e','a','n',0};
48 static const WCHAR szDateTime
[] = {'d','a','t','e','T','i','m','e',0};
49 static const WCHAR szDateTimeTZ
[] = {'d','a','t','e','T','i','m','e','.','t','z',0};
50 static const WCHAR szDate
[] = {'D','a','t','e',0};
51 static const WCHAR szTime
[] = {'T','i','m','e',0};
52 static const WCHAR szTimeTZ
[] = {'T','i','m','e','.','t','z',0};
53 static const WCHAR szI1
[] = {'i','1',0};
54 static const WCHAR szI2
[] = {'i','2',0};
55 static const WCHAR szI4
[] = {'i','4',0};
56 static const WCHAR szIU1
[] = {'u','i','1',0};
57 static const WCHAR szIU2
[] = {'u','i','2',0};
58 static const WCHAR szIU4
[] = {'u','i','4',0};
59 static const WCHAR szR4
[] = {'r','4',0};
60 static const WCHAR szR8
[] = {'r','8',0};
61 static const WCHAR szFloat
[] = {'f','l','o','a','t',0};
62 static const WCHAR szUUID
[] = {'u','u','i','d',0};
63 static const WCHAR szBinHex
[] = {'b','i','n','.','h','e','x',0};
65 static inline xmlnode
*impl_from_InternalUnknown( IUnknown
*iface
)
67 return (xmlnode
*)((char*)iface
- FIELD_OFFSET(xmlnode
, lpInternalUnkVtbl
));
70 xmlNodePtr
xmlNodePtr_from_domnode( IXMLDOMNode
*iface
, xmlElementType type
)
76 This
= impl_from_IXMLDOMNode( iface
);
79 if ( type
&& This
->node
->type
!= type
)
84 void attach_xmlnode( IXMLDOMNode
*node
, xmlNodePtr xml
)
86 xmlnode
*This
= impl_from_IXMLDOMNode( node
);
89 xmldoc_release(This
->node
->doc
);
93 xmldoc_add_ref(This
->node
->doc
);
98 static HRESULT WINAPI
xmlnode_QueryInterface(
103 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
104 TRACE("%p %s %p\n", This
, debugstr_guid(riid
), ppvObject
);
106 return IUnknown_QueryInterface(This
->pUnkOuter
, riid
, ppvObject
);
109 static ULONG WINAPI
xmlnode_AddRef(
112 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
113 return IUnknown_AddRef(This
->pUnkOuter
);
116 static ULONG WINAPI
xmlnode_Release(
119 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
120 return IUnknown_Release(This
->pUnkOuter
);
123 static HRESULT WINAPI
xmlnode_GetTypeInfoCount(
131 static HRESULT WINAPI
xmlnode_GetTypeInfo(
135 ITypeInfo
** ppTInfo
)
141 static HRESULT WINAPI
xmlnode_GetIDsOfNames(
153 static HRESULT WINAPI
xmlnode_Invoke(
159 DISPPARAMS
* pDispParams
,
161 EXCEPINFO
* pExcepInfo
,
168 static HRESULT WINAPI
xmlnode_get_nodeName(
172 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
175 TRACE("%p\n", This
);
183 switch( This
->node
->type
)
185 case XML_CDATA_SECTION_NODE
:
186 str
= (const xmlChar
*) "#cdata-section";
188 case XML_COMMENT_NODE
:
189 str
= (const xmlChar
*) "#comment";
191 case XML_DOCUMENT_FRAG_NODE
:
192 str
= (const xmlChar
*) "#document-fragment";
195 str
= (const xmlChar
*) "#text";
197 case XML_DOCUMENT_NODE
:
198 str
= (const xmlChar
*) "#document";
200 case XML_ATTRIBUTE_NODE
:
201 case XML_ELEMENT_NODE
:
203 str
= This
->node
->name
;
206 FIXME("nodeName not mapped correctly (%d)\n", This
->node
->type
);
207 str
= This
->node
->name
;
211 *name
= bstr_from_xmlChar( str
);
218 BSTR
bstr_from_xmlChar( const xmlChar
*buf
)
227 len
= MultiByteToWideChar( CP_UTF8
, 0, (LPCSTR
) buf
, -1, NULL
, 0 );
228 str
= (LPWSTR
) HeapAlloc( GetProcessHeap(), 0, len
* sizeof (WCHAR
) );
231 MultiByteToWideChar( CP_UTF8
, 0, (LPCSTR
) buf
, -1, str
, len
);
232 bstr
= SysAllocString( str
);
233 HeapFree( GetProcessHeap(), 0, str
);
237 static HRESULT WINAPI
xmlnode_get_nodeValue(
241 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
244 TRACE("%p %p\n", This
, value
);
249 V_BSTR(value
) = NULL
;
250 V_VT(value
) = VT_NULL
;
252 switch ( This
->node
->type
)
254 case XML_CDATA_SECTION_NODE
:
255 case XML_COMMENT_NODE
:
257 case XML_ATTRIBUTE_NODE
:
259 xmlChar
*content
= xmlNodeGetContent(This
->node
);
260 V_VT(value
) = VT_BSTR
;
261 V_BSTR(value
) = bstr_from_xmlChar( content
);
267 V_VT(value
) = VT_BSTR
;
268 V_BSTR(value
) = bstr_from_xmlChar( This
->node
->content
);
271 case XML_ELEMENT_NODE
:
272 case XML_DOCUMENT_NODE
:
273 /* these seem to return NULL */
277 FIXME("node %p type %d\n", This
, This
->node
->type
);
280 TRACE("%p returned %s\n", This
, debugstr_w( V_BSTR(value
) ) );
285 static HRESULT WINAPI
xmlnode_put_nodeValue(
289 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
290 HRESULT hr
= S_FALSE
;
293 TRACE("%p type(%d)\n", This
, This
->node
->type
);
295 /* Document, Document Fragment, Document Type, Element,
296 Entity, Entity Reference, Notation arent supported. */
297 switch ( This
->node
->type
)
299 case XML_ATTRIBUTE_NODE
:
300 case XML_CDATA_SECTION_NODE
:
301 case XML_COMMENT_NODE
:
305 str
= xmlChar_from_wchar((WCHAR
*)V_BSTR(&value
));
307 xmlNodeSetContent(This
->node
, str
);
312 /* Do nothing for unsupported types. */
319 static HRESULT WINAPI
xmlnode_get_nodeType(
323 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
325 TRACE("%p %p\n", This
, type
);
327 assert( NODE_ELEMENT
== XML_ELEMENT_NODE
);
328 assert( NODE_NOTATION
== XML_NOTATION_NODE
);
330 *type
= This
->node
->type
;
335 static HRESULT
get_node(
341 TRACE("%p->%s %p\n", This
, name
, node
);
345 *out
= create_node( node
);
351 static HRESULT WINAPI
xmlnode_get_parentNode(
353 IXMLDOMNode
** parent
)
355 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
356 return get_node( This
, "parent", This
->node
->parent
, parent
);
359 static HRESULT WINAPI
xmlnode_get_childNodes(
361 IXMLDOMNodeList
** childList
)
363 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
365 TRACE("%p %p\n", This
, childList
);
370 *childList
= create_children_nodelist(This
->node
);
371 if (*childList
== NULL
)
372 return E_OUTOFMEMORY
;
377 static HRESULT WINAPI
xmlnode_get_firstChild(
379 IXMLDOMNode
** firstChild
)
381 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
382 return get_node( This
, "firstChild", This
->node
->children
, firstChild
);
385 static HRESULT WINAPI
xmlnode_get_lastChild(
387 IXMLDOMNode
** lastChild
)
389 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
391 TRACE("%p\n", This
);
396 switch( This
->node
->type
)
398 /* CDATASection, Comment, PI and Text Nodes do not support lastChild */
400 case XML_CDATA_SECTION_NODE
:
402 case XML_COMMENT_NODE
:
406 return get_node( This
, "lastChild", This
->node
->last
, lastChild
);
410 static HRESULT WINAPI
xmlnode_get_previousSibling(
412 IXMLDOMNode
** previousSibling
)
414 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
416 TRACE("%p\n", This
);
418 if (!previousSibling
)
421 switch( This
->node
->type
)
423 /* Attribute, Document and Document Fragment Nodes do not support previousSibling */
424 case XML_DOCUMENT_NODE
:
425 case XML_DOCUMENT_FRAG_NODE
:
426 case XML_ATTRIBUTE_NODE
:
427 *previousSibling
= NULL
;
430 return get_node( This
, "previous", This
->node
->prev
, previousSibling
);
434 static HRESULT WINAPI
xmlnode_get_nextSibling(
436 IXMLDOMNode
** nextSibling
)
438 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
440 TRACE("%p\n", This
);
445 switch( This
->node
->type
)
447 /* Attribute, Document and Document Fragment Nodes do not support nextSibling */
448 case XML_DOCUMENT_NODE
:
449 case XML_DOCUMENT_FRAG_NODE
:
450 case XML_ATTRIBUTE_NODE
:
454 return get_node( This
, "next", This
->node
->next
, nextSibling
);
458 static HRESULT WINAPI
xmlnode_get_attributes(
460 IXMLDOMNamedNodeMap
** attributeMap
)
462 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
468 switch( This
->node
->type
)
470 /* Attribute, CDataSection, Comment, Documents, Documents Fragments,
471 Entity and Text Nodes does not support get_attributes */
472 case XML_ATTRIBUTE_NODE
:
473 case XML_CDATA_SECTION_NODE
:
474 case XML_COMMENT_NODE
:
475 case XML_DOCUMENT_NODE
:
476 case XML_DOCUMENT_FRAG_NODE
:
477 case XML_ENTITY_NODE
:
478 case XML_ENTITY_REF_NODE
:
480 *attributeMap
= NULL
;
483 *attributeMap
= create_nodemap( iface
);
488 static HRESULT WINAPI
xmlnode_insertBefore(
490 IXMLDOMNode
* newChild
,
492 IXMLDOMNode
** outNewChild
)
494 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
495 xmlNodePtr before_node
, new_child_node
;
496 IXMLDOMNode
*before
= NULL
, *new;
499 TRACE("(%p)->(%p,var,%p)\n",This
,newChild
,outNewChild
);
504 switch(V_VT(&refChild
))
511 hr
= IUnknown_QueryInterface(V_UNKNOWN(&refChild
), &IID_IXMLDOMNode
, (LPVOID
)&before
);
512 if(FAILED(hr
)) return hr
;
516 hr
= IDispatch_QueryInterface(V_DISPATCH(&refChild
), &IID_IXMLDOMNode
, (LPVOID
)&before
);
517 if(FAILED(hr
)) return hr
;
521 FIXME("refChild var type %x\n", V_VT(&refChild
));
525 IXMLDOMNode_QueryInterface(newChild
, &IID_IXMLDOMNode
, (LPVOID
)&new);
526 new_child_node
= impl_from_IXMLDOMNode(new)->node
;
527 TRACE("new_child_node %p This->node %p\n", new_child_node
, This
->node
);
531 before_node
= impl_from_IXMLDOMNode(before
)->node
;
532 xmlAddPrevSibling(before_node
, new_child_node
);
533 IXMLDOMNode_Release(before
);
537 xmlAddChild(This
->node
, new_child_node
);
540 IXMLDOMNode_Release(new);
541 IXMLDOMNode_AddRef(newChild
);
543 *outNewChild
= newChild
;
549 static HRESULT WINAPI
xmlnode_replaceChild(
551 IXMLDOMNode
* newChild
,
552 IXMLDOMNode
* oldChild
,
553 IXMLDOMNode
** outOldChild
)
559 static HRESULT WINAPI
xmlnode_removeChild(
561 IXMLDOMNode
* childNode
,
562 IXMLDOMNode
** oldChild
)
564 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
565 xmlNode
*ancestor
, *child_node_ptr
;
569 TRACE("%p->(%p, %p)\n", This
, childNode
, oldChild
);
573 if(!childNode
) return E_INVALIDARG
;
575 hr
= IXMLDOMNode_QueryInterface(childNode
, &IID_IXMLDOMNode
, (LPVOID
)&child
);
579 child_node_ptr
= ancestor
= impl_from_IXMLDOMNode(child
)->node
;
580 while(ancestor
->parent
)
582 if(ancestor
->parent
== This
->node
)
584 ancestor
= ancestor
->parent
;
586 if(!ancestor
->parent
)
588 WARN("childNode %p is not a child of %p\n", childNode
, iface
);
589 IXMLDOMNode_Release(child
);
593 xmlUnlinkNode(child_node_ptr
);
595 IXMLDOMNode_Release(child
);
596 IXMLDOMNode_AddRef(childNode
);
597 *oldChild
= childNode
;
601 static HRESULT WINAPI
xmlnode_appendChild(
603 IXMLDOMNode
* newChild
,
604 IXMLDOMNode
** outNewChild
)
606 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
607 IXMLDOMNode
*pAttr
= NULL
;
610 TRACE("(%p)->(%p,%p)\n", This
, newChild
, outNewChild
);
612 /* Cannot Append an Attribute node. */
613 IUnknown_QueryInterface(newChild
, &IID_IXMLDOMNode
, (LPVOID
*)&pAttr
);
616 xmlnode
*ThisNew
= impl_from_IXMLDOMNode( pAttr
);
618 if(ThisNew
->node
->type
== XML_ATTRIBUTE_NODE
)
620 if(outNewChild
) *outNewChild
= NULL
;
622 IUnknown_Release(pAttr
);
627 IUnknown_Release(pAttr
);
631 return IXMLDOMNode_insertBefore(iface
, newChild
, var
, outNewChild
);
634 static HRESULT WINAPI
xmlnode_hasChildNodes(
636 VARIANT_BOOL
* hasChild
)
638 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
644 if (!This
->node
->children
)
646 *hasChild
= VARIANT_FALSE
;
650 *hasChild
= VARIANT_TRUE
;
654 static HRESULT WINAPI
xmlnode_get_ownerDocument(
656 IXMLDOMDocument
** DOMDocument
)
662 static HRESULT WINAPI
xmlnode_cloneNode(
665 IXMLDOMNode
** cloneRoot
)
667 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
668 xmlNodePtr pClone
= NULL
;
669 IXMLDOMNode
*pNode
= NULL
;
671 TRACE("%p (%d)\n", This
, deep
);
676 pClone
= xmlCopyNode(This
->node
, deep
? 1 : 2);
679 pClone
->doc
= This
->node
->doc
;
681 pNode
= create_node(pClone
);
684 ERR("Copy failed\n");
692 ERR("Copy failed\n");
699 static HRESULT WINAPI
xmlnode_get_nodeTypeString(
703 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
706 TRACE("%p\n", This
);
714 switch( This
->node
->type
)
716 case XML_ATTRIBUTE_NODE
:
717 str
= (const xmlChar
*) "attribute";
719 case XML_CDATA_SECTION_NODE
:
720 str
= (const xmlChar
*) "cdatasection";
722 case XML_COMMENT_NODE
:
723 str
= (const xmlChar
*) "comment";
725 case XML_DOCUMENT_NODE
:
726 str
= (const xmlChar
*) "document";
728 case XML_DOCUMENT_FRAG_NODE
:
729 str
= (const xmlChar
*) "documentfragment";
731 case XML_ELEMENT_NODE
:
732 str
= (const xmlChar
*) "element";
734 case XML_ENTITY_NODE
:
735 str
= (const xmlChar
*) "entity";
737 case XML_ENTITY_REF_NODE
:
738 str
= (const xmlChar
*) "entityreference";
740 case XML_NOTATION_NODE
:
741 str
= (const xmlChar
*) "notation";
744 str
= (const xmlChar
*) "processinginstruction";
747 str
= (const xmlChar
*) "text";
750 FIXME("nodeName not mapped correctly (%d)\n", This
->node
->type
);
751 str
= This
->node
->name
;
755 *xmlnodeType
= bstr_from_xmlChar( str
);
762 static HRESULT WINAPI
xmlnode_get_text(
766 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
774 switch(This
->node
->type
)
776 case XML_ELEMENT_NODE
:
777 case XML_ATTRIBUTE_NODE
:
779 xmlNodePtr child
= This
->node
->children
;
780 if ( child
&& child
->type
== XML_TEXT_NODE
)
781 str
= bstr_from_xmlChar( child
->content
);
786 case XML_CDATA_SECTION_NODE
:
788 case XML_COMMENT_NODE
:
789 str
= bstr_from_xmlChar( This
->node
->content
);
793 FIXME("Unhandled node type %d\n", This
->node
->type
);
796 /* Always return a string. */
797 if (!str
) str
= SysAllocStringLen( NULL
, 0 );
799 TRACE("%p %s\n", This
, debugstr_w(str
) );
805 static HRESULT WINAPI
xmlnode_put_text(
809 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
814 switch(This
->node
->type
)
816 case XML_DOCUMENT_NODE
:
822 str
= xmlChar_from_wchar((WCHAR
*)text
);
824 /* Escape the string. */
825 str
= xmlEncodeEntitiesReentrant(This
->node
->doc
, str
);
826 str
= xmlEncodeSpecialChars(This
->node
->doc
, str
);
828 xmlNodeSetContent(This
->node
, str
);
834 static HRESULT WINAPI
xmlnode_get_specified(
836 VARIANT_BOOL
* isSpecified
)
842 static HRESULT WINAPI
xmlnode_get_definition(
844 IXMLDOMNode
** definitionNode
)
850 static HRESULT WINAPI
xmlnode_get_nodeTypedValue(
854 FIXME("ignoring data type\n");
855 return xmlnode_get_nodeValue(iface
, typedValue
);
858 static HRESULT WINAPI
xmlnode_put_nodeTypedValue(
866 static HRESULT WINAPI
xmlnode_get_dataType(
868 VARIANT
* dataTypeName
)
870 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
873 TRACE("iface %p\n", iface
);
878 /* Attribute, CDATA Section, Comment, Document, Document Fragment,
879 Entity, Notation, PI, and Text Node are non-typed. */
880 V_BSTR(dataTypeName
) = NULL
;
881 V_VT(dataTypeName
) = VT_NULL
;
883 switch ( This
->node
->type
)
885 case XML_ELEMENT_NODE
:
886 pVal
= xmlGetNsProp(This
->node
, (xmlChar
*)"dt",
887 (xmlChar
*)"urn:schemas-microsoft-com:datatypes");
890 V_VT(dataTypeName
) = VT_BSTR
;
891 V_BSTR(dataTypeName
) = bstr_from_xmlChar( pVal
);
895 case XML_ENTITY_REF_NODE
:
896 FIXME("XML_ENTITY_REF_NODE should return a valid value.\n");
899 TRACE("Type %d returning NULL\n", This
->node
->type
);
902 /* non-typed nodes return S_FALSE */
903 if(V_VT(dataTypeName
) == VT_NULL
)
911 static HRESULT WINAPI
xmlnode_put_dataType(
915 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
918 TRACE("iface %p\n", iface
);
920 if(dataTypeName
== NULL
)
923 /* An example of this is. The Text in the node needs to be a 0 or 1 for a boolean type.
924 This applies to changing types (string->bool) or setting a new one
926 FIXME("Need to Validate the data before allowing a type to be set.\n");
928 /* Check all supported types. */
929 if(lstrcmpiW(dataTypeName
,szString
) == 0 ||
930 lstrcmpiW(dataTypeName
,szNumber
) == 0 ||
931 lstrcmpiW(dataTypeName
,szUUID
) == 0 ||
932 lstrcmpiW(dataTypeName
,szInt
) == 0 ||
933 lstrcmpiW(dataTypeName
,szI4
) == 0 ||
934 lstrcmpiW(dataTypeName
,szFixed
) == 0 ||
935 lstrcmpiW(dataTypeName
,szBoolean
) == 0 ||
936 lstrcmpiW(dataTypeName
,szDateTime
) == 0 ||
937 lstrcmpiW(dataTypeName
,szDateTimeTZ
) == 0 ||
938 lstrcmpiW(dataTypeName
,szDate
) == 0 ||
939 lstrcmpiW(dataTypeName
,szTime
) == 0 ||
940 lstrcmpiW(dataTypeName
,szTimeTZ
) == 0 ||
941 lstrcmpiW(dataTypeName
,szI1
) == 0 ||
942 lstrcmpiW(dataTypeName
,szI2
) == 0 ||
943 lstrcmpiW(dataTypeName
,szIU1
) == 0 ||
944 lstrcmpiW(dataTypeName
,szIU2
) == 0 ||
945 lstrcmpiW(dataTypeName
,szIU4
) == 0 ||
946 lstrcmpiW(dataTypeName
,szR4
) == 0 ||
947 lstrcmpiW(dataTypeName
,szR8
) == 0 ||
948 lstrcmpiW(dataTypeName
,szFloat
) == 0 ||
949 lstrcmpiW(dataTypeName
,szBinHex
) == 0 ||
950 lstrcmpiW(dataTypeName
,szBinBase64
) == 0)
953 xmlAttrPtr pAttr
= NULL
;
954 xmlChar
* str
= xmlChar_from_wchar((WCHAR
*)dataTypeName
);
956 pAttr
= xmlHasNsProp(This
->node
, (xmlChar
*)"dt",
957 (xmlChar
*)"urn:schemas-microsoft-com:datatypes");
960 pAttr
= xmlSetNsProp(This
->node
, pAttr
->ns
, (xmlChar
*)"dt", str
);
966 pNS
= xmlNewNs(This
->node
, (xmlChar
*)"urn:schemas-microsoft-com:datatypes", (xmlChar
*)"dt");
969 pAttr
= xmlNewNsProp(This
->node
, pNS
, (xmlChar
*)"dt", str
);
972 xmlAddChild(This
->node
, (xmlNodePtr
)pAttr
);
977 ERR("Failed to create Attribute\n");
980 ERR("Failed to Create Namepsace\n");
987 static HRESULT WINAPI
xmlnode_get_xml(
991 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
992 xmlBufferPtr pXmlBuf
;
995 TRACE("iface %p\n", iface
);
1002 pXmlBuf
= xmlBufferCreate();
1005 nSize
= xmlNodeDump(pXmlBuf
, This
->node
->doc
, This
->node
, 0, 0);
1008 const xmlChar
*pContent
;
1010 /* Attribute Nodes return a space infront of their name */
1011 pContent
= xmlBufferContent(pXmlBuf
);
1012 if( ((char*)pContent
)[0] == ' ')
1013 *xmlString
= bstr_from_xmlChar(pContent
+1);
1015 *xmlString
= bstr_from_xmlChar(pContent
);
1018 xmlBufferFree(pXmlBuf
);
1022 /* Always returns a string. */
1023 if(*xmlString
== NULL
) *xmlString
= SysAllocStringLen( NULL
, 0 );
1028 static HRESULT WINAPI
xmlnode_transformNode(
1030 IXMLDOMNode
* styleSheet
,
1037 static HRESULT WINAPI
xmlnode_selectNodes(
1040 IXMLDOMNodeList
** resultList
)
1042 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
1044 TRACE("%p %s %p\n", This
, debugstr_w(queryString
), resultList
);
1046 return queryresult_create( This
->node
, queryString
, resultList
);
1049 static HRESULT WINAPI
xmlnode_selectSingleNode(
1052 IXMLDOMNode
** resultNode
)
1054 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
1055 IXMLDOMNodeList
*list
;
1058 TRACE("%p %s %p\n", This
, debugstr_w(queryString
), resultNode
);
1061 r
= IXMLDOMNode_selectNodes(iface
, queryString
, &list
);
1064 r
= IXMLDOMNodeList_nextNode(list
, resultNode
);
1065 IXMLDOMNodeList_Release(list
);
1070 static HRESULT WINAPI
xmlnode_get_parsed(
1072 VARIANT_BOOL
* isParsed
)
1078 static HRESULT WINAPI
xmlnode_get_namespaceURI(
1086 static HRESULT WINAPI
xmlnode_get_prefix(
1094 static HRESULT WINAPI
xmlnode_get_baseName(
1098 xmlnode
*This
= impl_from_IXMLDOMNode( iface
);
1100 HRESULT r
= S_FALSE
;
1102 TRACE("%p %p\n", This
, nameString
);
1105 return E_INVALIDARG
;
1107 switch ( This
->node
->type
)
1109 case XML_ELEMENT_NODE
:
1110 case XML_ATTRIBUTE_NODE
:
1111 str
= bstr_from_xmlChar( This
->node
->name
);
1117 ERR("Unhandled type %d\n", This
->node
->type
);
1121 TRACE("returning %08x str = %s\n", r
, debugstr_w( str
) );
1127 static HRESULT WINAPI
xmlnode_transformNodeToObject(
1129 IXMLDOMNode
* stylesheet
,
1130 VARIANT outputObject
)
1136 static const struct IXMLDOMNodeVtbl xmlnode_vtbl
=
1138 xmlnode_QueryInterface
,
1141 xmlnode_GetTypeInfoCount
,
1142 xmlnode_GetTypeInfo
,
1143 xmlnode_GetIDsOfNames
,
1145 xmlnode_get_nodeName
,
1146 xmlnode_get_nodeValue
,
1147 xmlnode_put_nodeValue
,
1148 xmlnode_get_nodeType
,
1149 xmlnode_get_parentNode
,
1150 xmlnode_get_childNodes
,
1151 xmlnode_get_firstChild
,
1152 xmlnode_get_lastChild
,
1153 xmlnode_get_previousSibling
,
1154 xmlnode_get_nextSibling
,
1155 xmlnode_get_attributes
,
1156 xmlnode_insertBefore
,
1157 xmlnode_replaceChild
,
1158 xmlnode_removeChild
,
1159 xmlnode_appendChild
,
1160 xmlnode_hasChildNodes
,
1161 xmlnode_get_ownerDocument
,
1163 xmlnode_get_nodeTypeString
,
1166 xmlnode_get_specified
,
1167 xmlnode_get_definition
,
1168 xmlnode_get_nodeTypedValue
,
1169 xmlnode_put_nodeTypedValue
,
1170 xmlnode_get_dataType
,
1171 xmlnode_put_dataType
,
1173 xmlnode_transformNode
,
1174 xmlnode_selectNodes
,
1175 xmlnode_selectSingleNode
,
1177 xmlnode_get_namespaceURI
,
1179 xmlnode_get_baseName
,
1180 xmlnode_transformNodeToObject
,
1183 static HRESULT WINAPI
Internal_QueryInterface(
1188 xmlnode
*This
= impl_from_InternalUnknown( iface
);
1190 TRACE("%p %s %p\n", iface
, debugstr_guid(riid
), ppvObject
);
1193 if ( IsEqualGUID( riid
, &IID_IUnknown
))
1195 else if ( IsEqualGUID( riid
, &IID_IDispatch
) ||
1196 IsEqualGUID( riid
, &IID_IXMLDOMNode
) )
1197 *ppvObject
= &This
->lpVtbl
;
1200 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
1202 return E_NOINTERFACE
;
1205 IUnknown_AddRef( (IUnknown
*)*ppvObject
);
1210 static ULONG WINAPI
Internal_AddRef(
1213 xmlnode
*This
= impl_from_InternalUnknown( iface
);
1214 return InterlockedIncrement( &This
->ref
);
1217 static ULONG WINAPI
Internal_Release(
1220 xmlnode
*This
= impl_from_InternalUnknown( iface
);
1223 ref
= InterlockedDecrement( &This
->ref
);
1227 xmldoc_release( This
->node
->doc
);
1228 HeapFree( GetProcessHeap(), 0, This
);
1234 static const struct IUnknownVtbl internal_unk_vtbl
=
1236 Internal_QueryInterface
,
1241 IUnknown
*create_basic_node( xmlNodePtr node
, IUnknown
*pUnkOuter
)
1245 This
= HeapAlloc( GetProcessHeap(), 0, sizeof *This
);
1250 xmldoc_add_ref( node
->doc
);
1252 This
->lpVtbl
= &xmlnode_vtbl
;
1253 This
->lpInternalUnkVtbl
= &internal_unk_vtbl
;
1256 This
->pUnkOuter
= pUnkOuter
; /* Don't take a ref on outer Unknown */
1258 This
->pUnkOuter
= (IUnknown
*)&This
->lpInternalUnkVtbl
;
1263 return (IUnknown
*)&This
->lpInternalUnkVtbl
;
1266 IXMLDOMNode
*create_node( xmlNodePtr node
)
1275 TRACE("type %d\n", node
->type
);
1278 case XML_ELEMENT_NODE
:
1279 pUnk
= create_element( node
, NULL
);
1281 case XML_ATTRIBUTE_NODE
:
1282 pUnk
= create_attribute( node
);
1285 pUnk
= create_text( node
);
1287 case XML_COMMENT_NODE
:
1288 pUnk
= create_comment( node
);
1290 case XML_DOCUMENT_NODE
:
1291 ERR("shouldn't be here!\n");
1294 FIXME("only creating basic node for type %d\n", node
->type
);
1295 pUnk
= create_basic_node( node
, NULL
);
1298 hr
= IUnknown_QueryInterface(pUnk
, &IID_IXMLDOMNode
, (LPVOID
*)&ret
);
1299 IUnknown_Release(pUnk
);
1300 if(FAILED(hr
)) return NULL
;