2 * SAX Reader implementation
4 * Copyright 2008 Alistair Leslie-Hughes
5 * Copyright 2008 Piotr Caban
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 # include <libxml/parser.h>
28 # include <libxml/xmlerror.h>
29 # include <libxml/SAX2.h>
30 # include <libxml/parserInternals.h>
44 #include "wine/debug.h"
46 #include "msxml_private.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
52 typedef struct _saxreader
54 IVBSAXXMLReader IVBSAXXMLReader_iface;
55 ISAXXMLReader ISAXXMLReader_iface;
57 struct ISAXContentHandler *contentHandler;
58 struct IVBSAXContentHandler *vbcontentHandler;
59 struct ISAXErrorHandler *errorHandler;
60 struct IVBSAXErrorHandler *vberrorHandler;
61 struct ISAXLexicalHandler *lexicalHandler;
62 struct IVBSAXLexicalHandler *vblexicalHandler;
63 struct ISAXDeclHandler *declHandler;
64 struct IVBSAXDeclHandler *vbdeclHandler;
69 typedef struct _saxlocator
71 IVBSAXLocator IVBSAXLocator_iface;
72 ISAXLocator ISAXLocator_iface;
76 xmlParserCtxtPtr pParserCtxt;
90 typedef struct _saxattributes
92 IVBSAXAttributes IVBSAXAttributes_iface;
93 ISAXAttributes ISAXAttributes_iface;
102 static inline saxreader *impl_from_IVBSAXXMLReader( IVBSAXXMLReader *iface )
104 return CONTAINING_RECORD(iface, saxreader, IVBSAXXMLReader_iface);
107 static inline saxreader *impl_from_ISAXXMLReader( ISAXXMLReader *iface )
109 return CONTAINING_RECORD(iface, saxreader, ISAXXMLReader_iface);
112 static inline saxlocator *impl_from_IVBSAXLocator( IVBSAXLocator *iface )
114 return CONTAINING_RECORD(iface, saxlocator, IVBSAXLocator_iface);
117 static inline saxlocator *impl_from_ISAXLocator( ISAXLocator *iface )
119 return CONTAINING_RECORD(iface, saxlocator, ISAXLocator_iface);
122 static inline saxattributes *impl_from_IVBSAXAttributes( IVBSAXAttributes *iface )
124 return CONTAINING_RECORD(iface, saxattributes, IVBSAXAttributes_iface);
127 static inline saxattributes *impl_from_ISAXAttributes( ISAXAttributes *iface )
129 return CONTAINING_RECORD(iface, saxattributes, ISAXAttributes_iface);
132 static inline BOOL has_content_handler(const saxlocator *locator)
134 return (locator->vbInterface && locator->saxreader->vbcontentHandler) ||
135 (!locator->vbInterface && locator->saxreader->contentHandler);
138 static inline BOOL has_error_handler(const saxlocator *locator)
140 return (locator->vbInterface && locator->saxreader->vberrorHandler) ||
141 (!locator->vbInterface && locator->saxreader->errorHandler);
144 static HRESULT namespacePush(saxlocator *locator, int ns)
146 if(locator->nsStackLast>=locator->nsStackSize)
150 new_stack = HeapReAlloc(GetProcessHeap(), 0,
151 locator->nsStack, sizeof(int)*locator->nsStackSize*2);
152 if(!new_stack) return E_OUTOFMEMORY;
153 locator->nsStack = new_stack;
154 locator->nsStackSize *= 2;
156 locator->nsStack[locator->nsStackLast++] = ns;
161 static int namespacePop(saxlocator *locator)
163 if(locator->nsStackLast == 0) return 0;
164 return locator->nsStack[--locator->nsStackLast];
167 static BSTR bstr_from_xmlCharN(const xmlChar *buf, int len)
175 dLen = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)buf, len, NULL, 0);
176 if(len != -1) dLen++;
177 bstr = SysAllocStringLen(NULL, dLen-1);
180 MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)buf, len, bstr, dLen);
181 if(len != -1) bstr[dLen-1] = '\0';
186 static BSTR QName_from_xmlChar(const xmlChar *prefix, const xmlChar *name)
191 if(!name) return NULL;
193 if(!prefix || !*prefix)
194 return bstr_from_xmlChar(name);
196 qname = xmlBuildQName(name, prefix, NULL, 0);
197 bstr = bstr_from_xmlChar(qname);
203 static void format_error_message_from_id(saxlocator *This, HRESULT hr)
205 xmlStopParser(This->pParserCtxt);
208 if(has_error_handler(This))
211 if(!FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM,
212 NULL, hr, 0, msg, sizeof(msg), NULL))
214 FIXME("MSXML errors not yet supported.\n");
218 if(This->vbInterface)
220 BSTR bstrMsg = SysAllocString(msg);
221 IVBSAXErrorHandler_fatalError(This->saxreader->vberrorHandler,
222 &This->IVBSAXLocator_iface, &bstrMsg, hr);
223 SysFreeString(bstrMsg);
226 ISAXErrorHandler_fatalError(This->saxreader->errorHandler,
227 &This->ISAXLocator_iface, msg, hr);
231 static void update_position(saxlocator *This, xmlChar *end)
233 if(This->lastCur == NULL)
235 This->lastCur = (xmlChar*)This->pParserCtxt->input->base;
237 This->realColumn = 1;
239 else if(This->lastCur < This->pParserCtxt->input->base)
241 This->lastCur = (xmlChar*)This->pParserCtxt->input->base;
243 This->realColumn = 1;
246 if(This->pParserCtxt->input->cur<This->lastCur)
248 This->lastCur = (xmlChar*)This->pParserCtxt->input->base;
250 This->realColumn = 1;
253 if(!end) end = (xmlChar*)This->pParserCtxt->input->cur;
255 while(This->lastCur < end)
257 if(*(This->lastCur) == '\n')
260 This->realColumn = 1;
262 else if(*(This->lastCur) == '\r' &&
263 (This->lastCur==This->pParserCtxt->input->end ||
264 *(This->lastCur+1)!='\n'))
267 This->realColumn = 1;
269 else This->realColumn++;
273 /* Count multibyte UTF8 encoded characters once */
274 while((*(This->lastCur)&0xC0) == 0x80) This->lastCur++;
277 This->line = This->realLine;
278 This->column = This->realColumn;
281 /*** IVBSAXAttributes interface ***/
282 /*** IUnknown methods ***/
283 static HRESULT WINAPI ivbsaxattributes_QueryInterface(
284 IVBSAXAttributes* iface,
288 saxattributes *This = impl_from_IVBSAXAttributes(iface);
290 TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
294 if (IsEqualGUID(riid, &IID_IUnknown) ||
295 IsEqualGUID(riid, &IID_IDispatch) ||
296 IsEqualGUID(riid, &IID_IVBSAXAttributes))
302 FIXME("interface %s not implemented\n", debugstr_guid(riid));
303 return E_NOINTERFACE;
306 IVBSAXAttributes_AddRef(iface);
311 static ULONG WINAPI ivbsaxattributes_AddRef(IVBSAXAttributes* iface)
313 saxattributes *This = impl_from_IVBSAXAttributes(iface);
314 return ISAXAttributes_AddRef(&This->ISAXAttributes_iface);
317 static ULONG WINAPI ivbsaxattributes_Release(IVBSAXAttributes* iface)
319 saxattributes *This = impl_from_IVBSAXAttributes(iface);
320 return ISAXAttributes_Release(&This->ISAXAttributes_iface);
323 /*** IDispatch methods ***/
324 static HRESULT WINAPI ivbsaxattributes_GetTypeInfoCount( IVBSAXAttributes *iface, UINT* pctinfo )
326 saxattributes *This = impl_from_IVBSAXAttributes( iface );
328 TRACE("(%p)->(%p)\n", This, pctinfo);
335 static HRESULT WINAPI ivbsaxattributes_GetTypeInfo(
336 IVBSAXAttributes *iface,
337 UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo )
339 saxattributes *This = impl_from_IVBSAXAttributes( iface );
342 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
344 hr = get_typeinfo(IVBSAXAttributes_tid, ppTInfo);
349 static HRESULT WINAPI ivbsaxattributes_GetIDsOfNames(
350 IVBSAXAttributes *iface,
357 saxattributes *This = impl_from_IVBSAXAttributes( iface );
361 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
364 if(!rgszNames || cNames == 0 || !rgDispId)
367 hr = get_typeinfo(IVBSAXAttributes_tid, &typeinfo);
370 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
371 ITypeInfo_Release(typeinfo);
377 static HRESULT WINAPI ivbsaxattributes_Invoke(
378 IVBSAXAttributes *iface,
383 DISPPARAMS* pDispParams,
385 EXCEPINFO* pExcepInfo,
388 saxattributes *This = impl_from_IVBSAXAttributes( iface );
392 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
393 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
395 hr = get_typeinfo(IVBSAXAttributes_tid, &typeinfo);
398 hr = ITypeInfo_Invoke(typeinfo, &This->IVBSAXAttributes_iface, dispIdMember, wFlags,
399 pDispParams, pVarResult, pExcepInfo, puArgErr);
400 ITypeInfo_Release(typeinfo);
406 /*** IVBSAXAttributes methods ***/
407 static HRESULT WINAPI ivbsaxattributes_get_length(
408 IVBSAXAttributes* iface,
411 saxattributes *This = impl_from_IVBSAXAttributes( iface );
412 return ISAXAttributes_getLength(&This->ISAXAttributes_iface, nLength);
415 static HRESULT WINAPI ivbsaxattributes_getURI(
416 IVBSAXAttributes* iface,
421 saxattributes *This = impl_from_IVBSAXAttributes( iface );
422 return ISAXAttributes_getURI(&This->ISAXAttributes_iface, nIndex, (const WCHAR**)uri, &len);
425 static HRESULT WINAPI ivbsaxattributes_getLocalName(
426 IVBSAXAttributes* iface,
431 saxattributes *This = impl_from_IVBSAXAttributes( iface );
432 return ISAXAttributes_getLocalName(&This->ISAXAttributes_iface, nIndex,
433 (const WCHAR**)localName, &len);
436 static HRESULT WINAPI ivbsaxattributes_getQName(
437 IVBSAXAttributes* iface,
442 saxattributes *This = impl_from_IVBSAXAttributes( iface );
443 return ISAXAttributes_getQName(&This->ISAXAttributes_iface, nIndex, (const WCHAR**)QName, &len);
446 static HRESULT WINAPI ivbsaxattributes_getIndexFromName(
447 IVBSAXAttributes* iface,
452 saxattributes *This = impl_from_IVBSAXAttributes( iface );
453 return ISAXAttributes_getIndexFromName(&This->ISAXAttributes_iface, uri, SysStringLen(uri),
454 localName, SysStringLen(localName), index);
457 static HRESULT WINAPI ivbsaxattributes_getIndexFromQName(
458 IVBSAXAttributes* iface,
462 saxattributes *This = impl_from_IVBSAXAttributes( iface );
463 return ISAXAttributes_getIndexFromQName(&This->ISAXAttributes_iface, QName,
464 SysStringLen(QName), index);
467 static HRESULT WINAPI ivbsaxattributes_getType(
468 IVBSAXAttributes* iface,
473 saxattributes *This = impl_from_IVBSAXAttributes( iface );
474 return ISAXAttributes_getType(&This->ISAXAttributes_iface, nIndex, (const WCHAR**)type, &len);
477 static HRESULT WINAPI ivbsaxattributes_getTypeFromName(
478 IVBSAXAttributes* iface,
484 saxattributes *This = impl_from_IVBSAXAttributes( iface );
485 return ISAXAttributes_getTypeFromName(&This->ISAXAttributes_iface, uri, SysStringLen(uri),
486 localName, SysStringLen(localName), (const WCHAR**)type, &len);
489 static HRESULT WINAPI ivbsaxattributes_getTypeFromQName(
490 IVBSAXAttributes* iface,
495 saxattributes *This = impl_from_IVBSAXAttributes( iface );
496 return ISAXAttributes_getTypeFromQName(&This->ISAXAttributes_iface, QName, SysStringLen(QName),
497 (const WCHAR**)type, &len);
500 static HRESULT WINAPI ivbsaxattributes_getValue(
501 IVBSAXAttributes* iface,
506 saxattributes *This = impl_from_IVBSAXAttributes( iface );
507 return ISAXAttributes_getValue(&This->ISAXAttributes_iface, nIndex, (const WCHAR**)value, &len);
510 static HRESULT WINAPI ivbsaxattributes_getValueFromName(
511 IVBSAXAttributes* iface,
517 saxattributes *This = impl_from_IVBSAXAttributes( iface );
518 return ISAXAttributes_getValueFromName(&This->ISAXAttributes_iface, uri, SysStringLen(uri),
519 localName, SysStringLen(localName), (const WCHAR**)value, &len);
522 static HRESULT WINAPI ivbsaxattributes_getValueFromQName(
523 IVBSAXAttributes* iface,
528 saxattributes *This = impl_from_IVBSAXAttributes( iface );
529 return ISAXAttributes_getValueFromQName(&This->ISAXAttributes_iface, QName,
530 SysStringLen(QName), (const WCHAR**)value, &len);
533 static const struct IVBSAXAttributesVtbl ivbsaxattributes_vtbl =
535 ivbsaxattributes_QueryInterface,
536 ivbsaxattributes_AddRef,
537 ivbsaxattributes_Release,
538 ivbsaxattributes_GetTypeInfoCount,
539 ivbsaxattributes_GetTypeInfo,
540 ivbsaxattributes_GetIDsOfNames,
541 ivbsaxattributes_Invoke,
542 ivbsaxattributes_get_length,
543 ivbsaxattributes_getURI,
544 ivbsaxattributes_getLocalName,
545 ivbsaxattributes_getQName,
546 ivbsaxattributes_getIndexFromName,
547 ivbsaxattributes_getIndexFromQName,
548 ivbsaxattributes_getType,
549 ivbsaxattributes_getTypeFromName,
550 ivbsaxattributes_getTypeFromQName,
551 ivbsaxattributes_getValue,
552 ivbsaxattributes_getValueFromName,
553 ivbsaxattributes_getValueFromQName
556 /*** ISAXAttributes interface ***/
557 /*** IUnknown methods ***/
558 static HRESULT WINAPI isaxattributes_QueryInterface(
559 ISAXAttributes* iface,
563 saxattributes *This = impl_from_ISAXAttributes(iface);
565 TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
569 if (IsEqualGUID(riid, &IID_IUnknown) ||
570 IsEqualGUID(riid, &IID_ISAXAttributes))
576 FIXME("interface %s not implemented\n", debugstr_guid(riid));
577 return E_NOINTERFACE;
580 ISAXAttributes_AddRef(iface);
585 static ULONG WINAPI isaxattributes_AddRef(ISAXAttributes* iface)
587 saxattributes *This = impl_from_ISAXAttributes(iface);
589 return InterlockedIncrement(&This->ref);
592 static ULONG WINAPI isaxattributes_Release(ISAXAttributes* iface)
594 saxattributes *This = impl_from_ISAXAttributes(iface);
599 ref = InterlockedDecrement(&This->ref);
603 for(index=0; index<This->nb_attributes; index++)
605 SysFreeString(This->szLocalname[index]);
606 SysFreeString(This->szURI[index]);
607 SysFreeString(This->szValue[index]);
608 SysFreeString(This->szQName[index]);
611 heap_free(This->szLocalname);
612 heap_free(This->szURI);
613 heap_free(This->szValue);
614 heap_free(This->szQName);
622 /*** ISAXAttributes methods ***/
623 static HRESULT WINAPI isaxattributes_getLength(
624 ISAXAttributes* iface,
627 saxattributes *This = impl_from_ISAXAttributes( iface );
629 *length = This->nb_attributes;
630 TRACE("Length set to %d\n", *length);
634 static HRESULT WINAPI isaxattributes_getURI(
635 ISAXAttributes* iface,
640 saxattributes *This = impl_from_ISAXAttributes( iface );
641 TRACE("(%p)->(%d)\n", This, nIndex);
643 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG;
644 if(!pUrl || !pUriSize) return E_POINTER;
646 *pUriSize = SysStringLen(This->szURI[nIndex]);
647 *pUrl = This->szURI[nIndex];
652 static HRESULT WINAPI isaxattributes_getLocalName(
653 ISAXAttributes* iface,
655 const WCHAR **pLocalName,
656 int *pLocalNameLength)
658 saxattributes *This = impl_from_ISAXAttributes( iface );
659 TRACE("(%p)->(%d)\n", This, nIndex);
661 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG;
662 if(!pLocalName || !pLocalNameLength) return E_POINTER;
664 *pLocalNameLength = SysStringLen(This->szLocalname[nIndex]);
665 *pLocalName = This->szLocalname[nIndex];
670 static HRESULT WINAPI isaxattributes_getQName(
671 ISAXAttributes* iface,
673 const WCHAR **pQName,
676 saxattributes *This = impl_from_ISAXAttributes( iface );
677 TRACE("(%p)->(%d)\n", This, nIndex);
679 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG;
680 if(!pQName || !pQNameLength) return E_POINTER;
682 *pQNameLength = SysStringLen(This->szQName[nIndex]);
683 *pQName = This->szQName[nIndex];
688 static HRESULT WINAPI isaxattributes_getName(
689 ISAXAttributes* iface,
693 const WCHAR **pLocalName,
695 const WCHAR **pQName,
698 saxattributes *This = impl_from_ISAXAttributes( iface );
699 TRACE("(%p)->(%d)\n", This, nIndex);
701 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG;
702 if(!pUri || !pUriLength || !pLocalName || !pLocalNameSize
703 || !pQName || !pQNameLength) return E_POINTER;
705 *pUriLength = SysStringLen(This->szURI[nIndex]);
706 *pUri = This->szURI[nIndex];
707 *pLocalNameSize = SysStringLen(This->szLocalname[nIndex]);
708 *pLocalName = This->szLocalname[nIndex];
709 *pQNameLength = SysStringLen(This->szQName[nIndex]);
710 *pQName = This->szQName[nIndex];
715 static HRESULT WINAPI isaxattributes_getIndexFromName(
716 ISAXAttributes* iface,
719 const WCHAR *pLocalName,
723 saxattributes *This = impl_from_ISAXAttributes( iface );
725 TRACE("(%p)->(%s, %d, %s, %d)\n", This, debugstr_w(pUri), cUriLength,
726 debugstr_w(pLocalName), cocalNameLength);
728 if(!pUri || !pLocalName || !index) return E_POINTER;
730 for(i=0; i<This->nb_attributes; i++)
732 if(cUriLength!=SysStringLen(This->szURI[i])
733 || cocalNameLength!=SysStringLen(This->szLocalname[i]))
735 if(cUriLength && memcmp(pUri, This->szURI[i],
736 sizeof(WCHAR)*cUriLength))
738 if(cocalNameLength && memcmp(pLocalName, This->szLocalname[i],
739 sizeof(WCHAR)*cocalNameLength))
749 static HRESULT WINAPI isaxattributes_getIndexFromQName(
750 ISAXAttributes* iface,
755 saxattributes *This = impl_from_ISAXAttributes( iface );
757 TRACE("(%p)->(%s, %d)\n", This, debugstr_w(pQName), nQNameLength);
759 if(!pQName || !index) return E_POINTER;
760 if(!nQNameLength) return E_INVALIDARG;
762 for(i=0; i<This->nb_attributes; i++)
764 if(nQNameLength!=SysStringLen(This->szQName[i])) continue;
765 if(memcmp(pQName, This->szQName, sizeof(WCHAR)*nQNameLength)) continue;
774 static HRESULT WINAPI isaxattributes_getType(
775 ISAXAttributes* iface,
780 saxattributes *This = impl_from_ISAXAttributes( iface );
782 FIXME("(%p)->(%d) stub\n", This, nIndex);
786 static HRESULT WINAPI isaxattributes_getTypeFromName(
787 ISAXAttributes* iface,
790 const WCHAR *pLocalName,
795 saxattributes *This = impl_from_ISAXAttributes( iface );
797 FIXME("(%p)->(%s, %d, %s, %d) stub\n", This, debugstr_w(pUri), nUri,
798 debugstr_w(pLocalName), nLocalName);
802 static HRESULT WINAPI isaxattributes_getTypeFromQName(
803 ISAXAttributes* iface,
809 saxattributes *This = impl_from_ISAXAttributes( iface );
811 FIXME("(%p)->(%s, %d) stub\n", This, debugstr_w(pQName), nQName);
815 static HRESULT WINAPI isaxattributes_getValue(
816 ISAXAttributes* iface,
818 const WCHAR **pValue,
821 saxattributes *This = impl_from_ISAXAttributes( iface );
822 TRACE("(%p)->(%d)\n", This, nIndex);
824 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG;
825 if(!pValue || !nValue) return E_POINTER;
827 *nValue = SysStringLen(This->szValue[nIndex]);
828 *pValue = This->szValue[nIndex];
833 static HRESULT WINAPI isaxattributes_getValueFromName(
834 ISAXAttributes* iface,
837 const WCHAR *pLocalName,
839 const WCHAR **pValue,
844 saxattributes *This = impl_from_ISAXAttributes( iface );
845 TRACE("(%p)->(%s, %d, %s, %d)\n", This, debugstr_w(pUri), nUri,
846 debugstr_w(pLocalName), nLocalName);
848 hr = ISAXAttributes_getIndexFromName(iface,
849 pUri, nUri, pLocalName, nLocalName, &index);
850 if(hr==S_OK) hr = ISAXAttributes_getValue(iface, index, pValue, nValue);
855 static HRESULT WINAPI isaxattributes_getValueFromQName(
856 ISAXAttributes* iface,
859 const WCHAR **pValue,
864 saxattributes *This = impl_from_ISAXAttributes( iface );
865 TRACE("(%p)->(%s, %d)\n", This, debugstr_w(pQName), nQName);
867 hr = ISAXAttributes_getIndexFromQName(iface, pQName, nQName, &index);
868 if(hr==S_OK) hr = ISAXAttributes_getValue(iface, index, pValue, nValue);
873 static const struct ISAXAttributesVtbl isaxattributes_vtbl =
875 isaxattributes_QueryInterface,
876 isaxattributes_AddRef,
877 isaxattributes_Release,
878 isaxattributes_getLength,
879 isaxattributes_getURI,
880 isaxattributes_getLocalName,
881 isaxattributes_getQName,
882 isaxattributes_getName,
883 isaxattributes_getIndexFromName,
884 isaxattributes_getIndexFromQName,
885 isaxattributes_getType,
886 isaxattributes_getTypeFromName,
887 isaxattributes_getTypeFromQName,
888 isaxattributes_getValue,
889 isaxattributes_getValueFromName,
890 isaxattributes_getValueFromQName
893 static HRESULT SAXAttributes_create(saxattributes **attr,
894 int nb_namespaces, const xmlChar **xmlNamespaces,
895 int nb_attributes, const xmlChar **xmlAttributes)
897 saxattributes *attributes;
899 static const xmlChar xmlns[] = "xmlns";
901 attributes = heap_alloc(sizeof(*attributes));
903 return E_OUTOFMEMORY;
905 attributes->IVBSAXAttributes_iface.lpVtbl = &ivbsaxattributes_vtbl;
906 attributes->ISAXAttributes_iface.lpVtbl = &isaxattributes_vtbl;
909 attributes->nb_attributes = nb_namespaces+nb_attributes;
911 attributes->szLocalname = heap_alloc(sizeof(BSTR)*attributes->nb_attributes);
912 attributes->szURI = heap_alloc(sizeof(BSTR)*attributes->nb_attributes);
913 attributes->szValue = heap_alloc(sizeof(BSTR)*attributes->nb_attributes);
914 attributes->szQName = heap_alloc(sizeof(BSTR)*attributes->nb_attributes);
916 if(!attributes->szLocalname || !attributes->szURI
917 || !attributes->szValue || !attributes->szQName)
919 heap_free(attributes->szLocalname);
920 heap_free(attributes->szURI);
921 heap_free(attributes->szValue);
922 heap_free(attributes->szQName);
923 heap_free(attributes);
927 for(index=0; index<nb_namespaces; index++)
929 attributes->szLocalname[index] = SysAllocStringLen(NULL, 0);
930 attributes->szURI[index] = SysAllocStringLen(NULL, 0);
931 attributes->szValue[index] = bstr_from_xmlChar(xmlNamespaces[2*index+1]);
932 attributes->szQName[index] = QName_from_xmlChar(xmlns, xmlNamespaces[2*index]);
935 for(index=0; index<nb_attributes; index++)
937 attributes->szLocalname[nb_namespaces+index] =
938 bstr_from_xmlChar(xmlAttributes[index*5]);
939 attributes->szURI[nb_namespaces+index] =
940 bstr_from_xmlChar(xmlAttributes[index*5+2]);
941 attributes->szValue[nb_namespaces+index] =
942 bstr_from_xmlCharN(xmlAttributes[index*5+3],
943 xmlAttributes[index*5+4]-xmlAttributes[index*5+3]);
944 attributes->szQName[nb_namespaces+index] =
945 QName_from_xmlChar(xmlAttributes[index*5+1], xmlAttributes[index*5]);
950 TRACE("returning %p\n", *attr);
955 /*** LibXML callbacks ***/
956 static void libxmlStartDocument(void *ctx)
958 saxlocator *This = ctx;
961 if(has_content_handler(This))
963 if(This->vbInterface)
964 hr = IVBSAXContentHandler_startDocument(This->saxreader->vbcontentHandler);
966 hr = ISAXContentHandler_startDocument(This->saxreader->contentHandler);
969 format_error_message_from_id(This, hr);
972 update_position(This, NULL);
975 static void libxmlEndDocument(void *ctx)
977 saxlocator *This = ctx;
983 if(This->ret != S_OK) return;
985 if(has_content_handler(This))
987 if(This->vbInterface)
988 hr = IVBSAXContentHandler_endDocument(This->saxreader->vbcontentHandler);
990 hr = ISAXContentHandler_endDocument(This->saxreader->contentHandler);
993 format_error_message_from_id(This, hr);
997 static void libxmlStartElementNS(
999 const xmlChar *localname,
1000 const xmlChar *prefix,
1003 const xmlChar **namespaces,
1006 const xmlChar **attributes)
1008 BSTR NamespaceUri, LocalName, QName, Prefix, Uri;
1009 saxlocator *This = ctx;
1011 saxattributes *attr;
1014 if(*(This->pParserCtxt->input->cur) == '/')
1015 update_position(This, (xmlChar*)This->pParserCtxt->input->cur+2);
1017 update_position(This, (xmlChar*)This->pParserCtxt->input->cur+1);
1019 hr = namespacePush(This, nb_namespaces);
1020 if(hr==S_OK && has_content_handler(This))
1022 for(index=0; index<nb_namespaces; index++)
1024 Prefix = bstr_from_xmlChar(namespaces[2*index]);
1025 Uri = bstr_from_xmlChar(namespaces[2*index+1]);
1027 if(This->vbInterface)
1028 hr = IVBSAXContentHandler_startPrefixMapping(
1029 This->saxreader->vbcontentHandler,
1032 hr = ISAXContentHandler_startPrefixMapping(
1033 This->saxreader->contentHandler,
1034 Prefix, SysStringLen(Prefix),
1035 Uri, SysStringLen(Uri));
1037 SysFreeString(Prefix);
1042 format_error_message_from_id(This, hr);
1047 NamespaceUri = bstr_from_xmlChar(URI);
1048 LocalName = bstr_from_xmlChar(localname);
1049 QName = QName_from_xmlChar(prefix, localname);
1051 hr = SAXAttributes_create(&attr, nb_namespaces, namespaces, nb_attributes, attributes);
1054 if(This->vbInterface)
1055 hr = IVBSAXContentHandler_startElement(This->saxreader->vbcontentHandler,
1056 &NamespaceUri, &LocalName, &QName, &attr->IVBSAXAttributes_iface);
1058 hr = ISAXContentHandler_startElement(This->saxreader->contentHandler, NamespaceUri,
1059 SysStringLen(NamespaceUri), LocalName, SysStringLen(LocalName), QName,
1060 SysStringLen(QName), &attr->ISAXAttributes_iface);
1062 ISAXAttributes_Release(&attr->ISAXAttributes_iface);
1065 SysFreeString(NamespaceUri);
1066 SysFreeString(LocalName);
1067 SysFreeString(QName);
1071 format_error_message_from_id(This, hr);
1074 static void libxmlEndElementNS(
1076 const xmlChar *localname,
1077 const xmlChar *prefix,
1080 BSTR NamespaceUri, LocalName, QName, Prefix;
1081 saxlocator *This = ctx;
1086 end = (xmlChar*)This->pParserCtxt->input->cur;
1087 if(*(end-1) != '>' || *(end-2) != '/')
1088 while(end-2>=This->pParserCtxt->input->base
1089 && *(end-2)!='<' && *(end-1)!='/') end--;
1091 update_position(This, end);
1093 nsNr = namespacePop(This);
1095 if(has_content_handler(This))
1097 NamespaceUri = bstr_from_xmlChar(URI);
1098 LocalName = bstr_from_xmlChar(localname);
1099 QName = QName_from_xmlChar(prefix, localname);
1101 if(This->vbInterface)
1102 hr = IVBSAXContentHandler_endElement(
1103 This->saxreader->vbcontentHandler,
1104 &NamespaceUri, &LocalName, &QName);
1106 hr = ISAXContentHandler_endElement(
1107 This->saxreader->contentHandler,
1108 NamespaceUri, SysStringLen(NamespaceUri),
1109 LocalName, SysStringLen(LocalName),
1110 QName, SysStringLen(QName));
1112 SysFreeString(NamespaceUri);
1113 SysFreeString(LocalName);
1114 SysFreeString(QName);
1118 format_error_message_from_id(This, hr);
1122 for(index=This->pParserCtxt->nsNr-2;
1123 index>=This->pParserCtxt->nsNr-nsNr*2; index-=2)
1125 Prefix = bstr_from_xmlChar(This->pParserCtxt->nsTab[index]);
1127 if(This->vbInterface)
1128 hr = IVBSAXContentHandler_endPrefixMapping(
1129 This->saxreader->vbcontentHandler, &Prefix);
1131 hr = ISAXContentHandler_endPrefixMapping(
1132 This->saxreader->contentHandler,
1133 Prefix, SysStringLen(Prefix));
1135 SysFreeString(Prefix);
1139 format_error_message_from_id(This, hr);
1146 update_position(This, NULL);
1149 static void libxmlCharacters(
1154 saxlocator *This = ctx;
1159 BOOL lastEvent = FALSE;
1161 if(!(has_content_handler(This))) return;
1164 if(*(ch-1)=='\r') cur--;
1167 if(ch<This->pParserCtxt->input->base || ch>This->pParserCtxt->input->end)
1172 while(end-ch<len && *end!='\r') end++;
1179 if(!lastEvent) *end = '\n';
1181 Chars = bstr_from_xmlCharN(cur, end-cur+1);
1182 if(This->vbInterface)
1183 hr = IVBSAXContentHandler_characters(
1184 This->saxreader->vbcontentHandler, &Chars);
1186 hr = ISAXContentHandler_characters(
1187 This->saxreader->contentHandler,
1188 Chars, SysStringLen(Chars));
1189 SysFreeString(Chars);
1193 format_error_message_from_id(This, hr);
1197 This->column += end-cur+1;
1211 if(end-ch == len) break;
1214 if(ch<This->pParserCtxt->input->base || ch>This->pParserCtxt->input->end)
1215 This->column = This->realColumn
1216 +This->pParserCtxt->input->cur-This->lastCur;
1219 static void libxmlSetDocumentLocator(
1221 xmlSAXLocatorPtr loc)
1223 saxlocator *This = ctx;
1226 if(has_content_handler(This))
1228 if(This->vbInterface)
1229 hr = IVBSAXContentHandler_putref_documentLocator(This->saxreader->vbcontentHandler,
1230 &This->IVBSAXLocator_iface);
1232 hr = ISAXContentHandler_putDocumentLocator(This->saxreader->contentHandler,
1233 &This->ISAXLocator_iface);
1237 format_error_message_from_id(This, hr);
1240 static void libxmlComment(void *ctx, const xmlChar *value)
1242 saxlocator *This = ctx;
1245 xmlChar *beg = (xmlChar*)This->pParserCtxt->input->cur;
1247 while(beg-4>=This->pParserCtxt->input->base
1248 && memcmp(beg-4, "<!--", sizeof(char[4]))) beg--;
1249 update_position(This, beg);
1251 if(!This->vbInterface && !This->saxreader->lexicalHandler) return;
1252 if(This->vbInterface && !This->saxreader->vblexicalHandler) return;
1254 bValue = bstr_from_xmlChar(value);
1256 if(This->vbInterface)
1257 hr = IVBSAXLexicalHandler_comment(
1258 This->saxreader->vblexicalHandler, &bValue);
1260 hr = ISAXLexicalHandler_comment(
1261 This->saxreader->lexicalHandler,
1262 bValue, SysStringLen(bValue));
1264 SysFreeString(bValue);
1267 format_error_message_from_id(This, hr);
1269 update_position(This, NULL);
1272 static void libxmlFatalError(void *ctx, const char *msg, ...)
1274 saxlocator *This = ctx;
1280 va_start(args, msg);
1281 vsprintf(message, msg, args);
1284 len = MultiByteToWideChar(CP_UNIXCP, 0, message, -1, NULL, 0);
1285 error = heap_alloc(sizeof(WCHAR)*len);
1288 MultiByteToWideChar(CP_UNIXCP, 0, message, -1, error, len);
1289 TRACE("fatal error for %p: %s\n", This, debugstr_w(error));
1292 if(!has_error_handler(This))
1294 xmlStopParser(This->pParserCtxt);
1300 FIXME("Error handling is not compatible.\n");
1302 if(This->vbInterface)
1304 BSTR bstrError = SysAllocString(error);
1305 IVBSAXErrorHandler_fatalError(This->saxreader->vberrorHandler, &This->IVBSAXLocator_iface,
1306 &bstrError, E_FAIL);
1307 SysFreeString(bstrError);
1310 ISAXErrorHandler_fatalError(This->saxreader->errorHandler, &This->ISAXLocator_iface,
1315 xmlStopParser(This->pParserCtxt);
1319 static void libxmlCDataBlock(void *ctx, const xmlChar *value, int len)
1321 saxlocator *This = ctx;
1323 xmlChar *beg = (xmlChar*)This->pParserCtxt->input->cur-len;
1327 BOOL lastEvent = FALSE, change;
1329 while(beg-9>=This->pParserCtxt->input->base
1330 && memcmp(beg-9, "<![CDATA[", sizeof(char[9]))) beg--;
1331 update_position(This, beg);
1333 if(This->vbInterface && This->saxreader->vblexicalHandler)
1334 hr = IVBSAXLexicalHandler_startCDATA(This->saxreader->vblexicalHandler);
1335 if(!This->vbInterface && This->saxreader->lexicalHandler)
1336 hr = ISAXLexicalHandler_startCDATA(This->saxreader->lexicalHandler);
1340 format_error_message_from_id(This, hr);
1344 realLen = This->pParserCtxt->input->cur-beg-3;
1350 while(end-beg<realLen && *end!='\r') end++;
1351 if(end-beg==realLen)
1356 else if(end-beg==realLen-1 && *end=='\r' && *(end+1)=='\n')
1359 if(*end == '\r') change = TRUE;
1360 else change = FALSE;
1362 if(change) *end = '\n';
1364 if(has_content_handler(This))
1366 Chars = bstr_from_xmlCharN(cur, end-cur+1);
1367 if(This->vbInterface)
1368 hr = IVBSAXContentHandler_characters(
1369 This->saxreader->vbcontentHandler, &Chars);
1371 hr = ISAXContentHandler_characters(
1372 This->saxreader->contentHandler,
1373 Chars, SysStringLen(Chars));
1374 SysFreeString(Chars);
1377 if(change) *end = '\r';
1382 This->column += end-cur+2;
1387 if(This->vbInterface && This->saxreader->vblexicalHandler)
1388 hr = IVBSAXLexicalHandler_endCDATA(This->saxreader->vblexicalHandler);
1389 if(!This->vbInterface && This->saxreader->lexicalHandler)
1390 hr = ISAXLexicalHandler_endCDATA(This->saxreader->lexicalHandler);
1393 format_error_message_from_id(This, hr);
1395 This->column += 4+end-cur;
1398 /*** IVBSAXLocator interface ***/
1399 /*** IUnknown methods ***/
1400 static HRESULT WINAPI ivbsaxlocator_QueryInterface(IVBSAXLocator* iface, REFIID riid, void **ppvObject)
1402 saxlocator *This = impl_from_IVBSAXLocator( iface );
1404 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject);
1408 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
1409 IsEqualGUID( riid, &IID_IDispatch) ||
1410 IsEqualGUID( riid, &IID_IVBSAXLocator ))
1416 FIXME("interface %s not implemented\n", debugstr_guid(riid));
1417 return E_NOINTERFACE;
1420 IVBSAXLocator_AddRef( iface );
1425 static ULONG WINAPI ivbsaxlocator_AddRef(IVBSAXLocator* iface)
1427 saxlocator *This = impl_from_IVBSAXLocator( iface );
1428 TRACE("%p\n", This );
1429 return InterlockedIncrement( &This->ref );
1432 static ULONG WINAPI ivbsaxlocator_Release(
1433 IVBSAXLocator* iface)
1435 saxlocator *This = impl_from_IVBSAXLocator( iface );
1436 return ISAXLocator_Release((ISAXLocator*)&This->IVBSAXLocator_iface);
1439 /*** IDispatch methods ***/
1440 static HRESULT WINAPI ivbsaxlocator_GetTypeInfoCount( IVBSAXLocator *iface, UINT* pctinfo )
1442 saxlocator *This = impl_from_IVBSAXLocator( iface );
1444 TRACE("(%p)->(%p)\n", This, pctinfo);
1451 static HRESULT WINAPI ivbsaxlocator_GetTypeInfo(
1452 IVBSAXLocator *iface,
1453 UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo )
1455 saxlocator *This = impl_from_IVBSAXLocator( iface );
1458 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
1460 hr = get_typeinfo(IVBSAXLocator_tid, ppTInfo);
1465 static HRESULT WINAPI ivbsaxlocator_GetIDsOfNames(
1466 IVBSAXLocator *iface,
1468 LPOLESTR* rgszNames,
1473 saxlocator *This = impl_from_IVBSAXLocator( iface );
1474 ITypeInfo *typeinfo;
1477 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
1480 if(!rgszNames || cNames == 0 || !rgDispId)
1481 return E_INVALIDARG;
1483 hr = get_typeinfo(IVBSAXLocator_tid, &typeinfo);
1486 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
1487 ITypeInfo_Release(typeinfo);
1493 static HRESULT WINAPI ivbsaxlocator_Invoke(
1494 IVBSAXLocator *iface,
1495 DISPID dispIdMember,
1499 DISPPARAMS* pDispParams,
1500 VARIANT* pVarResult,
1501 EXCEPINFO* pExcepInfo,
1504 saxlocator *This = impl_from_IVBSAXLocator( iface );
1505 ITypeInfo *typeinfo;
1508 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1509 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1511 hr = get_typeinfo(IVBSAXLocator_tid, &typeinfo);
1514 hr = ITypeInfo_Invoke(typeinfo, &This->IVBSAXLocator_iface, dispIdMember, wFlags,
1515 pDispParams, pVarResult, pExcepInfo, puArgErr);
1516 ITypeInfo_Release(typeinfo);
1522 /*** IVBSAXLocator methods ***/
1523 static HRESULT WINAPI ivbsaxlocator_get_columnNumber(
1524 IVBSAXLocator* iface,
1527 saxlocator *This = impl_from_IVBSAXLocator( iface );
1528 return ISAXLocator_getColumnNumber((ISAXLocator*)&This->IVBSAXLocator_iface, pnColumn);
1531 static HRESULT WINAPI ivbsaxlocator_get_lineNumber(
1532 IVBSAXLocator* iface,
1535 saxlocator *This = impl_from_IVBSAXLocator( iface );
1536 return ISAXLocator_getLineNumber((ISAXLocator*)&This->IVBSAXLocator_iface, pnLine);
1539 static HRESULT WINAPI ivbsaxlocator_get_publicId(
1540 IVBSAXLocator* iface,
1543 saxlocator *This = impl_from_IVBSAXLocator( iface );
1544 return ISAXLocator_getPublicId((ISAXLocator*)&This->IVBSAXLocator_iface,
1545 (const WCHAR**)publicId);
1548 static HRESULT WINAPI ivbsaxlocator_get_systemId(
1549 IVBSAXLocator* iface,
1552 saxlocator *This = impl_from_IVBSAXLocator( iface );
1553 return ISAXLocator_getSystemId((ISAXLocator*)&This->IVBSAXLocator_iface,
1554 (const WCHAR**)systemId);
1557 static const struct IVBSAXLocatorVtbl ivbsaxlocator_vtbl =
1559 ivbsaxlocator_QueryInterface,
1560 ivbsaxlocator_AddRef,
1561 ivbsaxlocator_Release,
1562 ivbsaxlocator_GetTypeInfoCount,
1563 ivbsaxlocator_GetTypeInfo,
1564 ivbsaxlocator_GetIDsOfNames,
1565 ivbsaxlocator_Invoke,
1566 ivbsaxlocator_get_columnNumber,
1567 ivbsaxlocator_get_lineNumber,
1568 ivbsaxlocator_get_publicId,
1569 ivbsaxlocator_get_systemId
1572 /*** ISAXLocator interface ***/
1573 /*** IUnknown methods ***/
1574 static HRESULT WINAPI isaxlocator_QueryInterface(ISAXLocator* iface, REFIID riid, void **ppvObject)
1576 saxlocator *This = impl_from_ISAXLocator( iface );
1578 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject );
1582 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
1583 IsEqualGUID( riid, &IID_ISAXLocator ))
1589 FIXME("interface %s not implemented\n", debugstr_guid(riid));
1590 return E_NOINTERFACE;
1593 ISAXLocator_AddRef( iface );
1598 static ULONG WINAPI isaxlocator_AddRef(ISAXLocator* iface)
1600 saxlocator *This = impl_from_ISAXLocator( iface );
1601 TRACE("%p\n", This );
1602 return InterlockedIncrement( &This->ref );
1605 static ULONG WINAPI isaxlocator_Release(
1608 saxlocator *This = impl_from_ISAXLocator( iface );
1611 TRACE("%p\n", This );
1613 ref = InterlockedDecrement( &This->ref );
1616 SysFreeString(This->publicId);
1617 SysFreeString(This->systemId);
1618 heap_free(This->nsStack);
1620 ISAXXMLReader_Release(&This->saxreader->ISAXXMLReader_iface);
1627 /*** ISAXLocator methods ***/
1628 static HRESULT WINAPI isaxlocator_getColumnNumber(
1632 saxlocator *This = impl_from_ISAXLocator( iface );
1634 *pnColumn = This->column;
1638 static HRESULT WINAPI isaxlocator_getLineNumber(
1642 saxlocator *This = impl_from_ISAXLocator( iface );
1644 *pnLine = This->line;
1648 static HRESULT WINAPI isaxlocator_getPublicId(
1650 const WCHAR ** ppwchPublicId)
1653 saxlocator *This = impl_from_ISAXLocator( iface );
1655 SysFreeString(This->publicId);
1657 publicId = bstr_from_xmlChar(xmlSAX2GetPublicId(This->pParserCtxt));
1658 if(SysStringLen(publicId))
1659 This->publicId = (WCHAR*)&publicId;
1662 SysFreeString(publicId);
1663 This->publicId = NULL;
1666 *ppwchPublicId = This->publicId;
1670 static HRESULT WINAPI isaxlocator_getSystemId(
1672 const WCHAR ** ppwchSystemId)
1675 saxlocator *This = impl_from_ISAXLocator( iface );
1677 SysFreeString(This->systemId);
1679 systemId = bstr_from_xmlChar(xmlSAX2GetSystemId(This->pParserCtxt));
1680 if(SysStringLen(systemId))
1681 This->systemId = (WCHAR*)&systemId;
1684 SysFreeString(systemId);
1685 This->systemId = NULL;
1688 *ppwchSystemId = This->systemId;
1692 static const struct ISAXLocatorVtbl isaxlocator_vtbl =
1694 isaxlocator_QueryInterface,
1696 isaxlocator_Release,
1697 isaxlocator_getColumnNumber,
1698 isaxlocator_getLineNumber,
1699 isaxlocator_getPublicId,
1700 isaxlocator_getSystemId
1703 static HRESULT SAXLocator_create(saxreader *reader, saxlocator **ppsaxlocator, BOOL vbInterface)
1705 saxlocator *locator;
1707 locator = heap_alloc( sizeof (*locator) );
1709 return E_OUTOFMEMORY;
1711 locator->IVBSAXLocator_iface.lpVtbl = &ivbsaxlocator_vtbl;
1712 locator->ISAXLocator_iface.lpVtbl = &isaxlocator_vtbl;
1714 locator->vbInterface = vbInterface;
1716 locator->saxreader = reader;
1717 ISAXXMLReader_AddRef(&reader->ISAXXMLReader_iface);
1719 locator->pParserCtxt = NULL;
1720 locator->publicId = NULL;
1721 locator->systemId = NULL;
1722 locator->lastCur = NULL;
1724 locator->column = 0;
1725 locator->ret = S_OK;
1726 locator->nsStackSize = 8;
1727 locator->nsStackLast = 0;
1728 locator->nsStack = heap_alloc(sizeof(int)*locator->nsStackSize);
1729 if(!locator->nsStack)
1731 ISAXXMLReader_Release(&reader->ISAXXMLReader_iface);
1733 return E_OUTOFMEMORY;
1736 *ppsaxlocator = locator;
1738 TRACE("returning %p\n", *ppsaxlocator);
1743 /*** SAXXMLReader internal functions ***/
1744 static HRESULT internal_parseBuffer(saxreader *This, const char *buffer, int size, BOOL vbInterface)
1746 xmlCharEncoding encoding = XML_CHAR_ENCODING_NONE;
1747 xmlChar *enc_name = NULL;
1748 saxlocator *locator;
1751 hr = SAXLocator_create(This, &locator, vbInterface);
1757 const unsigned char *buff = (unsigned char*)buffer;
1759 encoding = xmlDetectCharEncoding((xmlChar*)buffer, 4);
1760 enc_name = (xmlChar*)xmlGetCharEncodingName(encoding);
1761 TRACE("detected encoding: %s\n", enc_name);
1762 /* skip BOM, parser won't switch encodings and so won't skip it on its own */
1763 if ((encoding == XML_CHAR_ENCODING_UTF8) &&
1764 buff[0] == 0xEF && buff[1] == 0xBB && buff[2] == 0xBF)
1771 locator->pParserCtxt = xmlCreateMemoryParserCtxt(buffer, size);
1772 if(!locator->pParserCtxt)
1774 ISAXLocator_Release(&locator->ISAXLocator_iface);
1778 if (encoding == XML_CHAR_ENCODING_UTF8)
1779 locator->pParserCtxt->encoding = xmlStrdup(enc_name);
1781 xmlFree(locator->pParserCtxt->sax);
1782 locator->pParserCtxt->sax = &locator->saxreader->sax;
1783 locator->pParserCtxt->userData = locator;
1785 This->isParsing = TRUE;
1786 if(xmlParseDocument(locator->pParserCtxt) == -1) hr = E_FAIL;
1787 else hr = locator->ret;
1788 This->isParsing = FALSE;
1790 if(locator->pParserCtxt)
1792 locator->pParserCtxt->sax = NULL;
1793 xmlFreeParserCtxt(locator->pParserCtxt);
1794 locator->pParserCtxt = NULL;
1797 ISAXLocator_Release(&locator->ISAXLocator_iface);
1801 static HRESULT internal_parseStream(saxreader *This, IStream *stream, BOOL vbInterface)
1803 saxlocator *locator;
1808 hr = IStream_Read(stream, data, sizeof(data), &dataRead);
1812 hr = SAXLocator_create(This, &locator, vbInterface);
1816 locator->pParserCtxt = xmlCreatePushParserCtxt(
1817 &locator->saxreader->sax, locator,
1818 data, dataRead, NULL);
1819 if(!locator->pParserCtxt)
1821 ISAXLocator_Release(&locator->ISAXLocator_iface);
1825 This->isParsing = TRUE;
1828 hr = IStream_Read(stream, data, sizeof(data), &dataRead);
1832 if(xmlParseChunk(locator->pParserCtxt, data, dataRead, 0) != XML_ERR_OK) hr = E_FAIL;
1833 else hr = locator->ret;
1835 if(hr != S_OK) break;
1837 if(dataRead != sizeof(data))
1839 if(xmlParseChunk(locator->pParserCtxt, data, 0, 1) != XML_ERR_OK) hr = E_FAIL;
1840 else hr = locator->ret;
1845 This->isParsing = FALSE;
1847 xmlFreeParserCtxt(locator->pParserCtxt);
1848 locator->pParserCtxt = NULL;
1849 ISAXLocator_Release(&locator->ISAXLocator_iface);
1853 static HRESULT internal_getEntityResolver(
1855 void *pEntityResolver,
1858 FIXME("(%p)->(%p) stub\n", This, pEntityResolver);
1862 static HRESULT internal_putEntityResolver(
1864 void *pEntityResolver,
1867 FIXME("(%p)->(%p) stub\n", This, pEntityResolver);
1871 static HRESULT internal_getContentHandler(
1873 void *pContentHandler,
1876 TRACE("(%p)->(%p)\n", This, pContentHandler);
1877 if(pContentHandler == NULL)
1879 if((vbInterface && This->vbcontentHandler)
1880 || (!vbInterface && This->contentHandler))
1883 IVBSAXContentHandler_AddRef(This->vbcontentHandler);
1885 ISAXContentHandler_AddRef(This->contentHandler);
1887 if(vbInterface) *(IVBSAXContentHandler**)pContentHandler =
1888 This->vbcontentHandler;
1889 else *(ISAXContentHandler**)pContentHandler = This->contentHandler;
1894 static HRESULT internal_putContentHandler(
1896 void *contentHandler,
1899 TRACE("(%p)->(%p)\n", This, contentHandler);
1903 IVBSAXContentHandler_AddRef((IVBSAXContentHandler*)contentHandler);
1905 ISAXContentHandler_AddRef((ISAXContentHandler*)contentHandler);
1907 if((vbInterface && This->vbcontentHandler)
1908 || (!vbInterface && This->contentHandler))
1911 IVBSAXContentHandler_Release(This->vbcontentHandler);
1913 ISAXContentHandler_Release(This->contentHandler);
1916 This->vbcontentHandler = contentHandler;
1918 This->contentHandler = contentHandler;
1923 static HRESULT internal_getDTDHandler(
1928 FIXME("(%p)->(%p) stub\n", This, pDTDHandler);
1932 static HRESULT internal_putDTDHandler(
1937 FIXME("(%p)->(%p) stub\n", This, pDTDHandler);
1941 static HRESULT internal_getErrorHandler(
1943 void *pErrorHandler,
1946 TRACE("(%p)->(%p)\n", This, pErrorHandler);
1947 if(pErrorHandler == NULL)
1950 if(vbInterface && This->vberrorHandler)
1951 IVBSAXErrorHandler_AddRef(This->vberrorHandler);
1952 else if(!vbInterface && This->errorHandler)
1953 ISAXErrorHandler_AddRef(This->errorHandler);
1956 *(IVBSAXErrorHandler**)pErrorHandler = This->vberrorHandler;
1958 *(ISAXErrorHandler**)pErrorHandler = This->errorHandler;
1964 static HRESULT internal_putErrorHandler(
1969 TRACE("(%p)->(%p)\n", This, errorHandler);
1973 IVBSAXErrorHandler_AddRef((IVBSAXErrorHandler*)errorHandler);
1975 ISAXErrorHandler_AddRef((ISAXErrorHandler*)errorHandler);
1978 if(vbInterface && This->vberrorHandler)
1979 IVBSAXErrorHandler_Release(This->vberrorHandler);
1980 else if(!vbInterface && This->errorHandler)
1981 ISAXErrorHandler_Release(This->errorHandler);
1984 This->vberrorHandler = errorHandler;
1986 This->errorHandler = errorHandler;
1992 static HRESULT internal_parse(
1999 TRACE("(%p)->(%s)\n", This, debugstr_variant(&varInput));
2001 switch(V_VT(&varInput))
2004 hr = internal_parseBuffer(This, (const char*)V_BSTR(&varInput),
2005 SysStringByteLen(V_BSTR(&varInput)), vbInterface);
2007 case VT_ARRAY|VT_UI1: {
2009 LONG lBound, uBound;
2012 hr = SafeArrayGetLBound(V_ARRAY(&varInput), 1, &lBound);
2013 if(hr != S_OK) break;
2014 hr = SafeArrayGetUBound(V_ARRAY(&varInput), 1, &uBound);
2015 if(hr != S_OK) break;
2016 dataRead = (uBound-lBound)*SafeArrayGetElemsize(V_ARRAY(&varInput));
2017 hr = SafeArrayAccessData(V_ARRAY(&varInput), &pSAData);
2018 if(hr != S_OK) break;
2019 hr = internal_parseBuffer(This, pSAData, dataRead, vbInterface);
2020 SafeArrayUnaccessData(V_ARRAY(&varInput));
2025 IPersistStream *persistStream;
2026 IStream *stream = NULL;
2027 IXMLDOMDocument *xmlDoc;
2029 if(IUnknown_QueryInterface(V_UNKNOWN(&varInput),
2030 &IID_IXMLDOMDocument, (void**)&xmlDoc) == S_OK)
2034 IXMLDOMDocument_get_xml(xmlDoc, &bstrData);
2035 hr = internal_parseBuffer(This, (const char*)bstrData,
2036 SysStringByteLen(bstrData), vbInterface);
2037 IXMLDOMDocument_Release(xmlDoc);
2038 SysFreeString(bstrData);
2042 if(IUnknown_QueryInterface(V_UNKNOWN(&varInput),
2043 &IID_IPersistStream, (void**)&persistStream) == S_OK)
2045 hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
2048 IPersistStream_Release(persistStream);
2052 hr = IPersistStream_Save(persistStream, stream, TRUE);
2053 IPersistStream_Release(persistStream);
2056 IStream_Release(stream);
2060 if(stream || IUnknown_QueryInterface(V_UNKNOWN(&varInput),
2061 &IID_IStream, (void**)&stream) == S_OK)
2063 hr = internal_parseStream(This, stream, vbInterface);
2064 IStream_Release(stream);
2069 WARN("vt %d not implemented\n", V_VT(&varInput));
2076 static HRESULT internal_vbonDataAvailable(void *obj, char *ptr, DWORD len)
2078 saxreader *This = obj;
2080 return internal_parseBuffer(This, ptr, len, TRUE);
2083 static HRESULT internal_onDataAvailable(void *obj, char *ptr, DWORD len)
2085 saxreader *This = obj;
2087 return internal_parseBuffer(This, ptr, len, FALSE);
2090 static HRESULT internal_parseURL(
2098 TRACE("(%p)->(%s)\n", This, debugstr_w(url));
2100 if(vbInterface) hr = bind_url(url, internal_vbonDataAvailable, This, &bsc);
2101 else hr = bind_url(url, internal_onDataAvailable, This, &bsc);
2111 static HRESULT internal_putProperty(
2117 static const WCHAR wszCharset[] = {
2118 'c','h','a','r','s','e','t',0
2120 static const WCHAR wszDeclarationHandler[] = {
2121 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
2122 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
2123 'd','e','c','l','a','r','a','t','i','o','n',
2124 '-','h','a','n','d','l','e','r',0
2126 static const WCHAR wszDomNode[] = {
2127 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
2128 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
2129 'd','o','m','-','n','o','d','e',0
2131 static const WCHAR wszInputSource[] = {
2132 'i','n','p','u','t','-','s','o','u','r','c','e',0
2134 static const WCHAR wszLexicalHandler[] = {
2135 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
2136 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
2137 'l','e','x','i','c','a','l','-','h','a','n','d','l','e','r',0
2139 static const WCHAR wszMaxElementDepth[] = {
2140 'm','a','x','-','e','l','e','m','e','n','t','-','d','e','p','t','h',0
2142 static const WCHAR wszMaxXMLSize[] = {
2143 'm','a','x','-','x','m','l','-','s','i','z','e',0
2145 static const WCHAR wszSchemaDeclarationHandler[] = {
2146 's','c','h','e','m','a','-',
2147 'd','e','c','l','a','r','a','t','i','o','n','-',
2148 'h','a','n','d','l','e','r',0
2150 static const WCHAR wszXMLDeclEncoding[] = {
2151 'x','m','l','d','e','c','l','-','e','n','c','o','d','i','n','g',0
2153 static const WCHAR wszXMLDeclStandalone[] = {
2154 'x','m','l','d','e','c','l',
2155 '-','s','t','a','n','d','a','l','o','n','e',0
2157 static const WCHAR wszXMLDeclVersion[] = {
2158 'x','m','l','d','e','c','l','-','v','e','r','s','i','o','n',0
2161 TRACE("(%p)->(%s %s)\n", This, debugstr_w(pProp), debugstr_variant(&value));
2163 if(!memcmp(pProp, wszDeclarationHandler, sizeof(wszDeclarationHandler)))
2165 if(This->isParsing) return E_FAIL;
2167 if(V_UNKNOWN(&value))
2170 IVBSAXDeclHandler_AddRef((IVBSAXDeclHandler*)V_UNKNOWN(&value));
2172 ISAXDeclHandler_AddRef((ISAXDeclHandler*)V_UNKNOWN(&value));
2174 if((vbInterface && This->vbdeclHandler)
2175 || (!vbInterface && This->declHandler))
2178 IVBSAXDeclHandler_Release(This->vbdeclHandler);
2180 ISAXDeclHandler_Release(This->declHandler);
2183 This->vbdeclHandler = (IVBSAXDeclHandler*)V_UNKNOWN(&value);
2185 This->declHandler = (ISAXDeclHandler*)V_UNKNOWN(&value);
2189 if(!memcmp(pProp, wszLexicalHandler, sizeof(wszLexicalHandler)))
2191 if(This->isParsing) return E_FAIL;
2193 if(V_UNKNOWN(&value))
2196 IVBSAXLexicalHandler_AddRef(
2197 (IVBSAXLexicalHandler*)V_UNKNOWN(&value));
2199 ISAXLexicalHandler_AddRef(
2200 (ISAXLexicalHandler*)V_UNKNOWN(&value));
2202 if((vbInterface && This->vblexicalHandler)
2203 || (!vbInterface && This->lexicalHandler))
2206 IVBSAXLexicalHandler_Release(This->vblexicalHandler);
2208 ISAXLexicalHandler_Release(This->lexicalHandler);
2211 This->vblexicalHandler = (IVBSAXLexicalHandler*)V_UNKNOWN(&value);
2213 This->lexicalHandler = (ISAXLexicalHandler*)V_UNKNOWN(&value);
2217 FIXME("(%p)->(%s): unsupported property\n", This, debugstr_w(pProp));
2219 if(!memcmp(pProp, wszCharset, sizeof(wszCharset)))
2222 if(!memcmp(pProp, wszDomNode, sizeof(wszDomNode)))
2225 if(!memcmp(pProp, wszInputSource, sizeof(wszInputSource)))
2228 if(!memcmp(pProp, wszMaxElementDepth, sizeof(wszMaxElementDepth)))
2231 if(!memcmp(pProp, wszMaxXMLSize, sizeof(wszMaxXMLSize)))
2234 if(!memcmp(pProp, wszSchemaDeclarationHandler,
2235 sizeof(wszSchemaDeclarationHandler)))
2238 if(!memcmp(pProp, wszXMLDeclEncoding, sizeof(wszXMLDeclEncoding)))
2241 if(!memcmp(pProp, wszXMLDeclStandalone, sizeof(wszXMLDeclStandalone)))
2244 if(!memcmp(pProp, wszXMLDeclVersion, sizeof(wszXMLDeclVersion)))
2247 return E_INVALIDARG;
2250 /*** IVBSAXXMLReader interface ***/
2251 /*** IUnknown methods ***/
2252 static HRESULT WINAPI saxxmlreader_QueryInterface(IVBSAXXMLReader* iface, REFIID riid, void **ppvObject)
2254 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2256 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject );
2260 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
2261 IsEqualGUID( riid, &IID_IDispatch ) ||
2262 IsEqualGUID( riid, &IID_IVBSAXXMLReader ))
2266 else if( IsEqualGUID( riid, &IID_ISAXXMLReader ))
2268 *ppvObject = &This->ISAXXMLReader_iface;
2272 FIXME("interface %s not implemented\n", debugstr_guid(riid));
2273 return E_NOINTERFACE;
2276 IVBSAXXMLReader_AddRef( iface );
2281 static ULONG WINAPI saxxmlreader_AddRef(IVBSAXXMLReader* iface)
2283 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2284 TRACE("%p\n", This );
2285 return InterlockedIncrement( &This->ref );
2288 static ULONG WINAPI saxxmlreader_Release(
2289 IVBSAXXMLReader* iface)
2291 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2294 TRACE("%p\n", This );
2296 ref = InterlockedDecrement( &This->ref );
2299 if(This->contentHandler)
2300 ISAXContentHandler_Release(This->contentHandler);
2302 if(This->vbcontentHandler)
2303 IVBSAXContentHandler_Release(This->vbcontentHandler);
2305 if(This->errorHandler)
2306 ISAXErrorHandler_Release(This->errorHandler);
2308 if(This->vberrorHandler)
2309 IVBSAXErrorHandler_Release(This->vberrorHandler);
2311 if(This->lexicalHandler)
2312 ISAXLexicalHandler_Release(This->lexicalHandler);
2314 if(This->vblexicalHandler)
2315 IVBSAXLexicalHandler_Release(This->vblexicalHandler);
2317 if(This->declHandler)
2318 ISAXDeclHandler_Release(This->declHandler);
2320 if(This->vbdeclHandler)
2321 IVBSAXDeclHandler_Release(This->vbdeclHandler);
2329 static HRESULT WINAPI saxxmlreader_GetTypeInfoCount( IVBSAXXMLReader *iface, UINT* pctinfo )
2331 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2333 TRACE("(%p)->(%p)\n", This, pctinfo);
2340 static HRESULT WINAPI saxxmlreader_GetTypeInfo(
2341 IVBSAXXMLReader *iface,
2342 UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo )
2344 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2347 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
2349 hr = get_typeinfo(IVBSAXXMLReader_tid, ppTInfo);
2354 static HRESULT WINAPI saxxmlreader_GetIDsOfNames(
2355 IVBSAXXMLReader *iface,
2357 LPOLESTR* rgszNames,
2362 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2363 ITypeInfo *typeinfo;
2366 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
2369 if(!rgszNames || cNames == 0 || !rgDispId)
2370 return E_INVALIDARG;
2372 hr = get_typeinfo(IVBSAXXMLReader_tid, &typeinfo);
2375 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
2376 ITypeInfo_Release(typeinfo);
2382 static HRESULT WINAPI saxxmlreader_Invoke(
2383 IVBSAXXMLReader *iface,
2384 DISPID dispIdMember,
2388 DISPPARAMS* pDispParams,
2389 VARIANT* pVarResult,
2390 EXCEPINFO* pExcepInfo,
2393 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2394 ITypeInfo *typeinfo;
2397 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
2398 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2400 hr = get_typeinfo(IVBSAXXMLReader_tid, &typeinfo);
2403 hr = ITypeInfo_Invoke(typeinfo, &This->IVBSAXXMLReader_iface, dispIdMember, wFlags,
2404 pDispParams, pVarResult, pExcepInfo, puArgErr);
2405 ITypeInfo_Release(typeinfo);
2411 /*** IVBSAXXMLReader methods ***/
2412 static HRESULT WINAPI saxxmlreader_getFeature(
2413 IVBSAXXMLReader* iface,
2414 const WCHAR *pFeature,
2415 VARIANT_BOOL *pValue)
2417 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2419 FIXME("(%p)->(%s %p) stub\n", This, debugstr_w(pFeature), pValue);
2423 static HRESULT WINAPI saxxmlreader_putFeature(
2424 IVBSAXXMLReader* iface,
2425 const WCHAR *pFeature,
2426 VARIANT_BOOL vfValue)
2428 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2430 FIXME("(%p)->(%s %x) stub\n", This, debugstr_w(pFeature), vfValue);
2434 static HRESULT WINAPI saxxmlreader_getProperty(
2435 IVBSAXXMLReader* iface,
2439 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2441 FIXME("(%p)->(%s %p) stub\n", This, debugstr_w(pProp), pValue);
2445 static HRESULT WINAPI saxxmlreader_putProperty(
2446 IVBSAXXMLReader* iface,
2450 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2451 return internal_putProperty(This, pProp, value, TRUE);
2454 static HRESULT WINAPI saxxmlreader_get_entityResolver(
2455 IVBSAXXMLReader* iface,
2456 IVBSAXEntityResolver **pEntityResolver)
2458 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2459 return internal_getEntityResolver(This, pEntityResolver, TRUE);
2462 static HRESULT WINAPI saxxmlreader_put_entityResolver(
2463 IVBSAXXMLReader* iface,
2464 IVBSAXEntityResolver *pEntityResolver)
2466 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2467 return internal_putEntityResolver(This, pEntityResolver, TRUE);
2470 static HRESULT WINAPI saxxmlreader_get_contentHandler(
2471 IVBSAXXMLReader* iface,
2472 IVBSAXContentHandler **ppContentHandler)
2474 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2475 return internal_getContentHandler(This, ppContentHandler, TRUE);
2478 static HRESULT WINAPI saxxmlreader_put_contentHandler(
2479 IVBSAXXMLReader* iface,
2480 IVBSAXContentHandler *contentHandler)
2482 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2483 return internal_putContentHandler(This, contentHandler, TRUE);
2486 static HRESULT WINAPI saxxmlreader_get_dtdHandler(
2487 IVBSAXXMLReader* iface,
2488 IVBSAXDTDHandler **pDTDHandler)
2490 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2491 return internal_getDTDHandler(This, pDTDHandler, TRUE);
2494 static HRESULT WINAPI saxxmlreader_put_dtdHandler(
2495 IVBSAXXMLReader* iface,
2496 IVBSAXDTDHandler *pDTDHandler)
2498 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2499 return internal_putDTDHandler(This, pDTDHandler, TRUE);
2502 static HRESULT WINAPI saxxmlreader_get_errorHandler(
2503 IVBSAXXMLReader* iface,
2504 IVBSAXErrorHandler **pErrorHandler)
2506 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2507 return internal_getErrorHandler(This, pErrorHandler, TRUE);
2510 static HRESULT WINAPI saxxmlreader_put_errorHandler(
2511 IVBSAXXMLReader* iface,
2512 IVBSAXErrorHandler *errorHandler)
2514 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2515 return internal_putErrorHandler(This, errorHandler, TRUE);
2518 static HRESULT WINAPI saxxmlreader_get_baseURL(
2519 IVBSAXXMLReader* iface,
2520 const WCHAR **pBaseUrl)
2522 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2524 FIXME("(%p)->(%p) stub\n", This, pBaseUrl);
2528 static HRESULT WINAPI saxxmlreader_put_baseURL(
2529 IVBSAXXMLReader* iface,
2530 const WCHAR *pBaseUrl)
2532 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2534 FIXME("(%p)->(%s) stub\n", This, debugstr_w(pBaseUrl));
2538 static HRESULT WINAPI saxxmlreader_get_secureBaseURL(
2539 IVBSAXXMLReader* iface,
2540 const WCHAR **pSecureBaseUrl)
2542 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2544 FIXME("(%p)->(%p) stub\n", This, pSecureBaseUrl);
2549 static HRESULT WINAPI saxxmlreader_put_secureBaseURL(
2550 IVBSAXXMLReader* iface,
2551 const WCHAR *secureBaseUrl)
2553 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2555 FIXME("(%p)->(%s) stub\n", This, debugstr_w(secureBaseUrl));
2559 static HRESULT WINAPI saxxmlreader_parse(
2560 IVBSAXXMLReader* iface,
2563 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2564 return internal_parse(This, varInput, TRUE);
2567 static HRESULT WINAPI saxxmlreader_parseURL(
2568 IVBSAXXMLReader* iface,
2571 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2572 return internal_parseURL(This, url, TRUE);
2575 static const struct IVBSAXXMLReaderVtbl saxreader_vtbl =
2577 saxxmlreader_QueryInterface,
2578 saxxmlreader_AddRef,
2579 saxxmlreader_Release,
2580 saxxmlreader_GetTypeInfoCount,
2581 saxxmlreader_GetTypeInfo,
2582 saxxmlreader_GetIDsOfNames,
2583 saxxmlreader_Invoke,
2584 saxxmlreader_getFeature,
2585 saxxmlreader_putFeature,
2586 saxxmlreader_getProperty,
2587 saxxmlreader_putProperty,
2588 saxxmlreader_get_entityResolver,
2589 saxxmlreader_put_entityResolver,
2590 saxxmlreader_get_contentHandler,
2591 saxxmlreader_put_contentHandler,
2592 saxxmlreader_get_dtdHandler,
2593 saxxmlreader_put_dtdHandler,
2594 saxxmlreader_get_errorHandler,
2595 saxxmlreader_put_errorHandler,
2596 saxxmlreader_get_baseURL,
2597 saxxmlreader_put_baseURL,
2598 saxxmlreader_get_secureBaseURL,
2599 saxxmlreader_put_secureBaseURL,
2601 saxxmlreader_parseURL
2604 /*** ISAXXMLReader interface ***/
2605 /*** IUnknown methods ***/
2606 static HRESULT WINAPI isaxxmlreader_QueryInterface(ISAXXMLReader* iface, REFIID riid, void **ppvObject)
2608 saxreader *This = impl_from_ISAXXMLReader( iface );
2609 return saxxmlreader_QueryInterface(&This->IVBSAXXMLReader_iface, riid, ppvObject);
2612 static ULONG WINAPI isaxxmlreader_AddRef(ISAXXMLReader* iface)
2614 saxreader *This = impl_from_ISAXXMLReader( iface );
2615 return saxxmlreader_AddRef(&This->IVBSAXXMLReader_iface);
2618 static ULONG WINAPI isaxxmlreader_Release(ISAXXMLReader* iface)
2620 saxreader *This = impl_from_ISAXXMLReader( iface );
2621 return saxxmlreader_Release(&This->IVBSAXXMLReader_iface);
2624 /*** ISAXXMLReader methods ***/
2625 static HRESULT WINAPI isaxxmlreader_getFeature(
2626 ISAXXMLReader* iface,
2627 const WCHAR *pFeature,
2628 VARIANT_BOOL *pValue)
2630 saxreader *This = impl_from_ISAXXMLReader( iface );
2631 return IVBSAXXMLReader_getFeature(&This->IVBSAXXMLReader_iface, pFeature, pValue);
2634 static HRESULT WINAPI isaxxmlreader_putFeature(
2635 ISAXXMLReader* iface,
2636 const WCHAR *pFeature,
2637 VARIANT_BOOL vfValue)
2639 saxreader *This = impl_from_ISAXXMLReader( iface );
2640 return IVBSAXXMLReader_putFeature(&This->IVBSAXXMLReader_iface, pFeature, vfValue);
2643 static HRESULT WINAPI isaxxmlreader_getProperty(
2644 ISAXXMLReader* iface,
2648 saxreader *This = impl_from_ISAXXMLReader( iface );
2649 return IVBSAXXMLReader_getProperty(&This->IVBSAXXMLReader_iface, pProp, pValue);
2652 static HRESULT WINAPI isaxxmlreader_putProperty(
2653 ISAXXMLReader* iface,
2657 saxreader *This = impl_from_ISAXXMLReader( iface );
2658 return internal_putProperty(This, pProp, value, FALSE);
2661 static HRESULT WINAPI isaxxmlreader_getEntityResolver(
2662 ISAXXMLReader* iface,
2663 ISAXEntityResolver **ppEntityResolver)
2665 saxreader *This = impl_from_ISAXXMLReader( iface );
2666 return internal_getEntityResolver(This, ppEntityResolver, FALSE);
2669 static HRESULT WINAPI isaxxmlreader_putEntityResolver(
2670 ISAXXMLReader* iface,
2671 ISAXEntityResolver *pEntityResolver)
2673 saxreader *This = impl_from_ISAXXMLReader( iface );
2674 return internal_putEntityResolver(This, pEntityResolver, FALSE);
2677 static HRESULT WINAPI isaxxmlreader_getContentHandler(
2678 ISAXXMLReader* iface,
2679 ISAXContentHandler **pContentHandler)
2681 saxreader *This = impl_from_ISAXXMLReader( iface );
2682 return internal_getContentHandler(This, pContentHandler, FALSE);
2685 static HRESULT WINAPI isaxxmlreader_putContentHandler(
2686 ISAXXMLReader* iface,
2687 ISAXContentHandler *contentHandler)
2689 saxreader *This = impl_from_ISAXXMLReader( iface );
2690 return internal_putContentHandler(This, contentHandler, FALSE);
2693 static HRESULT WINAPI isaxxmlreader_getDTDHandler(
2694 ISAXXMLReader* iface,
2695 ISAXDTDHandler **pDTDHandler)
2697 saxreader *This = impl_from_ISAXXMLReader( iface );
2698 return internal_getDTDHandler(This, pDTDHandler, FALSE);
2701 static HRESULT WINAPI isaxxmlreader_putDTDHandler(
2702 ISAXXMLReader* iface,
2703 ISAXDTDHandler *pDTDHandler)
2705 saxreader *This = impl_from_ISAXXMLReader( iface );
2706 return internal_putDTDHandler(This, pDTDHandler, FALSE);
2709 static HRESULT WINAPI isaxxmlreader_getErrorHandler(
2710 ISAXXMLReader* iface,
2711 ISAXErrorHandler **pErrorHandler)
2713 saxreader *This = impl_from_ISAXXMLReader( iface );
2714 return internal_getErrorHandler(This, pErrorHandler, FALSE);
2717 static HRESULT WINAPI isaxxmlreader_putErrorHandler(
2718 ISAXXMLReader* iface,
2719 ISAXErrorHandler *errorHandler)
2721 saxreader *This = impl_from_ISAXXMLReader( iface );
2722 return internal_putErrorHandler(This, errorHandler, FALSE);
2725 static HRESULT WINAPI isaxxmlreader_getBaseURL(
2726 ISAXXMLReader* iface,
2727 const WCHAR **pBaseUrl)
2729 saxreader *This = impl_from_ISAXXMLReader( iface );
2730 return IVBSAXXMLReader_get_baseURL(&This->IVBSAXXMLReader_iface, pBaseUrl);
2733 static HRESULT WINAPI isaxxmlreader_putBaseURL(
2734 ISAXXMLReader* iface,
2735 const WCHAR *pBaseUrl)
2737 saxreader *This = impl_from_ISAXXMLReader( iface );
2738 return IVBSAXXMLReader_put_baseURL(&This->IVBSAXXMLReader_iface, pBaseUrl);
2741 static HRESULT WINAPI isaxxmlreader_getSecureBaseURL(
2742 ISAXXMLReader* iface,
2743 const WCHAR **pSecureBaseUrl)
2745 saxreader *This = impl_from_ISAXXMLReader( iface );
2746 return IVBSAXXMLReader_get_secureBaseURL(&This->IVBSAXXMLReader_iface, pSecureBaseUrl);
2749 static HRESULT WINAPI isaxxmlreader_putSecureBaseURL(
2750 ISAXXMLReader* iface,
2751 const WCHAR *secureBaseUrl)
2753 saxreader *This = impl_from_ISAXXMLReader( iface );
2754 return IVBSAXXMLReader_put_secureBaseURL(&This->IVBSAXXMLReader_iface, secureBaseUrl);
2757 static HRESULT WINAPI isaxxmlreader_parse(
2758 ISAXXMLReader* iface,
2761 saxreader *This = impl_from_ISAXXMLReader( iface );
2762 return internal_parse(This, varInput, FALSE);
2765 static HRESULT WINAPI isaxxmlreader_parseURL(
2766 ISAXXMLReader* iface,
2769 saxreader *This = impl_from_ISAXXMLReader( iface );
2770 return internal_parseURL(This, url, FALSE);
2773 static const struct ISAXXMLReaderVtbl isaxreader_vtbl =
2775 isaxxmlreader_QueryInterface,
2776 isaxxmlreader_AddRef,
2777 isaxxmlreader_Release,
2778 isaxxmlreader_getFeature,
2779 isaxxmlreader_putFeature,
2780 isaxxmlreader_getProperty,
2781 isaxxmlreader_putProperty,
2782 isaxxmlreader_getEntityResolver,
2783 isaxxmlreader_putEntityResolver,
2784 isaxxmlreader_getContentHandler,
2785 isaxxmlreader_putContentHandler,
2786 isaxxmlreader_getDTDHandler,
2787 isaxxmlreader_putDTDHandler,
2788 isaxxmlreader_getErrorHandler,
2789 isaxxmlreader_putErrorHandler,
2790 isaxxmlreader_getBaseURL,
2791 isaxxmlreader_putBaseURL,
2792 isaxxmlreader_getSecureBaseURL,
2793 isaxxmlreader_putSecureBaseURL,
2794 isaxxmlreader_parse,
2795 isaxxmlreader_parseURL
2798 HRESULT SAXXMLReader_create(IUnknown *pUnkOuter, LPVOID *ppObj)
2802 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
2804 reader = heap_alloc( sizeof (*reader) );
2806 return E_OUTOFMEMORY;
2808 reader->IVBSAXXMLReader_iface.lpVtbl = &saxreader_vtbl;
2809 reader->ISAXXMLReader_iface.lpVtbl = &isaxreader_vtbl;
2811 reader->contentHandler = NULL;
2812 reader->vbcontentHandler = NULL;
2813 reader->errorHandler = NULL;
2814 reader->vberrorHandler = NULL;
2815 reader->lexicalHandler = NULL;
2816 reader->vblexicalHandler = NULL;
2817 reader->declHandler = NULL;
2818 reader->vbdeclHandler = NULL;
2819 reader->isParsing = FALSE;
2821 memset(&reader->sax, 0, sizeof(xmlSAXHandler));
2822 reader->sax.initialized = XML_SAX2_MAGIC;
2823 reader->sax.startDocument = libxmlStartDocument;
2824 reader->sax.endDocument = libxmlEndDocument;
2825 reader->sax.startElementNs = libxmlStartElementNS;
2826 reader->sax.endElementNs = libxmlEndElementNS;
2827 reader->sax.characters = libxmlCharacters;
2828 reader->sax.setDocumentLocator = libxmlSetDocumentLocator;
2829 reader->sax.comment = libxmlComment;
2830 reader->sax.error = libxmlFatalError;
2831 reader->sax.fatalError = libxmlFatalError;
2832 reader->sax.cdataBlock = libxmlCDataBlock;
2834 *ppObj = &reader->IVBSAXXMLReader_iface;
2836 TRACE("returning iface %p\n", *ppObj);
2843 HRESULT SAXXMLReader_create(IUnknown *pUnkOuter, LPVOID *ppObj)
2845 MESSAGE("This program tried to use a SAX XML Reader object, but\n"
2846 "libxml2 support was not present at compile time.\n");