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
37 #include "wine/debug.h"
39 #include "msxml_private.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
45 #include <libxml/SAX2.h>
46 #include <libxml/parserInternals.h>
48 typedef struct _saxreader
50 IVBSAXXMLReader IVBSAXXMLReader_iface;
51 ISAXXMLReader ISAXXMLReader_iface;
53 struct ISAXContentHandler *contentHandler;
54 struct IVBSAXContentHandler *vbcontentHandler;
55 struct ISAXErrorHandler *errorHandler;
56 struct IVBSAXErrorHandler *vberrorHandler;
57 struct ISAXLexicalHandler *lexicalHandler;
58 struct IVBSAXLexicalHandler *vblexicalHandler;
59 struct ISAXDeclHandler *declHandler;
60 struct IVBSAXDeclHandler *vbdeclHandler;
65 typedef struct _saxlocator
67 IVBSAXLocator IVBSAXLocator_iface;
68 ISAXLocator ISAXLocator_iface;
72 xmlParserCtxtPtr pParserCtxt;
86 typedef struct _saxattributes
88 IVBSAXAttributes IVBSAXAttributes_iface;
89 ISAXAttributes ISAXAttributes_iface;
98 static inline saxreader *impl_from_IVBSAXXMLReader( IVBSAXXMLReader *iface )
100 return CONTAINING_RECORD(iface, saxreader, IVBSAXXMLReader_iface);
103 static inline saxreader *impl_from_ISAXXMLReader( ISAXXMLReader *iface )
105 return CONTAINING_RECORD(iface, saxreader, ISAXXMLReader_iface);
108 static inline saxlocator *impl_from_IVBSAXLocator( IVBSAXLocator *iface )
110 return CONTAINING_RECORD(iface, saxlocator, IVBSAXLocator_iface);
113 static inline saxlocator *impl_from_ISAXLocator( ISAXLocator *iface )
115 return CONTAINING_RECORD(iface, saxlocator, ISAXLocator_iface);
118 static inline saxattributes *impl_from_IVBSAXAttributes( IVBSAXAttributes *iface )
120 return CONTAINING_RECORD(iface, saxattributes, IVBSAXAttributes_iface);
123 static inline saxattributes *impl_from_ISAXAttributes( ISAXAttributes *iface )
125 return CONTAINING_RECORD(iface, saxattributes, ISAXAttributes_iface);
128 static inline BOOL has_content_handler(const saxlocator *locator)
130 return (locator->vbInterface && locator->saxreader->vbcontentHandler) ||
131 (!locator->vbInterface && locator->saxreader->contentHandler);
134 static inline BOOL has_error_handler(const saxlocator *locator)
136 return (locator->vbInterface && locator->saxreader->vberrorHandler) ||
137 (!locator->vbInterface && locator->saxreader->errorHandler);
140 static HRESULT namespacePush(saxlocator *locator, int ns)
142 if(locator->nsStackLast>=locator->nsStackSize)
146 new_stack = HeapReAlloc(GetProcessHeap(), 0,
147 locator->nsStack, sizeof(int)*locator->nsStackSize*2);
148 if(!new_stack) return E_OUTOFMEMORY;
149 locator->nsStack = new_stack;
150 locator->nsStackSize *= 2;
152 locator->nsStack[locator->nsStackLast++] = ns;
157 static int namespacePop(saxlocator *locator)
159 if(locator->nsStackLast == 0) return 0;
160 return locator->nsStack[--locator->nsStackLast];
163 static BSTR bstr_from_xmlCharN(const xmlChar *buf, int len)
171 dLen = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)buf, len, NULL, 0);
172 if(len != -1) dLen++;
173 bstr = SysAllocStringLen(NULL, dLen-1);
176 MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)buf, len, bstr, dLen);
177 if(len != -1) bstr[dLen-1] = '\0';
182 static BSTR QName_from_xmlChar(const xmlChar *prefix, const xmlChar *name)
187 if(!name) return NULL;
189 if(!prefix || !*prefix)
190 return bstr_from_xmlChar(name);
192 qname = xmlBuildQName(name, prefix, NULL, 0);
193 bstr = bstr_from_xmlChar(qname);
199 static void format_error_message_from_id(saxlocator *This, HRESULT hr)
201 xmlStopParser(This->pParserCtxt);
204 if(has_error_handler(This))
207 if(!FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM,
208 NULL, hr, 0, msg, sizeof(msg), NULL))
210 FIXME("MSXML errors not yet supported.\n");
214 if(This->vbInterface)
216 BSTR bstrMsg = SysAllocString(msg);
217 IVBSAXErrorHandler_fatalError(This->saxreader->vberrorHandler,
218 &This->IVBSAXLocator_iface, &bstrMsg, hr);
219 SysFreeString(bstrMsg);
222 ISAXErrorHandler_fatalError(This->saxreader->errorHandler,
223 &This->ISAXLocator_iface, msg, hr);
227 static void update_position(saxlocator *This, xmlChar *end)
229 if(This->lastCur == NULL)
231 This->lastCur = (xmlChar*)This->pParserCtxt->input->base;
233 This->realColumn = 1;
235 else if(This->lastCur < This->pParserCtxt->input->base)
237 This->lastCur = (xmlChar*)This->pParserCtxt->input->base;
239 This->realColumn = 1;
242 if(This->pParserCtxt->input->cur<This->lastCur)
244 This->lastCur = (xmlChar*)This->pParserCtxt->input->base;
246 This->realColumn = 1;
249 if(!end) end = (xmlChar*)This->pParserCtxt->input->cur;
251 while(This->lastCur < end)
253 if(*(This->lastCur) == '\n')
256 This->realColumn = 1;
258 else if(*(This->lastCur) == '\r' &&
259 (This->lastCur==This->pParserCtxt->input->end ||
260 *(This->lastCur+1)!='\n'))
263 This->realColumn = 1;
265 else This->realColumn++;
269 /* Count multibyte UTF8 encoded characters once */
270 while((*(This->lastCur)&0xC0) == 0x80) This->lastCur++;
273 This->line = This->realLine;
274 This->column = This->realColumn;
277 /*** IVBSAXAttributes interface ***/
278 /*** IUnknown methods ***/
279 static HRESULT WINAPI ivbsaxattributes_QueryInterface(
280 IVBSAXAttributes* iface,
284 saxattributes *This = impl_from_IVBSAXAttributes(iface);
286 TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
290 if (IsEqualGUID(riid, &IID_IUnknown) ||
291 IsEqualGUID(riid, &IID_IDispatch) ||
292 IsEqualGUID(riid, &IID_IVBSAXAttributes))
298 FIXME("interface %s not implemented\n", debugstr_guid(riid));
299 return E_NOINTERFACE;
302 IVBSAXAttributes_AddRef(iface);
307 static ULONG WINAPI ivbsaxattributes_AddRef(IVBSAXAttributes* iface)
309 saxattributes *This = impl_from_IVBSAXAttributes(iface);
310 return ISAXAttributes_AddRef(&This->ISAXAttributes_iface);
313 static ULONG WINAPI ivbsaxattributes_Release(IVBSAXAttributes* iface)
315 saxattributes *This = impl_from_IVBSAXAttributes(iface);
316 return ISAXAttributes_Release(&This->ISAXAttributes_iface);
319 /*** IDispatch methods ***/
320 static HRESULT WINAPI ivbsaxattributes_GetTypeInfoCount( IVBSAXAttributes *iface, UINT* pctinfo )
322 saxattributes *This = impl_from_IVBSAXAttributes( iface );
324 TRACE("(%p)->(%p)\n", This, pctinfo);
331 static HRESULT WINAPI ivbsaxattributes_GetTypeInfo(
332 IVBSAXAttributes *iface,
333 UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo )
335 saxattributes *This = impl_from_IVBSAXAttributes( iface );
338 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
340 hr = get_typeinfo(IVBSAXAttributes_tid, ppTInfo);
345 static HRESULT WINAPI ivbsaxattributes_GetIDsOfNames(
346 IVBSAXAttributes *iface,
353 saxattributes *This = impl_from_IVBSAXAttributes( iface );
357 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
360 if(!rgszNames || cNames == 0 || !rgDispId)
363 hr = get_typeinfo(IVBSAXAttributes_tid, &typeinfo);
366 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
367 ITypeInfo_Release(typeinfo);
373 static HRESULT WINAPI ivbsaxattributes_Invoke(
374 IVBSAXAttributes *iface,
379 DISPPARAMS* pDispParams,
381 EXCEPINFO* pExcepInfo,
384 saxattributes *This = impl_from_IVBSAXAttributes( iface );
388 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
389 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
391 hr = get_typeinfo(IVBSAXAttributes_tid, &typeinfo);
394 hr = ITypeInfo_Invoke(typeinfo, &This->IVBSAXAttributes_iface, dispIdMember, wFlags,
395 pDispParams, pVarResult, pExcepInfo, puArgErr);
396 ITypeInfo_Release(typeinfo);
402 /*** IVBSAXAttributes methods ***/
403 static HRESULT WINAPI ivbsaxattributes_get_length(
404 IVBSAXAttributes* iface,
407 saxattributes *This = impl_from_IVBSAXAttributes( iface );
408 return ISAXAttributes_getLength(&This->ISAXAttributes_iface, nLength);
411 static HRESULT WINAPI ivbsaxattributes_getURI(
412 IVBSAXAttributes* iface,
417 saxattributes *This = impl_from_IVBSAXAttributes( iface );
418 return ISAXAttributes_getURI(&This->ISAXAttributes_iface, nIndex, (const WCHAR**)uri, &len);
421 static HRESULT WINAPI ivbsaxattributes_getLocalName(
422 IVBSAXAttributes* iface,
427 saxattributes *This = impl_from_IVBSAXAttributes( iface );
428 return ISAXAttributes_getLocalName(&This->ISAXAttributes_iface, nIndex,
429 (const WCHAR**)localName, &len);
432 static HRESULT WINAPI ivbsaxattributes_getQName(
433 IVBSAXAttributes* iface,
438 saxattributes *This = impl_from_IVBSAXAttributes( iface );
439 return ISAXAttributes_getQName(&This->ISAXAttributes_iface, nIndex, (const WCHAR**)QName, &len);
442 static HRESULT WINAPI ivbsaxattributes_getIndexFromName(
443 IVBSAXAttributes* iface,
448 saxattributes *This = impl_from_IVBSAXAttributes( iface );
449 return ISAXAttributes_getIndexFromName(&This->ISAXAttributes_iface, uri, SysStringLen(uri),
450 localName, SysStringLen(localName), index);
453 static HRESULT WINAPI ivbsaxattributes_getIndexFromQName(
454 IVBSAXAttributes* iface,
458 saxattributes *This = impl_from_IVBSAXAttributes( iface );
459 return ISAXAttributes_getIndexFromQName(&This->ISAXAttributes_iface, QName,
460 SysStringLen(QName), index);
463 static HRESULT WINAPI ivbsaxattributes_getType(
464 IVBSAXAttributes* iface,
469 saxattributes *This = impl_from_IVBSAXAttributes( iface );
470 return ISAXAttributes_getType(&This->ISAXAttributes_iface, nIndex, (const WCHAR**)type, &len);
473 static HRESULT WINAPI ivbsaxattributes_getTypeFromName(
474 IVBSAXAttributes* iface,
480 saxattributes *This = impl_from_IVBSAXAttributes( iface );
481 return ISAXAttributes_getTypeFromName(&This->ISAXAttributes_iface, uri, SysStringLen(uri),
482 localName, SysStringLen(localName), (const WCHAR**)type, &len);
485 static HRESULT WINAPI ivbsaxattributes_getTypeFromQName(
486 IVBSAXAttributes* iface,
491 saxattributes *This = impl_from_IVBSAXAttributes( iface );
492 return ISAXAttributes_getTypeFromQName(&This->ISAXAttributes_iface, QName, SysStringLen(QName),
493 (const WCHAR**)type, &len);
496 static HRESULT WINAPI ivbsaxattributes_getValue(
497 IVBSAXAttributes* iface,
502 saxattributes *This = impl_from_IVBSAXAttributes( iface );
503 return ISAXAttributes_getValue(&This->ISAXAttributes_iface, nIndex, (const WCHAR**)value, &len);
506 static HRESULT WINAPI ivbsaxattributes_getValueFromName(
507 IVBSAXAttributes* iface,
513 saxattributes *This = impl_from_IVBSAXAttributes( iface );
514 return ISAXAttributes_getValueFromName(&This->ISAXAttributes_iface, uri, SysStringLen(uri),
515 localName, SysStringLen(localName), (const WCHAR**)value, &len);
518 static HRESULT WINAPI ivbsaxattributes_getValueFromQName(
519 IVBSAXAttributes* iface,
524 saxattributes *This = impl_from_IVBSAXAttributes( iface );
525 return ISAXAttributes_getValueFromQName(&This->ISAXAttributes_iface, QName,
526 SysStringLen(QName), (const WCHAR**)value, &len);
529 static const struct IVBSAXAttributesVtbl ivbsaxattributes_vtbl =
531 ivbsaxattributes_QueryInterface,
532 ivbsaxattributes_AddRef,
533 ivbsaxattributes_Release,
534 ivbsaxattributes_GetTypeInfoCount,
535 ivbsaxattributes_GetTypeInfo,
536 ivbsaxattributes_GetIDsOfNames,
537 ivbsaxattributes_Invoke,
538 ivbsaxattributes_get_length,
539 ivbsaxattributes_getURI,
540 ivbsaxattributes_getLocalName,
541 ivbsaxattributes_getQName,
542 ivbsaxattributes_getIndexFromName,
543 ivbsaxattributes_getIndexFromQName,
544 ivbsaxattributes_getType,
545 ivbsaxattributes_getTypeFromName,
546 ivbsaxattributes_getTypeFromQName,
547 ivbsaxattributes_getValue,
548 ivbsaxattributes_getValueFromName,
549 ivbsaxattributes_getValueFromQName
552 /*** ISAXAttributes interface ***/
553 /*** IUnknown methods ***/
554 static HRESULT WINAPI isaxattributes_QueryInterface(
555 ISAXAttributes* iface,
559 saxattributes *This = impl_from_ISAXAttributes(iface);
561 TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
565 if (IsEqualGUID(riid, &IID_IUnknown) ||
566 IsEqualGUID(riid, &IID_ISAXAttributes))
572 FIXME("interface %s not implemented\n", debugstr_guid(riid));
573 return E_NOINTERFACE;
576 ISAXAttributes_AddRef(iface);
581 static ULONG WINAPI isaxattributes_AddRef(ISAXAttributes* iface)
583 saxattributes *This = impl_from_ISAXAttributes(iface);
585 return InterlockedIncrement(&This->ref);
588 static ULONG WINAPI isaxattributes_Release(ISAXAttributes* iface)
590 saxattributes *This = impl_from_ISAXAttributes(iface);
595 ref = InterlockedDecrement(&This->ref);
599 for(index=0; index<This->nb_attributes; index++)
601 SysFreeString(This->szLocalname[index]);
602 SysFreeString(This->szURI[index]);
603 SysFreeString(This->szValue[index]);
604 SysFreeString(This->szQName[index]);
607 heap_free(This->szLocalname);
608 heap_free(This->szURI);
609 heap_free(This->szValue);
610 heap_free(This->szQName);
618 /*** ISAXAttributes methods ***/
619 static HRESULT WINAPI isaxattributes_getLength(
620 ISAXAttributes* iface,
623 saxattributes *This = impl_from_ISAXAttributes( iface );
625 *length = This->nb_attributes;
626 TRACE("Length set to %d\n", *length);
630 static HRESULT WINAPI isaxattributes_getURI(
631 ISAXAttributes* iface,
636 saxattributes *This = impl_from_ISAXAttributes( iface );
637 TRACE("(%p)->(%d)\n", This, nIndex);
639 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG;
640 if(!pUrl || !pUriSize) return E_POINTER;
642 *pUriSize = SysStringLen(This->szURI[nIndex]);
643 *pUrl = This->szURI[nIndex];
648 static HRESULT WINAPI isaxattributes_getLocalName(
649 ISAXAttributes* iface,
651 const WCHAR **pLocalName,
652 int *pLocalNameLength)
654 saxattributes *This = impl_from_ISAXAttributes( iface );
655 TRACE("(%p)->(%d)\n", This, nIndex);
657 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG;
658 if(!pLocalName || !pLocalNameLength) return E_POINTER;
660 *pLocalNameLength = SysStringLen(This->szLocalname[nIndex]);
661 *pLocalName = This->szLocalname[nIndex];
666 static HRESULT WINAPI isaxattributes_getQName(
667 ISAXAttributes* iface,
669 const WCHAR **pQName,
672 saxattributes *This = impl_from_ISAXAttributes( iface );
673 TRACE("(%p)->(%d)\n", This, nIndex);
675 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG;
676 if(!pQName || !pQNameLength) return E_POINTER;
678 *pQNameLength = SysStringLen(This->szQName[nIndex]);
679 *pQName = This->szQName[nIndex];
684 static HRESULT WINAPI isaxattributes_getName(
685 ISAXAttributes* iface,
689 const WCHAR **pLocalName,
691 const WCHAR **pQName,
694 saxattributes *This = impl_from_ISAXAttributes( iface );
695 TRACE("(%p)->(%d)\n", This, nIndex);
697 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG;
698 if(!pUri || !pUriLength || !pLocalName || !pLocalNameSize
699 || !pQName || !pQNameLength) return E_POINTER;
701 *pUriLength = SysStringLen(This->szURI[nIndex]);
702 *pUri = This->szURI[nIndex];
703 *pLocalNameSize = SysStringLen(This->szLocalname[nIndex]);
704 *pLocalName = This->szLocalname[nIndex];
705 *pQNameLength = SysStringLen(This->szQName[nIndex]);
706 *pQName = This->szQName[nIndex];
711 static HRESULT WINAPI isaxattributes_getIndexFromName(
712 ISAXAttributes* iface,
715 const WCHAR *pLocalName,
719 saxattributes *This = impl_from_ISAXAttributes( iface );
721 TRACE("(%p)->(%s, %d, %s, %d)\n", This, debugstr_w(pUri), cUriLength,
722 debugstr_w(pLocalName), cocalNameLength);
724 if(!pUri || !pLocalName || !index) return E_POINTER;
726 for(i=0; i<This->nb_attributes; i++)
728 if(cUriLength!=SysStringLen(This->szURI[i])
729 || cocalNameLength!=SysStringLen(This->szLocalname[i]))
731 if(cUriLength && memcmp(pUri, This->szURI[i],
732 sizeof(WCHAR)*cUriLength))
734 if(cocalNameLength && memcmp(pLocalName, This->szLocalname[i],
735 sizeof(WCHAR)*cocalNameLength))
745 static HRESULT WINAPI isaxattributes_getIndexFromQName(
746 ISAXAttributes* iface,
751 saxattributes *This = impl_from_ISAXAttributes( iface );
753 TRACE("(%p)->(%s, %d)\n", This, debugstr_w(pQName), nQNameLength);
755 if(!pQName || !index) return E_POINTER;
756 if(!nQNameLength) return E_INVALIDARG;
758 for(i=0; i<This->nb_attributes; i++)
760 if(nQNameLength!=SysStringLen(This->szQName[i])) continue;
761 if(memcmp(pQName, This->szQName, sizeof(WCHAR)*nQNameLength)) continue;
770 static HRESULT WINAPI isaxattributes_getType(
771 ISAXAttributes* iface,
776 saxattributes *This = impl_from_ISAXAttributes( iface );
778 FIXME("(%p)->(%d) stub\n", This, nIndex);
782 static HRESULT WINAPI isaxattributes_getTypeFromName(
783 ISAXAttributes* iface,
786 const WCHAR *pLocalName,
791 saxattributes *This = impl_from_ISAXAttributes( iface );
793 FIXME("(%p)->(%s, %d, %s, %d) stub\n", This, debugstr_w(pUri), nUri,
794 debugstr_w(pLocalName), nLocalName);
798 static HRESULT WINAPI isaxattributes_getTypeFromQName(
799 ISAXAttributes* iface,
805 saxattributes *This = impl_from_ISAXAttributes( iface );
807 FIXME("(%p)->(%s, %d) stub\n", This, debugstr_w(pQName), nQName);
811 static HRESULT WINAPI isaxattributes_getValue(
812 ISAXAttributes* iface,
814 const WCHAR **pValue,
817 saxattributes *This = impl_from_ISAXAttributes( iface );
818 TRACE("(%p)->(%d)\n", This, nIndex);
820 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG;
821 if(!pValue || !nValue) return E_POINTER;
823 *nValue = SysStringLen(This->szValue[nIndex]);
824 *pValue = This->szValue[nIndex];
829 static HRESULT WINAPI isaxattributes_getValueFromName(
830 ISAXAttributes* iface,
833 const WCHAR *pLocalName,
835 const WCHAR **pValue,
840 saxattributes *This = impl_from_ISAXAttributes( iface );
841 TRACE("(%p)->(%s, %d, %s, %d)\n", This, debugstr_w(pUri), nUri,
842 debugstr_w(pLocalName), nLocalName);
844 hr = ISAXAttributes_getIndexFromName(iface,
845 pUri, nUri, pLocalName, nLocalName, &index);
846 if(hr==S_OK) hr = ISAXAttributes_getValue(iface, index, pValue, nValue);
851 static HRESULT WINAPI isaxattributes_getValueFromQName(
852 ISAXAttributes* iface,
855 const WCHAR **pValue,
860 saxattributes *This = impl_from_ISAXAttributes( iface );
861 TRACE("(%p)->(%s, %d)\n", This, debugstr_w(pQName), nQName);
863 hr = ISAXAttributes_getIndexFromQName(iface, pQName, nQName, &index);
864 if(hr==S_OK) hr = ISAXAttributes_getValue(iface, index, pValue, nValue);
869 static const struct ISAXAttributesVtbl isaxattributes_vtbl =
871 isaxattributes_QueryInterface,
872 isaxattributes_AddRef,
873 isaxattributes_Release,
874 isaxattributes_getLength,
875 isaxattributes_getURI,
876 isaxattributes_getLocalName,
877 isaxattributes_getQName,
878 isaxattributes_getName,
879 isaxattributes_getIndexFromName,
880 isaxattributes_getIndexFromQName,
881 isaxattributes_getType,
882 isaxattributes_getTypeFromName,
883 isaxattributes_getTypeFromQName,
884 isaxattributes_getValue,
885 isaxattributes_getValueFromName,
886 isaxattributes_getValueFromQName
889 static HRESULT SAXAttributes_create(saxattributes **attr,
890 int nb_namespaces, const xmlChar **xmlNamespaces,
891 int nb_attributes, const xmlChar **xmlAttributes)
893 saxattributes *attributes;
895 static const xmlChar xmlns[] = "xmlns";
897 attributes = heap_alloc(sizeof(*attributes));
899 return E_OUTOFMEMORY;
901 attributes->IVBSAXAttributes_iface.lpVtbl = &ivbsaxattributes_vtbl;
902 attributes->ISAXAttributes_iface.lpVtbl = &isaxattributes_vtbl;
905 attributes->nb_attributes = nb_namespaces+nb_attributes;
907 attributes->szLocalname = heap_alloc(sizeof(BSTR)*attributes->nb_attributes);
908 attributes->szURI = heap_alloc(sizeof(BSTR)*attributes->nb_attributes);
909 attributes->szValue = heap_alloc(sizeof(BSTR)*attributes->nb_attributes);
910 attributes->szQName = heap_alloc(sizeof(BSTR)*attributes->nb_attributes);
912 if(!attributes->szLocalname || !attributes->szURI
913 || !attributes->szValue || !attributes->szQName)
915 heap_free(attributes->szLocalname);
916 heap_free(attributes->szURI);
917 heap_free(attributes->szValue);
918 heap_free(attributes->szQName);
919 heap_free(attributes);
923 for(index=0; index<nb_namespaces; index++)
925 attributes->szLocalname[index] = SysAllocStringLen(NULL, 0);
926 attributes->szURI[index] = SysAllocStringLen(NULL, 0);
927 attributes->szValue[index] = bstr_from_xmlChar(xmlNamespaces[2*index+1]);
928 attributes->szQName[index] = QName_from_xmlChar(xmlns, xmlNamespaces[2*index]);
931 for(index=0; index<nb_attributes; index++)
933 attributes->szLocalname[nb_namespaces+index] =
934 bstr_from_xmlChar(xmlAttributes[index*5]);
935 attributes->szURI[nb_namespaces+index] =
936 bstr_from_xmlChar(xmlAttributes[index*5+2]);
937 attributes->szValue[nb_namespaces+index] =
938 bstr_from_xmlCharN(xmlAttributes[index*5+3],
939 xmlAttributes[index*5+4]-xmlAttributes[index*5+3]);
940 attributes->szQName[nb_namespaces+index] =
941 QName_from_xmlChar(xmlAttributes[index*5+1], xmlAttributes[index*5]);
946 TRACE("returning %p\n", *attr);
951 /*** LibXML callbacks ***/
952 static void libxmlStartDocument(void *ctx)
954 saxlocator *This = ctx;
957 if(has_content_handler(This))
959 if(This->vbInterface)
960 hr = IVBSAXContentHandler_startDocument(This->saxreader->vbcontentHandler);
962 hr = ISAXContentHandler_startDocument(This->saxreader->contentHandler);
965 format_error_message_from_id(This, hr);
968 update_position(This, NULL);
971 static void libxmlEndDocument(void *ctx)
973 saxlocator *This = ctx;
979 if(This->ret != S_OK) return;
981 if(has_content_handler(This))
983 if(This->vbInterface)
984 hr = IVBSAXContentHandler_endDocument(This->saxreader->vbcontentHandler);
986 hr = ISAXContentHandler_endDocument(This->saxreader->contentHandler);
989 format_error_message_from_id(This, hr);
993 static void libxmlStartElementNS(
995 const xmlChar *localname,
996 const xmlChar *prefix,
999 const xmlChar **namespaces,
1002 const xmlChar **attributes)
1004 BSTR NamespaceUri, LocalName, QName, Prefix, Uri;
1005 saxlocator *This = ctx;
1007 saxattributes *attr;
1010 if(*(This->pParserCtxt->input->cur) == '/')
1011 update_position(This, (xmlChar*)This->pParserCtxt->input->cur+2);
1013 update_position(This, (xmlChar*)This->pParserCtxt->input->cur+1);
1015 hr = namespacePush(This, nb_namespaces);
1016 if(hr==S_OK && has_content_handler(This))
1018 for(index=0; index<nb_namespaces; index++)
1020 Prefix = bstr_from_xmlChar(namespaces[2*index]);
1021 Uri = bstr_from_xmlChar(namespaces[2*index+1]);
1023 if(This->vbInterface)
1024 hr = IVBSAXContentHandler_startPrefixMapping(
1025 This->saxreader->vbcontentHandler,
1028 hr = ISAXContentHandler_startPrefixMapping(
1029 This->saxreader->contentHandler,
1030 Prefix, SysStringLen(Prefix),
1031 Uri, SysStringLen(Uri));
1033 SysFreeString(Prefix);
1038 format_error_message_from_id(This, hr);
1043 NamespaceUri = bstr_from_xmlChar(URI);
1044 LocalName = bstr_from_xmlChar(localname);
1045 QName = QName_from_xmlChar(prefix, localname);
1047 hr = SAXAttributes_create(&attr, nb_namespaces, namespaces, nb_attributes, attributes);
1050 if(This->vbInterface)
1051 hr = IVBSAXContentHandler_startElement(This->saxreader->vbcontentHandler,
1052 &NamespaceUri, &LocalName, &QName, &attr->IVBSAXAttributes_iface);
1054 hr = ISAXContentHandler_startElement(This->saxreader->contentHandler, NamespaceUri,
1055 SysStringLen(NamespaceUri), LocalName, SysStringLen(LocalName), QName,
1056 SysStringLen(QName), &attr->ISAXAttributes_iface);
1058 ISAXAttributes_Release(&attr->ISAXAttributes_iface);
1061 SysFreeString(NamespaceUri);
1062 SysFreeString(LocalName);
1063 SysFreeString(QName);
1067 format_error_message_from_id(This, hr);
1070 static void libxmlEndElementNS(
1072 const xmlChar *localname,
1073 const xmlChar *prefix,
1076 BSTR NamespaceUri, LocalName, QName, Prefix;
1077 saxlocator *This = ctx;
1082 end = (xmlChar*)This->pParserCtxt->input->cur;
1083 if(*(end-1) != '>' || *(end-2) != '/')
1084 while(end-2>=This->pParserCtxt->input->base
1085 && *(end-2)!='<' && *(end-1)!='/') end--;
1087 update_position(This, end);
1089 nsNr = namespacePop(This);
1091 if(has_content_handler(This))
1093 NamespaceUri = bstr_from_xmlChar(URI);
1094 LocalName = bstr_from_xmlChar(localname);
1095 QName = QName_from_xmlChar(prefix, localname);
1097 if(This->vbInterface)
1098 hr = IVBSAXContentHandler_endElement(
1099 This->saxreader->vbcontentHandler,
1100 &NamespaceUri, &LocalName, &QName);
1102 hr = ISAXContentHandler_endElement(
1103 This->saxreader->contentHandler,
1104 NamespaceUri, SysStringLen(NamespaceUri),
1105 LocalName, SysStringLen(LocalName),
1106 QName, SysStringLen(QName));
1108 SysFreeString(NamespaceUri);
1109 SysFreeString(LocalName);
1110 SysFreeString(QName);
1114 format_error_message_from_id(This, hr);
1118 for(index=This->pParserCtxt->nsNr-2;
1119 index>=This->pParserCtxt->nsNr-nsNr*2; index-=2)
1121 Prefix = bstr_from_xmlChar(This->pParserCtxt->nsTab[index]);
1123 if(This->vbInterface)
1124 hr = IVBSAXContentHandler_endPrefixMapping(
1125 This->saxreader->vbcontentHandler, &Prefix);
1127 hr = ISAXContentHandler_endPrefixMapping(
1128 This->saxreader->contentHandler,
1129 Prefix, SysStringLen(Prefix));
1131 SysFreeString(Prefix);
1135 format_error_message_from_id(This, hr);
1142 update_position(This, NULL);
1145 static void libxmlCharacters(
1150 saxlocator *This = ctx;
1155 BOOL lastEvent = FALSE;
1157 if(!(has_content_handler(This))) return;
1160 if(*(ch-1)=='\r') cur--;
1163 if(ch<This->pParserCtxt->input->base || ch>This->pParserCtxt->input->end)
1168 while(end-ch<len && *end!='\r') end++;
1175 if(!lastEvent) *end = '\n';
1177 Chars = bstr_from_xmlCharN(cur, end-cur+1);
1178 if(This->vbInterface)
1179 hr = IVBSAXContentHandler_characters(
1180 This->saxreader->vbcontentHandler, &Chars);
1182 hr = ISAXContentHandler_characters(
1183 This->saxreader->contentHandler,
1184 Chars, SysStringLen(Chars));
1185 SysFreeString(Chars);
1189 format_error_message_from_id(This, hr);
1193 This->column += end-cur+1;
1207 if(end-ch == len) break;
1210 if(ch<This->pParserCtxt->input->base || ch>This->pParserCtxt->input->end)
1211 This->column = This->realColumn
1212 +This->pParserCtxt->input->cur-This->lastCur;
1215 static void libxmlSetDocumentLocator(
1217 xmlSAXLocatorPtr loc)
1219 saxlocator *This = ctx;
1222 if(has_content_handler(This))
1224 if(This->vbInterface)
1225 hr = IVBSAXContentHandler_putref_documentLocator(This->saxreader->vbcontentHandler,
1226 &This->IVBSAXLocator_iface);
1228 hr = ISAXContentHandler_putDocumentLocator(This->saxreader->contentHandler,
1229 &This->ISAXLocator_iface);
1233 format_error_message_from_id(This, hr);
1236 static void libxmlComment(void *ctx, const xmlChar *value)
1238 saxlocator *This = ctx;
1241 xmlChar *beg = (xmlChar*)This->pParserCtxt->input->cur;
1243 while(beg-4>=This->pParserCtxt->input->base
1244 && memcmp(beg-4, "<!--", sizeof(char[4]))) beg--;
1245 update_position(This, beg);
1247 if(!This->vbInterface && !This->saxreader->lexicalHandler) return;
1248 if(This->vbInterface && !This->saxreader->vblexicalHandler) return;
1250 bValue = bstr_from_xmlChar(value);
1252 if(This->vbInterface)
1253 hr = IVBSAXLexicalHandler_comment(
1254 This->saxreader->vblexicalHandler, &bValue);
1256 hr = ISAXLexicalHandler_comment(
1257 This->saxreader->lexicalHandler,
1258 bValue, SysStringLen(bValue));
1260 SysFreeString(bValue);
1263 format_error_message_from_id(This, hr);
1265 update_position(This, NULL);
1268 static void libxmlFatalError(void *ctx, const char *msg, ...)
1270 saxlocator *This = ctx;
1276 va_start(args, msg);
1277 vsprintf(message, msg, args);
1280 len = MultiByteToWideChar(CP_UNIXCP, 0, message, -1, NULL, 0);
1281 error = heap_alloc(sizeof(WCHAR)*len);
1284 MultiByteToWideChar(CP_UNIXCP, 0, message, -1, error, len);
1285 TRACE("fatal error for %p: %s\n", This, debugstr_w(error));
1288 if(!has_error_handler(This))
1290 xmlStopParser(This->pParserCtxt);
1296 FIXME("Error handling is not compatible.\n");
1298 if(This->vbInterface)
1300 BSTR bstrError = SysAllocString(error);
1301 IVBSAXErrorHandler_fatalError(This->saxreader->vberrorHandler, &This->IVBSAXLocator_iface,
1302 &bstrError, E_FAIL);
1303 SysFreeString(bstrError);
1306 ISAXErrorHandler_fatalError(This->saxreader->errorHandler, &This->ISAXLocator_iface,
1311 xmlStopParser(This->pParserCtxt);
1315 static void libxmlCDataBlock(void *ctx, const xmlChar *value, int len)
1317 saxlocator *This = ctx;
1319 xmlChar *beg = (xmlChar*)This->pParserCtxt->input->cur-len;
1323 BOOL lastEvent = FALSE, change;
1325 while(beg-9>=This->pParserCtxt->input->base
1326 && memcmp(beg-9, "<![CDATA[", sizeof(char[9]))) beg--;
1327 update_position(This, beg);
1329 if(This->vbInterface && This->saxreader->vblexicalHandler)
1330 hr = IVBSAXLexicalHandler_startCDATA(This->saxreader->vblexicalHandler);
1331 if(!This->vbInterface && This->saxreader->lexicalHandler)
1332 hr = ISAXLexicalHandler_startCDATA(This->saxreader->lexicalHandler);
1336 format_error_message_from_id(This, hr);
1340 realLen = This->pParserCtxt->input->cur-beg-3;
1346 while(end-beg<realLen && *end!='\r') end++;
1347 if(end-beg==realLen)
1352 else if(end-beg==realLen-1 && *end=='\r' && *(end+1)=='\n')
1355 if(*end == '\r') change = TRUE;
1356 else change = FALSE;
1358 if(change) *end = '\n';
1360 if(has_content_handler(This))
1362 Chars = bstr_from_xmlCharN(cur, end-cur+1);
1363 if(This->vbInterface)
1364 hr = IVBSAXContentHandler_characters(
1365 This->saxreader->vbcontentHandler, &Chars);
1367 hr = ISAXContentHandler_characters(
1368 This->saxreader->contentHandler,
1369 Chars, SysStringLen(Chars));
1370 SysFreeString(Chars);
1373 if(change) *end = '\r';
1378 This->column += end-cur+2;
1383 if(This->vbInterface && This->saxreader->vblexicalHandler)
1384 hr = IVBSAXLexicalHandler_endCDATA(This->saxreader->vblexicalHandler);
1385 if(!This->vbInterface && This->saxreader->lexicalHandler)
1386 hr = ISAXLexicalHandler_endCDATA(This->saxreader->lexicalHandler);
1389 format_error_message_from_id(This, hr);
1391 This->column += 4+end-cur;
1394 /*** IVBSAXLocator interface ***/
1395 /*** IUnknown methods ***/
1396 static HRESULT WINAPI ivbsaxlocator_QueryInterface(IVBSAXLocator* iface, REFIID riid, void **ppvObject)
1398 saxlocator *This = impl_from_IVBSAXLocator( iface );
1400 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject);
1404 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
1405 IsEqualGUID( riid, &IID_IDispatch) ||
1406 IsEqualGUID( riid, &IID_IVBSAXLocator ))
1412 FIXME("interface %s not implemented\n", debugstr_guid(riid));
1413 return E_NOINTERFACE;
1416 IVBSAXLocator_AddRef( iface );
1421 static ULONG WINAPI ivbsaxlocator_AddRef(IVBSAXLocator* iface)
1423 saxlocator *This = impl_from_IVBSAXLocator( iface );
1424 TRACE("%p\n", This );
1425 return InterlockedIncrement( &This->ref );
1428 static ULONG WINAPI ivbsaxlocator_Release(
1429 IVBSAXLocator* iface)
1431 saxlocator *This = impl_from_IVBSAXLocator( iface );
1432 return ISAXLocator_Release((ISAXLocator*)&This->IVBSAXLocator_iface);
1435 /*** IDispatch methods ***/
1436 static HRESULT WINAPI ivbsaxlocator_GetTypeInfoCount( IVBSAXLocator *iface, UINT* pctinfo )
1438 saxlocator *This = impl_from_IVBSAXLocator( iface );
1440 TRACE("(%p)->(%p)\n", This, pctinfo);
1447 static HRESULT WINAPI ivbsaxlocator_GetTypeInfo(
1448 IVBSAXLocator *iface,
1449 UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo )
1451 saxlocator *This = impl_from_IVBSAXLocator( iface );
1454 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
1456 hr = get_typeinfo(IVBSAXLocator_tid, ppTInfo);
1461 static HRESULT WINAPI ivbsaxlocator_GetIDsOfNames(
1462 IVBSAXLocator *iface,
1464 LPOLESTR* rgszNames,
1469 saxlocator *This = impl_from_IVBSAXLocator( iface );
1470 ITypeInfo *typeinfo;
1473 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
1476 if(!rgszNames || cNames == 0 || !rgDispId)
1477 return E_INVALIDARG;
1479 hr = get_typeinfo(IVBSAXLocator_tid, &typeinfo);
1482 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
1483 ITypeInfo_Release(typeinfo);
1489 static HRESULT WINAPI ivbsaxlocator_Invoke(
1490 IVBSAXLocator *iface,
1491 DISPID dispIdMember,
1495 DISPPARAMS* pDispParams,
1496 VARIANT* pVarResult,
1497 EXCEPINFO* pExcepInfo,
1500 saxlocator *This = impl_from_IVBSAXLocator( iface );
1501 ITypeInfo *typeinfo;
1504 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1505 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1507 hr = get_typeinfo(IVBSAXLocator_tid, &typeinfo);
1510 hr = ITypeInfo_Invoke(typeinfo, &This->IVBSAXLocator_iface, dispIdMember, wFlags,
1511 pDispParams, pVarResult, pExcepInfo, puArgErr);
1512 ITypeInfo_Release(typeinfo);
1518 /*** IVBSAXLocator methods ***/
1519 static HRESULT WINAPI ivbsaxlocator_get_columnNumber(
1520 IVBSAXLocator* iface,
1523 saxlocator *This = impl_from_IVBSAXLocator( iface );
1524 return ISAXLocator_getColumnNumber((ISAXLocator*)&This->IVBSAXLocator_iface, pnColumn);
1527 static HRESULT WINAPI ivbsaxlocator_get_lineNumber(
1528 IVBSAXLocator* iface,
1531 saxlocator *This = impl_from_IVBSAXLocator( iface );
1532 return ISAXLocator_getLineNumber((ISAXLocator*)&This->IVBSAXLocator_iface, pnLine);
1535 static HRESULT WINAPI ivbsaxlocator_get_publicId(
1536 IVBSAXLocator* iface,
1539 saxlocator *This = impl_from_IVBSAXLocator( iface );
1540 return ISAXLocator_getPublicId((ISAXLocator*)&This->IVBSAXLocator_iface,
1541 (const WCHAR**)publicId);
1544 static HRESULT WINAPI ivbsaxlocator_get_systemId(
1545 IVBSAXLocator* iface,
1548 saxlocator *This = impl_from_IVBSAXLocator( iface );
1549 return ISAXLocator_getSystemId((ISAXLocator*)&This->IVBSAXLocator_iface,
1550 (const WCHAR**)systemId);
1553 static const struct IVBSAXLocatorVtbl ivbsaxlocator_vtbl =
1555 ivbsaxlocator_QueryInterface,
1556 ivbsaxlocator_AddRef,
1557 ivbsaxlocator_Release,
1558 ivbsaxlocator_GetTypeInfoCount,
1559 ivbsaxlocator_GetTypeInfo,
1560 ivbsaxlocator_GetIDsOfNames,
1561 ivbsaxlocator_Invoke,
1562 ivbsaxlocator_get_columnNumber,
1563 ivbsaxlocator_get_lineNumber,
1564 ivbsaxlocator_get_publicId,
1565 ivbsaxlocator_get_systemId
1568 /*** ISAXLocator interface ***/
1569 /*** IUnknown methods ***/
1570 static HRESULT WINAPI isaxlocator_QueryInterface(ISAXLocator* iface, REFIID riid, void **ppvObject)
1572 saxlocator *This = impl_from_ISAXLocator( iface );
1574 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject );
1578 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
1579 IsEqualGUID( riid, &IID_ISAXLocator ))
1585 FIXME("interface %s not implemented\n", debugstr_guid(riid));
1586 return E_NOINTERFACE;
1589 ISAXLocator_AddRef( iface );
1594 static ULONG WINAPI isaxlocator_AddRef(ISAXLocator* iface)
1596 saxlocator *This = impl_from_ISAXLocator( iface );
1597 TRACE("%p\n", This );
1598 return InterlockedIncrement( &This->ref );
1601 static ULONG WINAPI isaxlocator_Release(
1604 saxlocator *This = impl_from_ISAXLocator( iface );
1607 TRACE("%p\n", This );
1609 ref = InterlockedDecrement( &This->ref );
1612 SysFreeString(This->publicId);
1613 SysFreeString(This->systemId);
1614 heap_free(This->nsStack);
1616 ISAXXMLReader_Release(&This->saxreader->ISAXXMLReader_iface);
1623 /*** ISAXLocator methods ***/
1624 static HRESULT WINAPI isaxlocator_getColumnNumber(
1628 saxlocator *This = impl_from_ISAXLocator( iface );
1630 *pnColumn = This->column;
1634 static HRESULT WINAPI isaxlocator_getLineNumber(
1638 saxlocator *This = impl_from_ISAXLocator( iface );
1640 *pnLine = This->line;
1644 static HRESULT WINAPI isaxlocator_getPublicId(
1646 const WCHAR ** ppwchPublicId)
1649 saxlocator *This = impl_from_ISAXLocator( iface );
1651 SysFreeString(This->publicId);
1653 publicId = bstr_from_xmlChar(xmlSAX2GetPublicId(This->pParserCtxt));
1654 if(SysStringLen(publicId))
1655 This->publicId = (WCHAR*)&publicId;
1658 SysFreeString(publicId);
1659 This->publicId = NULL;
1662 *ppwchPublicId = This->publicId;
1666 static HRESULT WINAPI isaxlocator_getSystemId(
1668 const WCHAR ** ppwchSystemId)
1671 saxlocator *This = impl_from_ISAXLocator( iface );
1673 SysFreeString(This->systemId);
1675 systemId = bstr_from_xmlChar(xmlSAX2GetSystemId(This->pParserCtxt));
1676 if(SysStringLen(systemId))
1677 This->systemId = (WCHAR*)&systemId;
1680 SysFreeString(systemId);
1681 This->systemId = NULL;
1684 *ppwchSystemId = This->systemId;
1688 static const struct ISAXLocatorVtbl isaxlocator_vtbl =
1690 isaxlocator_QueryInterface,
1692 isaxlocator_Release,
1693 isaxlocator_getColumnNumber,
1694 isaxlocator_getLineNumber,
1695 isaxlocator_getPublicId,
1696 isaxlocator_getSystemId
1699 static HRESULT SAXLocator_create(saxreader *reader, saxlocator **ppsaxlocator, BOOL vbInterface)
1701 saxlocator *locator;
1703 locator = heap_alloc( sizeof (*locator) );
1705 return E_OUTOFMEMORY;
1707 locator->IVBSAXLocator_iface.lpVtbl = &ivbsaxlocator_vtbl;
1708 locator->ISAXLocator_iface.lpVtbl = &isaxlocator_vtbl;
1710 locator->vbInterface = vbInterface;
1712 locator->saxreader = reader;
1713 ISAXXMLReader_AddRef(&reader->ISAXXMLReader_iface);
1715 locator->pParserCtxt = NULL;
1716 locator->publicId = NULL;
1717 locator->systemId = NULL;
1718 locator->lastCur = NULL;
1720 locator->column = 0;
1721 locator->ret = S_OK;
1722 locator->nsStackSize = 8;
1723 locator->nsStackLast = 0;
1724 locator->nsStack = heap_alloc(sizeof(int)*locator->nsStackSize);
1725 if(!locator->nsStack)
1727 ISAXXMLReader_Release(&reader->ISAXXMLReader_iface);
1729 return E_OUTOFMEMORY;
1732 *ppsaxlocator = locator;
1734 TRACE("returning %p\n", *ppsaxlocator);
1739 /*** SAXXMLReader internal functions ***/
1740 static HRESULT internal_parseBuffer(saxreader *This, const char *buffer, int size, BOOL vbInterface)
1742 xmlCharEncoding encoding = XML_CHAR_ENCODING_NONE;
1743 xmlChar *enc_name = NULL;
1744 saxlocator *locator;
1747 hr = SAXLocator_create(This, &locator, vbInterface);
1753 const unsigned char *buff = (unsigned char*)buffer;
1755 encoding = xmlDetectCharEncoding((xmlChar*)buffer, 4);
1756 enc_name = (xmlChar*)xmlGetCharEncodingName(encoding);
1757 TRACE("detected encoding: %s\n", enc_name);
1758 /* skip BOM, parser won't switch encodings and so won't skip it on its own */
1759 if ((encoding == XML_CHAR_ENCODING_UTF8) &&
1760 buff[0] == 0xEF && buff[1] == 0xBB && buff[2] == 0xBF)
1767 locator->pParserCtxt = xmlCreateMemoryParserCtxt(buffer, size);
1768 if(!locator->pParserCtxt)
1770 ISAXLocator_Release(&locator->ISAXLocator_iface);
1774 if (encoding == XML_CHAR_ENCODING_UTF8)
1775 locator->pParserCtxt->encoding = xmlStrdup(enc_name);
1777 xmlFree(locator->pParserCtxt->sax);
1778 locator->pParserCtxt->sax = &locator->saxreader->sax;
1779 locator->pParserCtxt->userData = locator;
1781 This->isParsing = TRUE;
1782 if(xmlParseDocument(locator->pParserCtxt) == -1) hr = E_FAIL;
1783 else hr = locator->ret;
1784 This->isParsing = FALSE;
1786 if(locator->pParserCtxt)
1788 locator->pParserCtxt->sax = NULL;
1789 xmlFreeParserCtxt(locator->pParserCtxt);
1790 locator->pParserCtxt = NULL;
1793 ISAXLocator_Release(&locator->ISAXLocator_iface);
1797 static HRESULT internal_parseStream(saxreader *This, IStream *stream, BOOL vbInterface)
1799 saxlocator *locator;
1804 hr = IStream_Read(stream, data, sizeof(data), &dataRead);
1808 hr = SAXLocator_create(This, &locator, vbInterface);
1812 locator->pParserCtxt = xmlCreatePushParserCtxt(
1813 &locator->saxreader->sax, locator,
1814 data, dataRead, NULL);
1815 if(!locator->pParserCtxt)
1817 ISAXLocator_Release(&locator->ISAXLocator_iface);
1821 This->isParsing = TRUE;
1824 hr = IStream_Read(stream, data, sizeof(data), &dataRead);
1828 if(xmlParseChunk(locator->pParserCtxt, data, dataRead, 0) != XML_ERR_OK) hr = E_FAIL;
1829 else hr = locator->ret;
1831 if(hr != S_OK) break;
1833 if(dataRead != sizeof(data))
1835 if(xmlParseChunk(locator->pParserCtxt, data, 0, 1) != XML_ERR_OK) hr = E_FAIL;
1836 else hr = locator->ret;
1841 This->isParsing = FALSE;
1843 xmlFreeParserCtxt(locator->pParserCtxt);
1844 locator->pParserCtxt = NULL;
1845 ISAXLocator_Release(&locator->ISAXLocator_iface);
1849 static HRESULT internal_getEntityResolver(
1851 void *pEntityResolver,
1854 FIXME("(%p)->(%p) stub\n", This, pEntityResolver);
1858 static HRESULT internal_putEntityResolver(
1860 void *pEntityResolver,
1863 FIXME("(%p)->(%p) stub\n", This, pEntityResolver);
1867 static HRESULT internal_getContentHandler(
1869 void *pContentHandler,
1872 TRACE("(%p)->(%p)\n", This, pContentHandler);
1873 if(pContentHandler == NULL)
1875 if((vbInterface && This->vbcontentHandler)
1876 || (!vbInterface && This->contentHandler))
1879 IVBSAXContentHandler_AddRef(This->vbcontentHandler);
1881 ISAXContentHandler_AddRef(This->contentHandler);
1883 if(vbInterface) *(IVBSAXContentHandler**)pContentHandler =
1884 This->vbcontentHandler;
1885 else *(ISAXContentHandler**)pContentHandler = This->contentHandler;
1890 static HRESULT internal_putContentHandler(
1892 void *contentHandler,
1895 TRACE("(%p)->(%p)\n", This, contentHandler);
1899 IVBSAXContentHandler_AddRef((IVBSAXContentHandler*)contentHandler);
1901 ISAXContentHandler_AddRef((ISAXContentHandler*)contentHandler);
1903 if((vbInterface && This->vbcontentHandler)
1904 || (!vbInterface && This->contentHandler))
1907 IVBSAXContentHandler_Release(This->vbcontentHandler);
1909 ISAXContentHandler_Release(This->contentHandler);
1912 This->vbcontentHandler = contentHandler;
1914 This->contentHandler = contentHandler;
1919 static HRESULT internal_getDTDHandler(
1924 FIXME("(%p)->(%p) stub\n", This, pDTDHandler);
1928 static HRESULT internal_putDTDHandler(
1933 FIXME("(%p)->(%p) stub\n", This, pDTDHandler);
1937 static HRESULT internal_getErrorHandler(
1939 void *pErrorHandler,
1942 TRACE("(%p)->(%p)\n", This, pErrorHandler);
1943 if(pErrorHandler == NULL)
1946 if(vbInterface && This->vberrorHandler)
1947 IVBSAXErrorHandler_AddRef(This->vberrorHandler);
1948 else if(!vbInterface && This->errorHandler)
1949 ISAXErrorHandler_AddRef(This->errorHandler);
1952 *(IVBSAXErrorHandler**)pErrorHandler = This->vberrorHandler;
1954 *(ISAXErrorHandler**)pErrorHandler = This->errorHandler;
1960 static HRESULT internal_putErrorHandler(
1965 TRACE("(%p)->(%p)\n", This, errorHandler);
1969 IVBSAXErrorHandler_AddRef((IVBSAXErrorHandler*)errorHandler);
1971 ISAXErrorHandler_AddRef((ISAXErrorHandler*)errorHandler);
1974 if(vbInterface && This->vberrorHandler)
1975 IVBSAXErrorHandler_Release(This->vberrorHandler);
1976 else if(!vbInterface && This->errorHandler)
1977 ISAXErrorHandler_Release(This->errorHandler);
1980 This->vberrorHandler = errorHandler;
1982 This->errorHandler = errorHandler;
1988 static HRESULT internal_parse(
1995 TRACE("(%p)\n", This);
1998 switch(V_VT(&varInput))
2001 hr = internal_parseBuffer(This, (const char*)V_BSTR(&varInput),
2002 SysStringByteLen(V_BSTR(&varInput)), vbInterface);
2004 case VT_ARRAY|VT_UI1: {
2006 LONG lBound, uBound;
2009 hr = SafeArrayGetLBound(V_ARRAY(&varInput), 1, &lBound);
2010 if(hr != S_OK) break;
2011 hr = SafeArrayGetUBound(V_ARRAY(&varInput), 1, &uBound);
2012 if(hr != S_OK) break;
2013 dataRead = (uBound-lBound)*SafeArrayGetElemsize(V_ARRAY(&varInput));
2014 hr = SafeArrayAccessData(V_ARRAY(&varInput), &pSAData);
2015 if(hr != S_OK) break;
2016 hr = internal_parseBuffer(This, pSAData, dataRead, vbInterface);
2017 SafeArrayUnaccessData(V_ARRAY(&varInput));
2022 IPersistStream *persistStream;
2023 IStream *stream = NULL;
2024 IXMLDOMDocument *xmlDoc;
2026 if(IUnknown_QueryInterface(V_UNKNOWN(&varInput),
2027 &IID_IXMLDOMDocument, (void**)&xmlDoc) == S_OK)
2031 IXMLDOMDocument_get_xml(xmlDoc, &bstrData);
2032 hr = internal_parseBuffer(This, (const char*)bstrData,
2033 SysStringByteLen(bstrData), vbInterface);
2034 IXMLDOMDocument_Release(xmlDoc);
2035 SysFreeString(bstrData);
2039 if(IUnknown_QueryInterface(V_UNKNOWN(&varInput),
2040 &IID_IPersistStream, (void**)&persistStream) == S_OK)
2042 hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
2045 IPersistStream_Release(persistStream);
2049 hr = IPersistStream_Save(persistStream, stream, TRUE);
2050 IPersistStream_Release(persistStream);
2053 IStream_Release(stream);
2057 if(stream || IUnknown_QueryInterface(V_UNKNOWN(&varInput),
2058 &IID_IStream, (void**)&stream) == S_OK)
2060 hr = internal_parseStream(This, stream, vbInterface);
2061 IStream_Release(stream);
2066 WARN("vt %d not implemented\n", V_VT(&varInput));
2073 static HRESULT internal_vbonDataAvailable(void *obj, char *ptr, DWORD len)
2075 saxreader *This = obj;
2077 return internal_parseBuffer(This, ptr, len, TRUE);
2080 static HRESULT internal_onDataAvailable(void *obj, char *ptr, DWORD len)
2082 saxreader *This = obj;
2084 return internal_parseBuffer(This, ptr, len, FALSE);
2087 static HRESULT internal_parseURL(
2095 TRACE("(%p)->(%s)\n", This, debugstr_w(url));
2097 if(vbInterface) hr = bind_url(url, internal_vbonDataAvailable, This, &bsc);
2098 else hr = bind_url(url, internal_onDataAvailable, This, &bsc);
2108 static HRESULT internal_putProperty(
2114 static const WCHAR wszCharset[] = {
2115 'c','h','a','r','s','e','t',0
2117 static const WCHAR wszDeclarationHandler[] = {
2118 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
2119 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
2120 'd','e','c','l','a','r','a','t','i','o','n',
2121 '-','h','a','n','d','l','e','r',0
2123 static const WCHAR wszDomNode[] = {
2124 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
2125 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
2126 'd','o','m','-','n','o','d','e',0
2128 static const WCHAR wszInputSource[] = {
2129 'i','n','p','u','t','-','s','o','u','r','c','e',0
2131 static const WCHAR wszLexicalHandler[] = {
2132 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
2133 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
2134 'l','e','x','i','c','a','l','-','h','a','n','d','l','e','r',0
2136 static const WCHAR wszMaxElementDepth[] = {
2137 'm','a','x','-','e','l','e','m','e','n','t','-','d','e','p','t','h',0
2139 static const WCHAR wszMaxXMLSize[] = {
2140 'm','a','x','-','x','m','l','-','s','i','z','e',0
2142 static const WCHAR wszSchemaDeclarationHandler[] = {
2143 's','c','h','e','m','a','-',
2144 'd','e','c','l','a','r','a','t','i','o','n','-',
2145 'h','a','n','d','l','e','r',0
2147 static const WCHAR wszXMLDeclEncoding[] = {
2148 'x','m','l','d','e','c','l','-','e','n','c','o','d','i','n','g',0
2150 static const WCHAR wszXMLDeclStandalone[] = {
2151 'x','m','l','d','e','c','l',
2152 '-','s','t','a','n','d','a','l','o','n','e',0
2154 static const WCHAR wszXMLDeclVersion[] = {
2155 'x','m','l','d','e','c','l','-','v','e','r','s','i','o','n',0
2158 TRACE("(%p)->(%s)\n", This, debugstr_w(pProp));
2160 if(!memcmp(pProp, wszDeclarationHandler, sizeof(wszDeclarationHandler)))
2162 if(This->isParsing) return E_FAIL;
2164 if(V_UNKNOWN(&value))
2167 IVBSAXDeclHandler_AddRef((IVBSAXDeclHandler*)V_UNKNOWN(&value));
2169 ISAXDeclHandler_AddRef((ISAXDeclHandler*)V_UNKNOWN(&value));
2171 if((vbInterface && This->vbdeclHandler)
2172 || (!vbInterface && This->declHandler))
2175 IVBSAXDeclHandler_Release(This->vbdeclHandler);
2177 ISAXDeclHandler_Release(This->declHandler);
2180 This->vbdeclHandler = (IVBSAXDeclHandler*)V_UNKNOWN(&value);
2182 This->declHandler = (ISAXDeclHandler*)V_UNKNOWN(&value);
2186 if(!memcmp(pProp, wszLexicalHandler, sizeof(wszLexicalHandler)))
2188 if(This->isParsing) return E_FAIL;
2190 if(V_UNKNOWN(&value))
2193 IVBSAXLexicalHandler_AddRef(
2194 (IVBSAXLexicalHandler*)V_UNKNOWN(&value));
2196 ISAXLexicalHandler_AddRef(
2197 (ISAXLexicalHandler*)V_UNKNOWN(&value));
2199 if((vbInterface && This->vblexicalHandler)
2200 || (!vbInterface && This->lexicalHandler))
2203 IVBSAXLexicalHandler_Release(This->vblexicalHandler);
2205 ISAXLexicalHandler_Release(This->lexicalHandler);
2208 This->vblexicalHandler = (IVBSAXLexicalHandler*)V_UNKNOWN(&value);
2210 This->lexicalHandler = (ISAXLexicalHandler*)V_UNKNOWN(&value);
2214 FIXME("(%p)->(%s): unsupported property\n", This, debugstr_w(pProp));
2216 if(!memcmp(pProp, wszCharset, sizeof(wszCharset)))
2219 if(!memcmp(pProp, wszDomNode, sizeof(wszDomNode)))
2222 if(!memcmp(pProp, wszInputSource, sizeof(wszInputSource)))
2225 if(!memcmp(pProp, wszMaxElementDepth, sizeof(wszMaxElementDepth)))
2228 if(!memcmp(pProp, wszMaxXMLSize, sizeof(wszMaxXMLSize)))
2231 if(!memcmp(pProp, wszSchemaDeclarationHandler,
2232 sizeof(wszSchemaDeclarationHandler)))
2235 if(!memcmp(pProp, wszXMLDeclEncoding, sizeof(wszXMLDeclEncoding)))
2238 if(!memcmp(pProp, wszXMLDeclStandalone, sizeof(wszXMLDeclStandalone)))
2241 if(!memcmp(pProp, wszXMLDeclVersion, sizeof(wszXMLDeclVersion)))
2244 return E_INVALIDARG;
2247 /*** IVBSAXXMLReader interface ***/
2248 /*** IUnknown methods ***/
2249 static HRESULT WINAPI saxxmlreader_QueryInterface(IVBSAXXMLReader* iface, REFIID riid, void **ppvObject)
2251 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2253 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject );
2257 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
2258 IsEqualGUID( riid, &IID_IDispatch ) ||
2259 IsEqualGUID( riid, &IID_IVBSAXXMLReader ))
2263 else if( IsEqualGUID( riid, &IID_ISAXXMLReader ))
2265 *ppvObject = &This->ISAXXMLReader_iface;
2269 FIXME("interface %s not implemented\n", debugstr_guid(riid));
2270 return E_NOINTERFACE;
2273 IVBSAXXMLReader_AddRef( iface );
2278 static ULONG WINAPI saxxmlreader_AddRef(IVBSAXXMLReader* iface)
2280 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2281 TRACE("%p\n", This );
2282 return InterlockedIncrement( &This->ref );
2285 static ULONG WINAPI saxxmlreader_Release(
2286 IVBSAXXMLReader* iface)
2288 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2291 TRACE("%p\n", This );
2293 ref = InterlockedDecrement( &This->ref );
2296 if(This->contentHandler)
2297 ISAXContentHandler_Release(This->contentHandler);
2299 if(This->vbcontentHandler)
2300 IVBSAXContentHandler_Release(This->vbcontentHandler);
2302 if(This->errorHandler)
2303 ISAXErrorHandler_Release(This->errorHandler);
2305 if(This->vberrorHandler)
2306 IVBSAXErrorHandler_Release(This->vberrorHandler);
2308 if(This->lexicalHandler)
2309 ISAXLexicalHandler_Release(This->lexicalHandler);
2311 if(This->vblexicalHandler)
2312 IVBSAXLexicalHandler_Release(This->vblexicalHandler);
2314 if(This->declHandler)
2315 ISAXDeclHandler_Release(This->declHandler);
2317 if(This->vbdeclHandler)
2318 IVBSAXDeclHandler_Release(This->vbdeclHandler);
2326 static HRESULT WINAPI saxxmlreader_GetTypeInfoCount( IVBSAXXMLReader *iface, UINT* pctinfo )
2328 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2330 TRACE("(%p)->(%p)\n", This, pctinfo);
2337 static HRESULT WINAPI saxxmlreader_GetTypeInfo(
2338 IVBSAXXMLReader *iface,
2339 UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo )
2341 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2344 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
2346 hr = get_typeinfo(IVBSAXXMLReader_tid, ppTInfo);
2351 static HRESULT WINAPI saxxmlreader_GetIDsOfNames(
2352 IVBSAXXMLReader *iface,
2354 LPOLESTR* rgszNames,
2359 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2360 ITypeInfo *typeinfo;
2363 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
2366 if(!rgszNames || cNames == 0 || !rgDispId)
2367 return E_INVALIDARG;
2369 hr = get_typeinfo(IVBSAXXMLReader_tid, &typeinfo);
2372 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
2373 ITypeInfo_Release(typeinfo);
2379 static HRESULT WINAPI saxxmlreader_Invoke(
2380 IVBSAXXMLReader *iface,
2381 DISPID dispIdMember,
2385 DISPPARAMS* pDispParams,
2386 VARIANT* pVarResult,
2387 EXCEPINFO* pExcepInfo,
2390 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2391 ITypeInfo *typeinfo;
2394 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
2395 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2397 hr = get_typeinfo(IVBSAXXMLReader_tid, &typeinfo);
2400 hr = ITypeInfo_Invoke(typeinfo, &This->IVBSAXXMLReader_iface, dispIdMember, wFlags,
2401 pDispParams, pVarResult, pExcepInfo, puArgErr);
2402 ITypeInfo_Release(typeinfo);
2408 /*** IVBSAXXMLReader methods ***/
2409 static HRESULT WINAPI saxxmlreader_getFeature(
2410 IVBSAXXMLReader* iface,
2411 const WCHAR *pFeature,
2412 VARIANT_BOOL *pValue)
2414 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2416 FIXME("(%p)->(%s %p) stub\n", This, debugstr_w(pFeature), pValue);
2420 static HRESULT WINAPI saxxmlreader_putFeature(
2421 IVBSAXXMLReader* iface,
2422 const WCHAR *pFeature,
2423 VARIANT_BOOL vfValue)
2425 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2427 FIXME("(%p)->(%s %x) stub\n", This, debugstr_w(pFeature), vfValue);
2431 static HRESULT WINAPI saxxmlreader_getProperty(
2432 IVBSAXXMLReader* iface,
2436 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2438 FIXME("(%p)->(%s %p) stub\n", This, debugstr_w(pProp), pValue);
2442 static HRESULT WINAPI saxxmlreader_putProperty(
2443 IVBSAXXMLReader* iface,
2447 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2448 return internal_putProperty(This, pProp, value, TRUE);
2451 static HRESULT WINAPI saxxmlreader_get_entityResolver(
2452 IVBSAXXMLReader* iface,
2453 IVBSAXEntityResolver **pEntityResolver)
2455 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2456 return internal_getEntityResolver(This, pEntityResolver, TRUE);
2459 static HRESULT WINAPI saxxmlreader_put_entityResolver(
2460 IVBSAXXMLReader* iface,
2461 IVBSAXEntityResolver *pEntityResolver)
2463 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2464 return internal_putEntityResolver(This, pEntityResolver, TRUE);
2467 static HRESULT WINAPI saxxmlreader_get_contentHandler(
2468 IVBSAXXMLReader* iface,
2469 IVBSAXContentHandler **ppContentHandler)
2471 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2472 return internal_getContentHandler(This, ppContentHandler, TRUE);
2475 static HRESULT WINAPI saxxmlreader_put_contentHandler(
2476 IVBSAXXMLReader* iface,
2477 IVBSAXContentHandler *contentHandler)
2479 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2480 return internal_putContentHandler(This, contentHandler, TRUE);
2483 static HRESULT WINAPI saxxmlreader_get_dtdHandler(
2484 IVBSAXXMLReader* iface,
2485 IVBSAXDTDHandler **pDTDHandler)
2487 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2488 return internal_getDTDHandler(This, pDTDHandler, TRUE);
2491 static HRESULT WINAPI saxxmlreader_put_dtdHandler(
2492 IVBSAXXMLReader* iface,
2493 IVBSAXDTDHandler *pDTDHandler)
2495 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2496 return internal_putDTDHandler(This, pDTDHandler, TRUE);
2499 static HRESULT WINAPI saxxmlreader_get_errorHandler(
2500 IVBSAXXMLReader* iface,
2501 IVBSAXErrorHandler **pErrorHandler)
2503 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2504 return internal_getErrorHandler(This, pErrorHandler, TRUE);
2507 static HRESULT WINAPI saxxmlreader_put_errorHandler(
2508 IVBSAXXMLReader* iface,
2509 IVBSAXErrorHandler *errorHandler)
2511 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2512 return internal_putErrorHandler(This, errorHandler, TRUE);
2515 static HRESULT WINAPI saxxmlreader_get_baseURL(
2516 IVBSAXXMLReader* iface,
2517 const WCHAR **pBaseUrl)
2519 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2521 FIXME("(%p)->(%p) stub\n", This, pBaseUrl);
2525 static HRESULT WINAPI saxxmlreader_put_baseURL(
2526 IVBSAXXMLReader* iface,
2527 const WCHAR *pBaseUrl)
2529 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2531 FIXME("(%p)->(%s) stub\n", This, debugstr_w(pBaseUrl));
2535 static HRESULT WINAPI saxxmlreader_get_secureBaseURL(
2536 IVBSAXXMLReader* iface,
2537 const WCHAR **pSecureBaseUrl)
2539 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2541 FIXME("(%p)->(%p) stub\n", This, pSecureBaseUrl);
2546 static HRESULT WINAPI saxxmlreader_put_secureBaseURL(
2547 IVBSAXXMLReader* iface,
2548 const WCHAR *secureBaseUrl)
2550 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2552 FIXME("(%p)->(%s) stub\n", This, debugstr_w(secureBaseUrl));
2556 static HRESULT WINAPI saxxmlreader_parse(
2557 IVBSAXXMLReader* iface,
2560 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2561 return internal_parse(This, varInput, TRUE);
2564 static HRESULT WINAPI saxxmlreader_parseURL(
2565 IVBSAXXMLReader* iface,
2568 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2569 return internal_parseURL(This, url, TRUE);
2572 static const struct IVBSAXXMLReaderVtbl saxreader_vtbl =
2574 saxxmlreader_QueryInterface,
2575 saxxmlreader_AddRef,
2576 saxxmlreader_Release,
2577 saxxmlreader_GetTypeInfoCount,
2578 saxxmlreader_GetTypeInfo,
2579 saxxmlreader_GetIDsOfNames,
2580 saxxmlreader_Invoke,
2581 saxxmlreader_getFeature,
2582 saxxmlreader_putFeature,
2583 saxxmlreader_getProperty,
2584 saxxmlreader_putProperty,
2585 saxxmlreader_get_entityResolver,
2586 saxxmlreader_put_entityResolver,
2587 saxxmlreader_get_contentHandler,
2588 saxxmlreader_put_contentHandler,
2589 saxxmlreader_get_dtdHandler,
2590 saxxmlreader_put_dtdHandler,
2591 saxxmlreader_get_errorHandler,
2592 saxxmlreader_put_errorHandler,
2593 saxxmlreader_get_baseURL,
2594 saxxmlreader_put_baseURL,
2595 saxxmlreader_get_secureBaseURL,
2596 saxxmlreader_put_secureBaseURL,
2598 saxxmlreader_parseURL
2601 /*** ISAXXMLReader interface ***/
2602 /*** IUnknown methods ***/
2603 static HRESULT WINAPI isaxxmlreader_QueryInterface(ISAXXMLReader* iface, REFIID riid, void **ppvObject)
2605 saxreader *This = impl_from_ISAXXMLReader( iface );
2606 return saxxmlreader_QueryInterface(&This->IVBSAXXMLReader_iface, riid, ppvObject);
2609 static ULONG WINAPI isaxxmlreader_AddRef(ISAXXMLReader* iface)
2611 saxreader *This = impl_from_ISAXXMLReader( iface );
2612 return saxxmlreader_AddRef(&This->IVBSAXXMLReader_iface);
2615 static ULONG WINAPI isaxxmlreader_Release(ISAXXMLReader* iface)
2617 saxreader *This = impl_from_ISAXXMLReader( iface );
2618 return saxxmlreader_Release(&This->IVBSAXXMLReader_iface);
2621 /*** ISAXXMLReader methods ***/
2622 static HRESULT WINAPI isaxxmlreader_getFeature(
2623 ISAXXMLReader* iface,
2624 const WCHAR *pFeature,
2625 VARIANT_BOOL *pValue)
2627 saxreader *This = impl_from_ISAXXMLReader( iface );
2628 return IVBSAXXMLReader_getFeature(&This->IVBSAXXMLReader_iface, pFeature, pValue);
2631 static HRESULT WINAPI isaxxmlreader_putFeature(
2632 ISAXXMLReader* iface,
2633 const WCHAR *pFeature,
2634 VARIANT_BOOL vfValue)
2636 saxreader *This = impl_from_ISAXXMLReader( iface );
2637 return IVBSAXXMLReader_putFeature(&This->IVBSAXXMLReader_iface, pFeature, vfValue);
2640 static HRESULT WINAPI isaxxmlreader_getProperty(
2641 ISAXXMLReader* iface,
2645 saxreader *This = impl_from_ISAXXMLReader( iface );
2646 return IVBSAXXMLReader_getProperty(&This->IVBSAXXMLReader_iface, pProp, pValue);
2649 static HRESULT WINAPI isaxxmlreader_putProperty(
2650 ISAXXMLReader* iface,
2654 saxreader *This = impl_from_ISAXXMLReader( iface );
2655 return internal_putProperty(This, pProp, value, FALSE);
2658 static HRESULT WINAPI isaxxmlreader_getEntityResolver(
2659 ISAXXMLReader* iface,
2660 ISAXEntityResolver **ppEntityResolver)
2662 saxreader *This = impl_from_ISAXXMLReader( iface );
2663 return internal_getEntityResolver(This, ppEntityResolver, FALSE);
2666 static HRESULT WINAPI isaxxmlreader_putEntityResolver(
2667 ISAXXMLReader* iface,
2668 ISAXEntityResolver *pEntityResolver)
2670 saxreader *This = impl_from_ISAXXMLReader( iface );
2671 return internal_putEntityResolver(This, pEntityResolver, FALSE);
2674 static HRESULT WINAPI isaxxmlreader_getContentHandler(
2675 ISAXXMLReader* iface,
2676 ISAXContentHandler **pContentHandler)
2678 saxreader *This = impl_from_ISAXXMLReader( iface );
2679 return internal_getContentHandler(This, pContentHandler, FALSE);
2682 static HRESULT WINAPI isaxxmlreader_putContentHandler(
2683 ISAXXMLReader* iface,
2684 ISAXContentHandler *contentHandler)
2686 saxreader *This = impl_from_ISAXXMLReader( iface );
2687 return internal_putContentHandler(This, contentHandler, FALSE);
2690 static HRESULT WINAPI isaxxmlreader_getDTDHandler(
2691 ISAXXMLReader* iface,
2692 ISAXDTDHandler **pDTDHandler)
2694 saxreader *This = impl_from_ISAXXMLReader( iface );
2695 return internal_getDTDHandler(This, pDTDHandler, FALSE);
2698 static HRESULT WINAPI isaxxmlreader_putDTDHandler(
2699 ISAXXMLReader* iface,
2700 ISAXDTDHandler *pDTDHandler)
2702 saxreader *This = impl_from_ISAXXMLReader( iface );
2703 return internal_putDTDHandler(This, pDTDHandler, FALSE);
2706 static HRESULT WINAPI isaxxmlreader_getErrorHandler(
2707 ISAXXMLReader* iface,
2708 ISAXErrorHandler **pErrorHandler)
2710 saxreader *This = impl_from_ISAXXMLReader( iface );
2711 return internal_getErrorHandler(This, pErrorHandler, FALSE);
2714 static HRESULT WINAPI isaxxmlreader_putErrorHandler(
2715 ISAXXMLReader* iface,
2716 ISAXErrorHandler *errorHandler)
2718 saxreader *This = impl_from_ISAXXMLReader( iface );
2719 return internal_putErrorHandler(This, errorHandler, FALSE);
2722 static HRESULT WINAPI isaxxmlreader_getBaseURL(
2723 ISAXXMLReader* iface,
2724 const WCHAR **pBaseUrl)
2726 saxreader *This = impl_from_ISAXXMLReader( iface );
2727 return IVBSAXXMLReader_get_baseURL(&This->IVBSAXXMLReader_iface, pBaseUrl);
2730 static HRESULT WINAPI isaxxmlreader_putBaseURL(
2731 ISAXXMLReader* iface,
2732 const WCHAR *pBaseUrl)
2734 saxreader *This = impl_from_ISAXXMLReader( iface );
2735 return IVBSAXXMLReader_put_baseURL(&This->IVBSAXXMLReader_iface, pBaseUrl);
2738 static HRESULT WINAPI isaxxmlreader_getSecureBaseURL(
2739 ISAXXMLReader* iface,
2740 const WCHAR **pSecureBaseUrl)
2742 saxreader *This = impl_from_ISAXXMLReader( iface );
2743 return IVBSAXXMLReader_get_secureBaseURL(&This->IVBSAXXMLReader_iface, pSecureBaseUrl);
2746 static HRESULT WINAPI isaxxmlreader_putSecureBaseURL(
2747 ISAXXMLReader* iface,
2748 const WCHAR *secureBaseUrl)
2750 saxreader *This = impl_from_ISAXXMLReader( iface );
2751 return IVBSAXXMLReader_put_secureBaseURL(&This->IVBSAXXMLReader_iface, secureBaseUrl);
2754 static HRESULT WINAPI isaxxmlreader_parse(
2755 ISAXXMLReader* iface,
2758 saxreader *This = impl_from_ISAXXMLReader( iface );
2759 return internal_parse(This, varInput, FALSE);
2762 static HRESULT WINAPI isaxxmlreader_parseURL(
2763 ISAXXMLReader* iface,
2766 saxreader *This = impl_from_ISAXXMLReader( iface );
2767 return internal_parseURL(This, url, FALSE);
2770 static const struct ISAXXMLReaderVtbl isaxreader_vtbl =
2772 isaxxmlreader_QueryInterface,
2773 isaxxmlreader_AddRef,
2774 isaxxmlreader_Release,
2775 isaxxmlreader_getFeature,
2776 isaxxmlreader_putFeature,
2777 isaxxmlreader_getProperty,
2778 isaxxmlreader_putProperty,
2779 isaxxmlreader_getEntityResolver,
2780 isaxxmlreader_putEntityResolver,
2781 isaxxmlreader_getContentHandler,
2782 isaxxmlreader_putContentHandler,
2783 isaxxmlreader_getDTDHandler,
2784 isaxxmlreader_putDTDHandler,
2785 isaxxmlreader_getErrorHandler,
2786 isaxxmlreader_putErrorHandler,
2787 isaxxmlreader_getBaseURL,
2788 isaxxmlreader_putBaseURL,
2789 isaxxmlreader_getSecureBaseURL,
2790 isaxxmlreader_putSecureBaseURL,
2791 isaxxmlreader_parse,
2792 isaxxmlreader_parseURL
2795 HRESULT SAXXMLReader_create(IUnknown *pUnkOuter, LPVOID *ppObj)
2799 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
2801 reader = heap_alloc( sizeof (*reader) );
2803 return E_OUTOFMEMORY;
2805 reader->IVBSAXXMLReader_iface.lpVtbl = &saxreader_vtbl;
2806 reader->ISAXXMLReader_iface.lpVtbl = &isaxreader_vtbl;
2808 reader->contentHandler = NULL;
2809 reader->vbcontentHandler = NULL;
2810 reader->errorHandler = NULL;
2811 reader->vberrorHandler = NULL;
2812 reader->lexicalHandler = NULL;
2813 reader->vblexicalHandler = NULL;
2814 reader->declHandler = NULL;
2815 reader->vbdeclHandler = NULL;
2816 reader->isParsing = FALSE;
2818 memset(&reader->sax, 0, sizeof(xmlSAXHandler));
2819 reader->sax.initialized = XML_SAX2_MAGIC;
2820 reader->sax.startDocument = libxmlStartDocument;
2821 reader->sax.endDocument = libxmlEndDocument;
2822 reader->sax.startElementNs = libxmlStartElementNS;
2823 reader->sax.endElementNs = libxmlEndElementNS;
2824 reader->sax.characters = libxmlCharacters;
2825 reader->sax.setDocumentLocator = libxmlSetDocumentLocator;
2826 reader->sax.comment = libxmlComment;
2827 reader->sax.error = libxmlFatalError;
2828 reader->sax.fatalError = libxmlFatalError;
2829 reader->sax.cdataBlock = libxmlCDataBlock;
2831 *ppObj = &reader->IVBSAXXMLReader_iface;
2833 TRACE("returning iface %p\n", *ppObj);
2840 HRESULT SAXXMLReader_create(IUnknown *pUnkOuter, LPVOID *ppObj)
2842 MESSAGE("This program tried to use a SAX XML Reader object, but\n"
2843 "libxml2 support was not present at compile time.\n");