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"
45 #include "wine/list.h"
47 #include "msxml_private.h"
49 WINE_DEFAULT_DEBUG_CHANNEL(msxml
);
56 ExhaustiveErrors
= 1 << 1,
57 ExternalGeneralEntities
= 1 << 2,
58 ExternalParameterEntities
= 1 << 3,
59 ForcedResync
= 1 << 4,
60 NamespacePrefixes
= 1 << 5,
62 ParameterEntities
= 1 << 7,
63 PreserveSystemIndentifiers
= 1 << 8,
65 SchemaValidation
= 1 << 10,
66 ServerHttpRequest
= 1 << 11,
67 SuppressValidationfatalError
= 1 << 12,
68 UseInlineSchema
= 1 << 13,
69 UseSchemaLocation
= 1 << 14,
70 LexicalHandlerParEntities
= 1 << 15
74 static const WCHAR FeatureExternalGeneralEntitiesW
[] = {
75 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/','s','a','x','/',
76 'f','e','a','t','u','r','e','s','/','e','x','t','e','r','n','a','l','-','g','e','n','e','r','a','l',
77 '-','e','n','t','i','t','i','e','s',0
80 static const WCHAR FeatureExternalParameterEntitiesW
[] = {
81 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/','s','a','x','/','f','e','a','t','u','r','e','s',
82 '/','e','x','t','e','r','n','a','l','-','p','a','r','a','m','e','t','e','r','-','e','n','t','i','t','i','e','s',0
85 static const WCHAR FeatureLexicalHandlerParEntitiesW
[] = {
86 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/','s','a','x','/','f','e','a','t','u','r','e','s',
87 '/','l','e','x','i','c','a','l','-','h','a','n','d','l','e','r','/','p','a','r','a','m','e','t','e','r','-','e','n','t','i','t','i','e','s',0
90 static const WCHAR FeatureProhibitDTDW
[] = {
91 'p','r','o','h','i','b','i','t','-','d','t','d',0
94 static const WCHAR FeatureNamespacesW
[] = {
95 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/','s','a','x','/','f','e','a','t','u','r','e','s',
96 '/','n','a','m','e','s','p','a','c','e','s',0
99 static const WCHAR FeatureNamespacePrefixesW
[] = {
100 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/','s','a','x','/','f','e','a','t','u','r','e','s',
101 '/','n','a','m','e','s','p','a','c','e','-','p','r','e','f','i','x','e','s',0
104 struct saxreader_feature_pair
106 saxreader_feature feature
;
110 static const struct saxreader_feature_pair saxreader_feature_map
[] = {
111 { ExternalGeneralEntities
, FeatureExternalGeneralEntitiesW
},
112 { ExternalParameterEntities
, FeatureExternalParameterEntitiesW
},
113 { LexicalHandlerParEntities
, FeatureLexicalHandlerParEntitiesW
},
114 { NamespacePrefixes
, FeatureNamespacePrefixesW
},
115 { Namespaces
, FeatureNamespacesW
},
116 { ProhibitDTD
, FeatureProhibitDTDW
}
119 static saxreader_feature
get_saxreader_feature(const WCHAR
*name
)
124 max
= sizeof(saxreader_feature_map
)/sizeof(struct saxreader_feature_pair
) - 1;
130 c
= strcmpW(saxreader_feature_map
[n
].name
, name
);
132 return saxreader_feature_map
[n
].feature
;
140 return FeatureUnknown
;
162 ns
*ns
; /* namespaces defined in this particular element */
168 SAXContentHandler
= 0,
177 struct saxanyhandler_iface
183 struct saxcontenthandler_iface
185 ISAXContentHandler
*handler
;
186 IVBSAXContentHandler
*vbhandler
;
189 struct saxerrorhandler_iface
191 ISAXErrorHandler
*handler
;
192 IVBSAXErrorHandler
*vbhandler
;
195 struct saxlexicalhandler_iface
197 ISAXLexicalHandler
*handler
;
198 IVBSAXLexicalHandler
*vbhandler
;
201 struct saxentityresolver_iface
203 ISAXEntityResolver
*handler
;
204 IVBSAXEntityResolver
*vbhandler
;
207 struct saxhandler_iface
210 struct saxcontenthandler_iface content
;
211 struct saxentityresolver_iface entityresolver
;
212 struct saxerrorhandler_iface error
;
213 struct saxlexicalhandler_iface lexical
;
214 struct saxanyhandler_iface anyhandler
;
221 IVBSAXXMLReader IVBSAXXMLReader_iface
;
222 ISAXXMLReader ISAXXMLReader_iface
;
225 struct saxhandler_iface saxhandlers
[SAXHandler_Last
];
228 struct bstrpool pool
;
229 saxreader_feature features
;
230 BSTR xmldecl_version
;
231 MSXML_VERSION version
;
234 static HRESULT
saxreader_put_handler(saxreader
*reader
, enum saxhandler_type type
, void *ptr
, BOOL vb
)
236 struct saxanyhandler_iface
*iface
= &reader
->saxhandlers
[type
].u
.anyhandler
;
237 IUnknown
*unk
= (IUnknown
*)ptr
;
240 IUnknown_AddRef(unk
);
242 if ((vb
&& iface
->vbhandler
) || (!vb
&& iface
->handler
))
243 IUnknown_Release(vb
? iface
->vbhandler
: iface
->handler
);
246 iface
->vbhandler
= unk
;
248 iface
->handler
= unk
;
253 static HRESULT
saxreader_get_handler(const saxreader
*reader
, enum saxhandler_type type
, BOOL vb
, void **ret
)
255 const struct saxanyhandler_iface
*iface
= &reader
->saxhandlers
[type
].u
.anyhandler
;
257 if (!ret
) return E_POINTER
;
259 if ((vb
&& iface
->vbhandler
) || (!vb
&& iface
->handler
))
262 IUnknown_AddRef(iface
->vbhandler
);
264 IUnknown_AddRef(iface
->handler
);
267 *ret
= vb
? iface
->vbhandler
: iface
->handler
;
272 static struct saxcontenthandler_iface
*saxreader_get_contenthandler(saxreader
*reader
)
274 return &reader
->saxhandlers
[SAXContentHandler
].u
.content
;
277 static struct saxerrorhandler_iface
*saxreader_get_errorhandler(saxreader
*reader
)
279 return &reader
->saxhandlers
[SAXErrorHandler
].u
.error
;
282 static struct saxlexicalhandler_iface
*saxreader_get_lexicalhandler(saxreader
*reader
)
284 return &reader
->saxhandlers
[SAXLexicalHandler
].u
.lexical
;
289 IVBSAXLocator IVBSAXLocator_iface
;
290 ISAXLocator ISAXLocator_iface
;
291 IVBSAXAttributes IVBSAXAttributes_iface
;
292 ISAXAttributes ISAXAttributes_iface
;
294 saxreader
*saxreader
;
296 xmlParserCtxtPtr pParserCtxt
;
302 struct list elements
;
316 static inline saxreader
*impl_from_IVBSAXXMLReader( IVBSAXXMLReader
*iface
)
318 return CONTAINING_RECORD(iface
, saxreader
, IVBSAXXMLReader_iface
);
321 static inline saxreader
*impl_from_ISAXXMLReader( ISAXXMLReader
*iface
)
323 return CONTAINING_RECORD(iface
, saxreader
, ISAXXMLReader_iface
);
326 static inline saxlocator
*impl_from_IVBSAXLocator( IVBSAXLocator
*iface
)
328 return CONTAINING_RECORD(iface
, saxlocator
, IVBSAXLocator_iface
);
331 static inline saxlocator
*impl_from_ISAXLocator( ISAXLocator
*iface
)
333 return CONTAINING_RECORD(iface
, saxlocator
, ISAXLocator_iface
);
336 static inline saxlocator
*impl_from_IVBSAXAttributes( IVBSAXAttributes
*iface
)
338 return CONTAINING_RECORD(iface
, saxlocator
, IVBSAXAttributes_iface
);
341 static inline saxlocator
*impl_from_ISAXAttributes( ISAXAttributes
*iface
)
343 return CONTAINING_RECORD(iface
, saxlocator
, ISAXAttributes_iface
);
346 static inline int saxreader_has_handler(const saxlocator
*locator
, enum saxhandler_type type
)
348 struct saxanyhandler_iface
*iface
= &locator
->saxreader
->saxhandlers
[type
].u
.anyhandler
;
349 return (locator
->vbInterface
&& iface
->vbhandler
) || (!locator
->vbInterface
&& iface
->handler
);
353 static const WCHAR PropertyCharsetW
[] = {
354 'c','h','a','r','s','e','t',0
356 static const WCHAR PropertyXmlDeclVersionW
[] = {
357 'x','m','l','d','e','c','l','-','v','e','r','s','i','o','n',0
359 static const WCHAR PropertyDeclHandlerW
[] = {
360 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
361 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
362 'd','e','c','l','a','r','a','t','i','o','n',
363 '-','h','a','n','d','l','e','r',0
365 static const WCHAR PropertyDomNodeW
[] = {
366 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
367 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
368 'd','o','m','-','n','o','d','e',0
370 static const WCHAR PropertyInputSourceW
[] = {
371 'i','n','p','u','t','-','s','o','u','r','c','e',0
373 static const WCHAR PropertyLexicalHandlerW
[] = {
374 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
375 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
376 'l','e','x','i','c','a','l','-','h','a','n','d','l','e','r',0
378 static const WCHAR PropertyMaxElementDepthW
[] = {
379 'm','a','x','-','e','l','e','m','e','n','t','-','d','e','p','t','h',0
381 static const WCHAR PropertyMaxXMLSizeW
[] = {
382 'm','a','x','-','x','m','l','-','s','i','z','e',0
384 static const WCHAR PropertySchemaDeclHandlerW
[] = {
385 's','c','h','e','m','a','-','d','e','c','l','a','r','a','t','i','o','n','-',
386 'h','a','n','d','l','e','r',0
388 static const WCHAR PropertyXMLDeclEncodingW
[] = {
389 'x','m','l','d','e','c','l','-','e','n','c','o','d','i','n','g',0
391 static const WCHAR PropertyXMLDeclStandaloneW
[] = {
392 'x','m','l','d','e','c','l','-','s','t','a','n','d','a','l','o','n','e',0
394 static const WCHAR PropertyXMLDeclVersionW
[] = {
395 'x','m','l','d','e','c','l','-','v','e','r','s','i','o','n',0
398 static inline HRESULT
set_feature_value(saxreader
*reader
, saxreader_feature feature
, VARIANT_BOOL value
)
400 /* handling of non-VARIANT_* values is version dependent */
401 if ((reader
->version
< MSXML4
) && (value
!= VARIANT_TRUE
))
402 value
= VARIANT_FALSE
;
403 if ((reader
->version
>= MSXML4
) && (value
!= VARIANT_FALSE
))
404 value
= VARIANT_TRUE
;
406 if (value
== VARIANT_TRUE
)
407 reader
->features
|= feature
;
409 reader
->features
&= ~feature
;
414 static inline HRESULT
get_feature_value(const saxreader
*reader
, saxreader_feature feature
, VARIANT_BOOL
*value
)
416 *value
= reader
->features
& feature
? VARIANT_TRUE
: VARIANT_FALSE
;
420 static BOOL
is_namespaces_enabled(const saxreader
*reader
)
422 return (reader
->version
< MSXML4
) || (reader
->features
& Namespaces
);
425 static BSTR
build_qname(BSTR prefix
, BSTR local
)
427 if (prefix
&& *prefix
)
429 BSTR qname
= SysAllocStringLen(NULL
, SysStringLen(prefix
) + SysStringLen(local
) + 1);
433 strcpyW(ptr
, prefix
);
434 ptr
+= SysStringLen(prefix
);
440 return SysAllocString(local
);
443 static element_entry
* alloc_element_entry(const xmlChar
*local
, const xmlChar
*prefix
, int nb_ns
,
444 const xmlChar
**namespaces
)
449 ret
= heap_alloc(sizeof(*ret
));
450 if (!ret
) return ret
;
452 ret
->local
= bstr_from_xmlChar(local
);
453 ret
->prefix
= bstr_from_xmlChar(prefix
);
454 ret
->qname
= build_qname(ret
->prefix
, ret
->local
);
455 ret
->ns
= nb_ns
? heap_alloc(nb_ns
*sizeof(ns
)) : NULL
;
456 ret
->ns_count
= nb_ns
;
458 for (i
=0; i
< nb_ns
; i
++)
460 ret
->ns
[i
].prefix
= bstr_from_xmlChar(namespaces
[2*i
]);
461 ret
->ns
[i
].uri
= bstr_from_xmlChar(namespaces
[2*i
+1]);
467 static void free_element_entry(element_entry
*element
)
471 for (i
=0; i
<element
->ns_count
;i
++)
473 SysFreeString(element
->ns
[i
].prefix
);
474 SysFreeString(element
->ns
[i
].uri
);
477 SysFreeString(element
->prefix
);
478 SysFreeString(element
->local
);
480 heap_free(element
->ns
);
484 static void push_element_ns(saxlocator
*locator
, element_entry
*element
)
486 list_add_head(&locator
->elements
, &element
->entry
);
489 static element_entry
* pop_element_ns(saxlocator
*locator
)
491 element_entry
*element
= LIST_ENTRY(list_head(&locator
->elements
), element_entry
, entry
);
494 list_remove(&element
->entry
);
499 static BSTR
find_element_uri(saxlocator
*locator
, const xmlChar
*uri
)
501 element_entry
*element
;
505 if (!uri
) return NULL
;
507 uriW
= bstr_from_xmlChar(uri
);
509 LIST_FOR_EACH_ENTRY(element
, &locator
->elements
, element_entry
, entry
)
511 for (i
=0; i
< element
->ns_count
; i
++)
512 if (!strcmpW(uriW
, element
->ns
[i
].uri
))
515 return element
->ns
[i
].uri
;
520 ERR("namespace uri not found, %s\n", debugstr_a((char*)uri
));
524 /* used to localize version dependent error check behaviour */
525 static inline BOOL
sax_callback_failed(saxlocator
*This
, HRESULT hr
)
527 return This
->saxreader
->version
>= MSXML4
? FAILED(hr
) : hr
!= S_OK
;
530 /* index value -1 means it tries to loop for a first time */
531 static inline BOOL
iterate_endprefix_index(saxlocator
*This
, const element_entry
*element
, int *i
)
533 if (This
->saxreader
->version
>= MSXML4
)
535 if (*i
== -1) *i
= 0; else ++*i
;
536 return *i
< element
->ns_count
;
540 if (*i
== -1) *i
= element
->ns_count
-1; else --*i
;
545 static BOOL
bstr_pool_insert(struct bstrpool
*pool
, BSTR pool_entry
)
549 pool
->pool
= HeapAlloc(GetProcessHeap(), 0, 16 * sizeof(*pool
->pool
));
556 else if (pool
->index
== pool
->len
)
558 BSTR
*realloc
= HeapReAlloc(GetProcessHeap(), 0, pool
->pool
, pool
->len
* 2 * sizeof(*realloc
));
563 pool
->pool
= realloc
;
567 pool
->pool
[pool
->index
++] = pool_entry
;
571 static void free_bstr_pool(struct bstrpool
*pool
)
575 for (i
= 0; i
< pool
->index
; i
++)
576 SysFreeString(pool
->pool
[i
]);
578 HeapFree(GetProcessHeap(), 0, pool
->pool
);
581 pool
->index
= pool
->len
= 0;
584 static BSTR
bstr_from_xmlCharN(const xmlChar
*buf
, int len
)
592 dLen
= MultiByteToWideChar(CP_UTF8
, 0, (LPCSTR
)buf
, len
, NULL
, 0);
593 if(len
!= -1) dLen
++;
594 bstr
= SysAllocStringLen(NULL
, dLen
-1);
597 MultiByteToWideChar(CP_UTF8
, 0, (LPCSTR
)buf
, len
, bstr
, dLen
);
598 if(len
!= -1) bstr
[dLen
-1] = '\0';
603 static BSTR
QName_from_xmlChar(const xmlChar
*prefix
, const xmlChar
*name
)
608 if(!name
) return NULL
;
610 if(!prefix
|| !*prefix
)
611 return bstr_from_xmlChar(name
);
613 qname
= xmlBuildQName(name
, prefix
, NULL
, 0);
614 bstr
= bstr_from_xmlChar(qname
);
620 static BSTR
pooled_bstr_from_xmlChar(struct bstrpool
*pool
, const xmlChar
*buf
)
622 BSTR pool_entry
= bstr_from_xmlChar(buf
);
624 if (pool_entry
&& !bstr_pool_insert(pool
, pool_entry
))
626 SysFreeString(pool_entry
);
633 static BSTR
pooled_bstr_from_xmlCharN(struct bstrpool
*pool
, const xmlChar
*buf
, int len
)
635 BSTR pool_entry
= bstr_from_xmlCharN(buf
, len
);
637 if (pool_entry
&& !bstr_pool_insert(pool
, pool_entry
))
639 SysFreeString(pool_entry
);
646 static void format_error_message_from_id(saxlocator
*This
, HRESULT hr
)
648 struct saxerrorhandler_iface
*handler
= saxreader_get_errorhandler(This
->saxreader
);
649 xmlStopParser(This
->pParserCtxt
);
652 if (saxreader_has_handler(This
, SAXErrorHandler
))
655 if(!FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM
,
656 NULL
, hr
, 0, msg
, sizeof(msg
), NULL
))
658 FIXME("MSXML errors not yet supported.\n");
662 if(This
->vbInterface
)
664 BSTR bstrMsg
= SysAllocString(msg
);
665 IVBSAXErrorHandler_fatalError(handler
->vbhandler
,
666 &This
->IVBSAXLocator_iface
, &bstrMsg
, hr
);
667 SysFreeString(bstrMsg
);
670 ISAXErrorHandler_fatalError(handler
->handler
,
671 &This
->ISAXLocator_iface
, msg
, hr
);
675 static void update_position(saxlocator
*This
, BOOL fix_column
)
677 const xmlChar
*p
= This
->pParserCtxt
->input
->cur
-1;
679 This
->line
= xmlSAX2GetLineNumber(This
->pParserCtxt
);
683 for(; *p
!='\n' && *p
!='\r' && p
>=This
->pParserCtxt
->input
->base
; p
--)
688 This
->column
= xmlSAX2GetColumnNumber(This
->pParserCtxt
);
692 /*** IVBSAXAttributes interface ***/
693 /*** IUnknown methods ***/
694 static HRESULT WINAPI
ivbsaxattributes_QueryInterface(
695 IVBSAXAttributes
* iface
,
699 saxlocator
*This
= impl_from_IVBSAXAttributes(iface
);
700 TRACE("%p %s %p\n", This
, debugstr_guid(riid
), ppvObject
);
701 return IVBSAXLocator_QueryInterface(&This
->IVBSAXLocator_iface
, riid
, ppvObject
);
704 static ULONG WINAPI
ivbsaxattributes_AddRef(IVBSAXAttributes
* iface
)
706 saxlocator
*This
= impl_from_IVBSAXAttributes(iface
);
707 return ISAXLocator_AddRef(&This
->ISAXLocator_iface
);
710 static ULONG WINAPI
ivbsaxattributes_Release(IVBSAXAttributes
* iface
)
712 saxlocator
*This
= impl_from_IVBSAXAttributes(iface
);
713 return ISAXLocator_Release(&This
->ISAXLocator_iface
);
716 /*** IDispatch methods ***/
717 static HRESULT WINAPI
ivbsaxattributes_GetTypeInfoCount( IVBSAXAttributes
*iface
, UINT
* pctinfo
)
719 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
721 TRACE("(%p)->(%p)\n", This
, pctinfo
);
728 static HRESULT WINAPI
ivbsaxattributes_GetTypeInfo(
729 IVBSAXAttributes
*iface
,
730 UINT iTInfo
, LCID lcid
, ITypeInfo
** ti
)
732 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
735 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ti
);
737 hr
= get_typeinfo(IVBSAXAttributes_tid
, ti
);
738 ITypeInfo_AddRef(*ti
);
742 static HRESULT WINAPI
ivbsaxattributes_GetIDsOfNames(
743 IVBSAXAttributes
*iface
,
750 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
754 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
757 if(!rgszNames
|| cNames
== 0 || !rgDispId
)
760 hr
= get_typeinfo(IVBSAXAttributes_tid
, &typeinfo
);
762 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
767 static HRESULT WINAPI
ivbsaxattributes_Invoke(
768 IVBSAXAttributes
*iface
,
773 DISPPARAMS
* pDispParams
,
775 EXCEPINFO
* pExcepInfo
,
778 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
782 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
783 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
785 hr
= get_typeinfo(IVBSAXAttributes_tid
, &typeinfo
);
787 hr
= ITypeInfo_Invoke(typeinfo
, &This
->IVBSAXAttributes_iface
, dispIdMember
, wFlags
,
788 pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
793 /*** IVBSAXAttributes methods ***/
794 static HRESULT WINAPI
ivbsaxattributes_get_length(
795 IVBSAXAttributes
* iface
,
798 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
799 return ISAXAttributes_getLength(&This
->ISAXAttributes_iface
, nLength
);
802 static HRESULT WINAPI
ivbsaxattributes_getURI(
803 IVBSAXAttributes
* iface
,
808 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
809 return ISAXAttributes_getURI(&This
->ISAXAttributes_iface
, nIndex
, (const WCHAR
**)uri
, &len
);
812 static HRESULT WINAPI
ivbsaxattributes_getLocalName(
813 IVBSAXAttributes
* iface
,
818 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
819 return ISAXAttributes_getLocalName(&This
->ISAXAttributes_iface
, nIndex
,
820 (const WCHAR
**)localName
, &len
);
823 static HRESULT WINAPI
ivbsaxattributes_getQName(
824 IVBSAXAttributes
* iface
,
829 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
830 return ISAXAttributes_getQName(&This
->ISAXAttributes_iface
, nIndex
, (const WCHAR
**)QName
, &len
);
833 static HRESULT WINAPI
ivbsaxattributes_getIndexFromName(
834 IVBSAXAttributes
* iface
,
839 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
840 return ISAXAttributes_getIndexFromName(&This
->ISAXAttributes_iface
, uri
, SysStringLen(uri
),
841 localName
, SysStringLen(localName
), index
);
844 static HRESULT WINAPI
ivbsaxattributes_getIndexFromQName(
845 IVBSAXAttributes
* iface
,
849 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
850 return ISAXAttributes_getIndexFromQName(&This
->ISAXAttributes_iface
, QName
,
851 SysStringLen(QName
), index
);
854 static HRESULT WINAPI
ivbsaxattributes_getType(
855 IVBSAXAttributes
* iface
,
860 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
861 return ISAXAttributes_getType(&This
->ISAXAttributes_iface
, nIndex
, (const WCHAR
**)type
, &len
);
864 static HRESULT WINAPI
ivbsaxattributes_getTypeFromName(
865 IVBSAXAttributes
* iface
,
871 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
872 return ISAXAttributes_getTypeFromName(&This
->ISAXAttributes_iface
, uri
, SysStringLen(uri
),
873 localName
, SysStringLen(localName
), (const WCHAR
**)type
, &len
);
876 static HRESULT WINAPI
ivbsaxattributes_getTypeFromQName(
877 IVBSAXAttributes
* iface
,
882 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
883 return ISAXAttributes_getTypeFromQName(&This
->ISAXAttributes_iface
, QName
, SysStringLen(QName
),
884 (const WCHAR
**)type
, &len
);
887 static HRESULT WINAPI
ivbsaxattributes_getValue(
888 IVBSAXAttributes
* iface
,
893 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
894 return ISAXAttributes_getValue(&This
->ISAXAttributes_iface
, nIndex
, (const WCHAR
**)value
, &len
);
897 static HRESULT WINAPI
ivbsaxattributes_getValueFromName(
898 IVBSAXAttributes
* iface
,
904 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
905 return ISAXAttributes_getValueFromName(&This
->ISAXAttributes_iface
, uri
, SysStringLen(uri
),
906 localName
, SysStringLen(localName
), (const WCHAR
**)value
, &len
);
909 static HRESULT WINAPI
ivbsaxattributes_getValueFromQName(
910 IVBSAXAttributes
* iface
,
915 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
916 return ISAXAttributes_getValueFromQName(&This
->ISAXAttributes_iface
, QName
,
917 SysStringLen(QName
), (const WCHAR
**)value
, &len
);
920 static const struct IVBSAXAttributesVtbl ivbsaxattributes_vtbl
=
922 ivbsaxattributes_QueryInterface
,
923 ivbsaxattributes_AddRef
,
924 ivbsaxattributes_Release
,
925 ivbsaxattributes_GetTypeInfoCount
,
926 ivbsaxattributes_GetTypeInfo
,
927 ivbsaxattributes_GetIDsOfNames
,
928 ivbsaxattributes_Invoke
,
929 ivbsaxattributes_get_length
,
930 ivbsaxattributes_getURI
,
931 ivbsaxattributes_getLocalName
,
932 ivbsaxattributes_getQName
,
933 ivbsaxattributes_getIndexFromName
,
934 ivbsaxattributes_getIndexFromQName
,
935 ivbsaxattributes_getType
,
936 ivbsaxattributes_getTypeFromName
,
937 ivbsaxattributes_getTypeFromQName
,
938 ivbsaxattributes_getValue
,
939 ivbsaxattributes_getValueFromName
,
940 ivbsaxattributes_getValueFromQName
943 /*** ISAXAttributes interface ***/
944 /*** IUnknown methods ***/
945 static HRESULT WINAPI
isaxattributes_QueryInterface(
946 ISAXAttributes
* iface
,
950 saxlocator
*This
= impl_from_ISAXAttributes(iface
);
951 TRACE("%p %s %p\n", This
, debugstr_guid(riid
), ppvObject
);
952 return ISAXLocator_QueryInterface(&This
->ISAXLocator_iface
, riid
, ppvObject
);
955 static ULONG WINAPI
isaxattributes_AddRef(ISAXAttributes
* iface
)
957 saxlocator
*This
= impl_from_ISAXAttributes(iface
);
959 return ISAXLocator_AddRef(&This
->ISAXLocator_iface
);
962 static ULONG WINAPI
isaxattributes_Release(ISAXAttributes
* iface
)
964 saxlocator
*This
= impl_from_ISAXAttributes(iface
);
967 return ISAXLocator_Release(&This
->ISAXLocator_iface
);
970 /*** ISAXAttributes methods ***/
971 static HRESULT WINAPI
isaxattributes_getLength(
972 ISAXAttributes
* iface
,
975 saxlocator
*This
= impl_from_ISAXAttributes( iface
);
977 *length
= This
->nb_attributes
;
978 TRACE("Length set to %d\n", *length
);
982 static HRESULT WINAPI
isaxattributes_getURI(
983 ISAXAttributes
* iface
,
988 saxlocator
*This
= impl_from_ISAXAttributes( iface
);
989 TRACE("(%p)->(%d)\n", This
, index
);
991 if(index
>= This
->nb_attributes
|| index
< 0) return E_INVALIDARG
;
992 if(!url
|| !size
) return E_POINTER
;
994 *size
= SysStringLen(This
->attributes
[index
].szURI
);
995 *url
= This
->attributes
[index
].szURI
;
997 TRACE("(%s:%d)\n", debugstr_w(This
->attributes
[index
].szURI
), *size
);
1002 static HRESULT WINAPI
isaxattributes_getLocalName(
1003 ISAXAttributes
* iface
,
1005 const WCHAR
**pLocalName
,
1006 int *pLocalNameLength
)
1008 saxlocator
*This
= impl_from_ISAXAttributes( iface
);
1009 TRACE("(%p)->(%d)\n", This
, nIndex
);
1011 if(nIndex
>=This
->nb_attributes
|| nIndex
<0) return E_INVALIDARG
;
1012 if(!pLocalName
|| !pLocalNameLength
) return E_POINTER
;
1014 *pLocalNameLength
= SysStringLen(This
->attributes
[nIndex
].szLocalname
);
1015 *pLocalName
= This
->attributes
[nIndex
].szLocalname
;
1020 static HRESULT WINAPI
isaxattributes_getQName(
1021 ISAXAttributes
* iface
,
1023 const WCHAR
**pQName
,
1026 saxlocator
*This
= impl_from_ISAXAttributes( iface
);
1027 TRACE("(%p)->(%d)\n", This
, nIndex
);
1029 if(nIndex
>=This
->nb_attributes
|| nIndex
<0) return E_INVALIDARG
;
1030 if(!pQName
|| !pQNameLength
) return E_POINTER
;
1032 *pQNameLength
= SysStringLen(This
->attributes
[nIndex
].szQName
);
1033 *pQName
= This
->attributes
[nIndex
].szQName
;
1038 static HRESULT WINAPI
isaxattributes_getName(
1039 ISAXAttributes
* iface
,
1043 const WCHAR
**localName
,
1044 int *pLocalNameSize
,
1045 const WCHAR
**QName
,
1048 saxlocator
*This
= impl_from_ISAXAttributes( iface
);
1049 TRACE("(%p)->(%d)\n", This
, index
);
1051 if(index
>=This
->nb_attributes
|| index
<0) return E_INVALIDARG
;
1052 if(!uri
|| !pUriLength
|| !localName
|| !pLocalNameSize
1053 || !QName
|| !pQNameLength
) return E_POINTER
;
1055 *pUriLength
= SysStringLen(This
->attributes
[index
].szURI
);
1056 *uri
= This
->attributes
[index
].szURI
;
1057 *pLocalNameSize
= SysStringLen(This
->attributes
[index
].szLocalname
);
1058 *localName
= This
->attributes
[index
].szLocalname
;
1059 *pQNameLength
= SysStringLen(This
->attributes
[index
].szQName
);
1060 *QName
= This
->attributes
[index
].szQName
;
1062 TRACE("(%s, %s, %s)\n", debugstr_w(*uri
), debugstr_w(*localName
), debugstr_w(*QName
));
1067 static HRESULT WINAPI
isaxattributes_getIndexFromName(
1068 ISAXAttributes
* iface
,
1071 const WCHAR
*pLocalName
,
1072 int cocalNameLength
,
1075 saxlocator
*This
= impl_from_ISAXAttributes( iface
);
1077 TRACE("(%p)->(%s, %d, %s, %d)\n", This
, debugstr_w(pUri
), cUriLength
,
1078 debugstr_w(pLocalName
), cocalNameLength
);
1080 if(!pUri
|| !pLocalName
|| !index
) return E_POINTER
;
1082 for(i
=0; i
<This
->nb_attributes
; i
++)
1084 if(cUriLength
!=SysStringLen(This
->attributes
[i
].szURI
)
1085 || cocalNameLength
!=SysStringLen(This
->attributes
[i
].szLocalname
))
1087 if(cUriLength
&& memcmp(pUri
, This
->attributes
[i
].szURI
,
1088 sizeof(WCHAR
)*cUriLength
))
1090 if(cocalNameLength
&& memcmp(pLocalName
, This
->attributes
[i
].szLocalname
,
1091 sizeof(WCHAR
)*cocalNameLength
))
1098 return E_INVALIDARG
;
1101 static HRESULT WINAPI
isaxattributes_getIndexFromQName(
1102 ISAXAttributes
* iface
,
1103 const WCHAR
*pQName
,
1107 saxlocator
*This
= impl_from_ISAXAttributes( iface
);
1109 TRACE("(%p)->(%s, %d)\n", This
, debugstr_w(pQName
), nQNameLength
);
1111 if(!pQName
|| !index
) return E_POINTER
;
1112 if(!nQNameLength
) return E_INVALIDARG
;
1114 for(i
=0; i
<This
->nb_attributes
; i
++)
1116 if(nQNameLength
!=SysStringLen(This
->attributes
[i
].szQName
)) continue;
1117 if(memcmp(pQName
, This
->attributes
[i
].szQName
, sizeof(WCHAR
)*nQNameLength
)) continue;
1123 return E_INVALIDARG
;
1126 static HRESULT WINAPI
isaxattributes_getType(
1127 ISAXAttributes
* iface
,
1129 const WCHAR
**pType
,
1132 saxlocator
*This
= impl_from_ISAXAttributes( iface
);
1134 FIXME("(%p)->(%d) stub\n", This
, nIndex
);
1138 static HRESULT WINAPI
isaxattributes_getTypeFromName(
1139 ISAXAttributes
* iface
,
1142 const WCHAR
*pLocalName
,
1144 const WCHAR
**pType
,
1147 saxlocator
*This
= impl_from_ISAXAttributes( iface
);
1149 FIXME("(%p)->(%s, %d, %s, %d) stub\n", This
, debugstr_w(pUri
), nUri
,
1150 debugstr_w(pLocalName
), nLocalName
);
1154 static HRESULT WINAPI
isaxattributes_getTypeFromQName(
1155 ISAXAttributes
* iface
,
1156 const WCHAR
*pQName
,
1158 const WCHAR
**pType
,
1161 saxlocator
*This
= impl_from_ISAXAttributes( iface
);
1163 FIXME("(%p)->(%s, %d) stub\n", This
, debugstr_w(pQName
), nQName
);
1167 static HRESULT WINAPI
isaxattributes_getValue(
1168 ISAXAttributes
* iface
,
1170 const WCHAR
**value
,
1173 saxlocator
*This
= impl_from_ISAXAttributes( iface
);
1174 TRACE("(%p)->(%d)\n", This
, index
);
1176 if(index
>=This
->nb_attributes
|| index
<0) return E_INVALIDARG
;
1177 if(!value
|| !nValue
) return E_POINTER
;
1179 *nValue
= SysStringLen(This
->attributes
[index
].szValue
);
1180 *value
= This
->attributes
[index
].szValue
;
1182 TRACE("(%s:%d)\n", debugstr_w(*value
), *nValue
);
1187 static HRESULT WINAPI
isaxattributes_getValueFromName(
1188 ISAXAttributes
* iface
,
1191 const WCHAR
*pLocalName
,
1193 const WCHAR
**pValue
,
1198 saxlocator
*This
= impl_from_ISAXAttributes( iface
);
1199 TRACE("(%p)->(%s, %d, %s, %d)\n", This
, debugstr_w(pUri
), nUri
,
1200 debugstr_w(pLocalName
), nLocalName
);
1202 hr
= ISAXAttributes_getIndexFromName(iface
,
1203 pUri
, nUri
, pLocalName
, nLocalName
, &index
);
1204 if(hr
==S_OK
) hr
= ISAXAttributes_getValue(iface
, index
, pValue
, nValue
);
1209 static HRESULT WINAPI
isaxattributes_getValueFromQName(
1210 ISAXAttributes
* iface
,
1211 const WCHAR
*pQName
,
1213 const WCHAR
**pValue
,
1218 saxlocator
*This
= impl_from_ISAXAttributes( iface
);
1219 TRACE("(%p)->(%s, %d)\n", This
, debugstr_w(pQName
), nQName
);
1221 hr
= ISAXAttributes_getIndexFromQName(iface
, pQName
, nQName
, &index
);
1222 if(hr
==S_OK
) hr
= ISAXAttributes_getValue(iface
, index
, pValue
, nValue
);
1227 static const struct ISAXAttributesVtbl isaxattributes_vtbl
=
1229 isaxattributes_QueryInterface
,
1230 isaxattributes_AddRef
,
1231 isaxattributes_Release
,
1232 isaxattributes_getLength
,
1233 isaxattributes_getURI
,
1234 isaxattributes_getLocalName
,
1235 isaxattributes_getQName
,
1236 isaxattributes_getName
,
1237 isaxattributes_getIndexFromName
,
1238 isaxattributes_getIndexFromQName
,
1239 isaxattributes_getType
,
1240 isaxattributes_getTypeFromName
,
1241 isaxattributes_getTypeFromQName
,
1242 isaxattributes_getValue
,
1243 isaxattributes_getValueFromName
,
1244 isaxattributes_getValueFromQName
1247 static HRESULT
SAXAttributes_populate(saxlocator
*locator
,
1248 int nb_namespaces
, const xmlChar
**xmlNamespaces
,
1249 int nb_attributes
, const xmlChar
**xmlAttributes
)
1251 static const xmlChar xmlns
[] = "xmlns";
1252 static const WCHAR xmlnsW
[] = { 'x','m','l','n','s',0 };
1254 struct _attributes
*attrs
;
1257 /* skip namespace definitions */
1258 if ((locator
->saxreader
->features
& NamespacePrefixes
) == 0)
1261 locator
->nb_attributes
= nb_namespaces
+ nb_attributes
;
1262 if(locator
->nb_attributes
> locator
->attributesSize
)
1264 attrs
= heap_realloc(locator
->attributes
, sizeof(struct _attributes
)*locator
->nb_attributes
*2);
1267 locator
->nb_attributes
= 0;
1268 return E_OUTOFMEMORY
;
1270 locator
->attributes
= attrs
;
1274 attrs
= locator
->attributes
;
1277 for (i
= 0; i
< nb_namespaces
; i
++)
1279 attrs
[nb_attributes
+i
].szLocalname
= SysAllocStringLen(NULL
, 0);
1280 attrs
[nb_attributes
+i
].szURI
= locator
->namespaceUri
;
1281 attrs
[nb_attributes
+i
].szValue
= bstr_from_xmlChar(xmlNamespaces
[2*i
+1]);
1282 if(!xmlNamespaces
[2*i
])
1283 attrs
[nb_attributes
+i
].szQName
= SysAllocString(xmlnsW
);
1285 attrs
[nb_attributes
+i
].szQName
= QName_from_xmlChar(xmlns
, xmlNamespaces
[2*i
]);
1288 for (i
= 0; i
< nb_attributes
; i
++)
1290 static const xmlChar xmlA
[] = "xml";
1292 if (xmlStrEqual(xmlAttributes
[i
*5+1], xmlA
))
1293 attrs
[i
].szURI
= bstr_from_xmlChar(xmlAttributes
[i
*5+2]);
1295 /* that's an important feature to keep same uri pointer for every reported attribute */
1296 attrs
[i
].szURI
= find_element_uri(locator
, xmlAttributes
[i
*5+2]);
1298 attrs
[i
].szLocalname
= bstr_from_xmlChar(xmlAttributes
[i
*5]);
1299 attrs
[i
].szValue
= bstr_from_xmlCharN(xmlAttributes
[i
*5+3],
1300 xmlAttributes
[i
*5+4]-xmlAttributes
[i
*5+3]);
1301 attrs
[i
].szQName
= QName_from_xmlChar(xmlAttributes
[i
*5+1],
1302 xmlAttributes
[i
*5]);
1308 /*** LibXML callbacks ***/
1309 static void libxmlStartDocument(void *ctx
)
1311 saxlocator
*This
= ctx
;
1312 struct saxcontenthandler_iface
*handler
= saxreader_get_contenthandler(This
->saxreader
);
1315 if (This
->saxreader
->version
>= MSXML4
)
1317 const xmlChar
*p
= This
->pParserCtxt
->input
->cur
-1;
1318 update_position(This
, FALSE
);
1319 while(p
>This
->pParserCtxt
->input
->base
&& *p
!='>')
1321 if(*p
=='\n' || (*p
=='\r' && *(p
+1)!='\n'))
1326 for(; p
>=This
->pParserCtxt
->input
->base
&& *p
!='\n' && *p
!='\r'; p
--)
1330 /* store version value, declaration has to contain version attribute */
1331 if (This
->pParserCtxt
->standalone
!= -1)
1333 SysFreeString(This
->saxreader
->xmldecl_version
);
1334 This
->saxreader
->xmldecl_version
= bstr_from_xmlChar(This
->pParserCtxt
->version
);
1337 if (saxreader_has_handler(This
, SAXContentHandler
))
1339 if(This
->vbInterface
)
1340 hr
= IVBSAXContentHandler_startDocument(handler
->vbhandler
);
1342 hr
= ISAXContentHandler_startDocument(handler
->handler
);
1344 if (sax_callback_failed(This
, hr
))
1345 format_error_message_from_id(This
, hr
);
1349 static void libxmlEndDocument(void *ctx
)
1351 saxlocator
*This
= ctx
;
1352 struct saxcontenthandler_iface
*handler
= saxreader_get_contenthandler(This
->saxreader
);
1355 if (This
->saxreader
->version
>= MSXML4
) {
1356 update_position(This
, FALSE
);
1357 if(This
->column
> 1)
1365 if(This
->ret
!= S_OK
) return;
1367 if (saxreader_has_handler(This
, SAXContentHandler
))
1369 if(This
->vbInterface
)
1370 hr
= IVBSAXContentHandler_endDocument(handler
->vbhandler
);
1372 hr
= ISAXContentHandler_endDocument(handler
->handler
);
1374 if (sax_callback_failed(This
, hr
))
1375 format_error_message_from_id(This
, hr
);
1379 static void libxmlStartElementNS(
1381 const xmlChar
*localname
,
1382 const xmlChar
*prefix
,
1385 const xmlChar
**namespaces
,
1388 const xmlChar
**attributes
)
1390 saxlocator
*This
= ctx
;
1391 struct saxcontenthandler_iface
*handler
= saxreader_get_contenthandler(This
->saxreader
);
1392 element_entry
*element
;
1396 update_position(This
, TRUE
);
1397 if(*(This
->pParserCtxt
->input
->cur
) == '/')
1399 if(This
->saxreader
->version
< MSXML4
)
1402 element
= alloc_element_entry(localname
, prefix
, nb_namespaces
, namespaces
);
1403 push_element_ns(This
, element
);
1405 if (is_namespaces_enabled(This
->saxreader
))
1409 for (i
= 0; i
< nb_namespaces
&& saxreader_has_handler(This
, SAXContentHandler
); i
++)
1411 if (This
->vbInterface
)
1412 hr
= IVBSAXContentHandler_startPrefixMapping(
1414 &element
->ns
[i
].prefix
,
1415 &element
->ns
[i
].uri
);
1417 hr
= ISAXContentHandler_startPrefixMapping(
1419 element
->ns
[i
].prefix
,
1420 SysStringLen(element
->ns
[i
].prefix
),
1422 SysStringLen(element
->ns
[i
].uri
));
1424 if (sax_callback_failed(This
, hr
))
1426 format_error_message_from_id(This
, hr
);
1432 uri
= find_element_uri(This
, URI
);
1433 hr
= SAXAttributes_populate(This
, nb_namespaces
, namespaces
, nb_attributes
, attributes
);
1434 if (hr
== S_OK
&& saxreader_has_handler(This
, SAXContentHandler
))
1438 if (is_namespaces_enabled(This
->saxreader
))
1439 local
= element
->local
;
1443 if (This
->vbInterface
)
1444 hr
= IVBSAXContentHandler_startElement(handler
->vbhandler
,
1445 &uri
, &local
, &element
->qname
, &This
->IVBSAXAttributes_iface
);
1447 hr
= ISAXContentHandler_startElement(handler
->handler
,
1448 uri
, SysStringLen(uri
),
1449 local
, SysStringLen(local
),
1450 element
->qname
, SysStringLen(element
->qname
),
1451 &This
->ISAXAttributes_iface
);
1453 if (sax_callback_failed(This
, hr
))
1454 format_error_message_from_id(This
, hr
);
1458 static void libxmlEndElementNS(
1460 const xmlChar
*localname
,
1461 const xmlChar
*prefix
,
1464 saxlocator
*This
= ctx
;
1465 struct saxcontenthandler_iface
*handler
= saxreader_get_contenthandler(This
->saxreader
);
1466 element_entry
*element
;
1471 update_position(This
, FALSE
);
1472 p
= This
->pParserCtxt
->input
->cur
;
1474 if (This
->saxreader
->version
>= MSXML4
)
1477 while(p
>This
->pParserCtxt
->input
->base
&& *p
!='>')
1479 if(*p
=='\n' || (*p
=='\r' && *(p
+1)!='\n'))
1484 else if(*(p
-1)!='>' || *(p
-2)!='/')
1487 while(p
-2>=This
->pParserCtxt
->input
->base
1488 && *(p
-2)!='<' && *(p
-1)!='/')
1490 if(*p
=='\n' || (*p
=='\r' && *(p
+1)!='\n'))
1496 for(; p
>=This
->pParserCtxt
->input
->base
&& *p
!='\n' && *p
!='\r'; p
--)
1499 uri
= find_element_uri(This
, URI
);
1500 element
= pop_element_ns(This
);
1502 if (!saxreader_has_handler(This
, SAXContentHandler
))
1504 This
->nb_attributes
= 0;
1505 free_element_entry(element
);
1509 if (is_namespaces_enabled(This
->saxreader
))
1510 local
= element
->local
;
1514 if (This
->vbInterface
)
1515 hr
= IVBSAXContentHandler_endElement(
1517 &uri
, &local
, &element
->qname
);
1519 hr
= ISAXContentHandler_endElement(
1521 uri
, SysStringLen(uri
),
1522 local
, SysStringLen(local
),
1523 element
->qname
, SysStringLen(element
->qname
));
1525 This
->nb_attributes
= 0;
1527 if (sax_callback_failed(This
, hr
))
1529 format_error_message_from_id(This
, hr
);
1530 free_element_entry(element
);
1534 if (is_namespaces_enabled(This
->saxreader
))
1537 while (iterate_endprefix_index(This
, element
, &i
) && saxreader_has_handler(This
, SAXContentHandler
))
1539 if (This
->vbInterface
)
1540 hr
= IVBSAXContentHandler_endPrefixMapping(
1541 handler
->vbhandler
, &element
->ns
[i
].prefix
);
1543 hr
= ISAXContentHandler_endPrefixMapping(
1544 handler
->handler
, element
->ns
[i
].prefix
, SysStringLen(element
->ns
[i
].prefix
));
1546 if (sax_callback_failed(This
, hr
)) break;
1549 if (sax_callback_failed(This
, hr
))
1550 format_error_message_from_id(This
, hr
);
1553 free_element_entry(element
);
1556 static void libxmlCharacters(
1561 saxlocator
*This
= ctx
;
1562 struct saxcontenthandler_iface
*handler
= saxreader_get_contenthandler(This
->saxreader
);
1566 BOOL lastEvent
= FALSE
;
1568 if (!saxreader_has_handler(This
, SAXContentHandler
)) return;
1570 update_position(This
, FALSE
);
1571 cur
= (xmlChar
*)This
->pParserCtxt
->input
->cur
;
1572 while(cur
>=This
->pParserCtxt
->input
->base
&& *cur
!='>')
1574 if(*cur
=='\n' || (*cur
=='\r' && *(cur
+1)!='\n'))
1579 for(; cur
>=This
->pParserCtxt
->input
->base
&& *cur
!='\n' && *cur
!='\r'; cur
--)
1583 if(*(ch
-1)=='\r') cur
--;
1588 while(end
-ch
<len
&& *end
!='\r') end
++;
1599 if (This
->saxreader
->version
>= MSXML4
)
1603 for(p
=cur
; p
!=end
; p
++)
1620 Chars
= pooled_bstr_from_xmlCharN(&This
->saxreader
->pool
, cur
, end
-cur
);
1621 if(This
->vbInterface
)
1622 hr
= IVBSAXContentHandler_characters(handler
->vbhandler
, &Chars
);
1624 hr
= ISAXContentHandler_characters(handler
->handler
, Chars
, SysStringLen(Chars
));
1626 if (sax_callback_failed(This
, hr
))
1628 format_error_message_from_id(This
, hr
);
1632 if (This
->saxreader
->version
< MSXML4
)
1633 This
->column
+= end
-cur
;
1646 if(end
-ch
== len
) break;
1650 static void libxmlSetDocumentLocator(
1652 xmlSAXLocatorPtr loc
)
1654 saxlocator
*This
= ctx
;
1655 struct saxcontenthandler_iface
*handler
= saxreader_get_contenthandler(This
->saxreader
);
1658 if (saxreader_has_handler(This
, SAXContentHandler
))
1660 if(This
->vbInterface
)
1661 hr
= IVBSAXContentHandler_putref_documentLocator(handler
->vbhandler
,
1662 &This
->IVBSAXLocator_iface
);
1664 hr
= ISAXContentHandler_putDocumentLocator(handler
->handler
, &This
->ISAXLocator_iface
);
1668 format_error_message_from_id(This
, hr
);
1671 static void libxmlComment(void *ctx
, const xmlChar
*value
)
1673 saxlocator
*This
= ctx
;
1674 struct saxlexicalhandler_iface
*handler
= saxreader_get_lexicalhandler(This
->saxreader
);
1677 const xmlChar
*p
= This
->pParserCtxt
->input
->cur
;
1679 update_position(This
, FALSE
);
1680 while(p
-4>=This
->pParserCtxt
->input
->base
1681 && memcmp(p
-4, "<!--", sizeof(char[4])))
1683 if(*p
=='\n' || (*p
=='\r' && *(p
+1)!='\n'))
1689 for(; p
>=This
->pParserCtxt
->input
->base
&& *p
!='\n' && *p
!='\r'; p
--)
1692 if (!saxreader_has_handler(This
, SAXLexicalHandler
)) return;
1694 bValue
= pooled_bstr_from_xmlChar(&This
->saxreader
->pool
, value
);
1696 if (This
->vbInterface
)
1697 hr
= IVBSAXLexicalHandler_comment(handler
->vbhandler
, &bValue
);
1699 hr
= ISAXLexicalHandler_comment(handler
->handler
, bValue
, SysStringLen(bValue
));
1702 format_error_message_from_id(This
, hr
);
1705 static void libxmlFatalError(void *ctx
, const char *msg
, ...)
1707 saxlocator
*This
= ctx
;
1708 struct saxerrorhandler_iface
*handler
= saxreader_get_errorhandler(This
->saxreader
);
1714 if(This
->ret
!= S_OK
) {
1715 xmlStopParser(This
->pParserCtxt
);
1719 va_start(args
, msg
);
1720 vsprintf(message
, msg
, args
);
1723 len
= MultiByteToWideChar(CP_UNIXCP
, 0, message
, -1, NULL
, 0);
1724 error
= heap_alloc(sizeof(WCHAR
)*len
);
1727 MultiByteToWideChar(CP_UNIXCP
, 0, message
, -1, error
, len
);
1728 TRACE("fatal error for %p: %s\n", This
, debugstr_w(error
));
1731 if (!saxreader_has_handler(This
, SAXErrorHandler
))
1733 xmlStopParser(This
->pParserCtxt
);
1739 FIXME("Error handling is not compatible.\n");
1741 if(This
->vbInterface
)
1743 BSTR bstrError
= SysAllocString(error
);
1744 IVBSAXErrorHandler_fatalError(handler
->vbhandler
, &This
->IVBSAXLocator_iface
,
1745 &bstrError
, E_FAIL
);
1746 SysFreeString(bstrError
);
1749 ISAXErrorHandler_fatalError(handler
->handler
, &This
->ISAXLocator_iface
, error
, E_FAIL
);
1753 xmlStopParser(This
->pParserCtxt
);
1757 static void libxmlCDataBlock(void *ctx
, const xmlChar
*value
, int len
)
1759 saxlocator
*This
= ctx
;
1760 struct saxcontenthandler_iface
*content
= saxreader_get_contenthandler(This
->saxreader
);
1761 struct saxlexicalhandler_iface
*lexical
= saxreader_get_lexicalhandler(This
->saxreader
);
1763 xmlChar
*beg
= (xmlChar
*)This
->pParserCtxt
->input
->cur
-len
;
1767 BOOL lastEvent
= FALSE
, change
;
1769 update_position(This
, FALSE
);
1770 while(beg
-9>=This
->pParserCtxt
->input
->base
1771 && memcmp(beg
-9, "<![CDATA[", sizeof(char[9])))
1773 if(*beg
=='\n' || (*beg
=='\r' && *(beg
+1)!='\n'))
1778 for(; beg
>=This
->pParserCtxt
->input
->base
&& *beg
!='\n' && *beg
!='\r'; beg
--)
1781 if (saxreader_has_handler(This
, SAXLexicalHandler
))
1783 if (This
->vbInterface
)
1784 hr
= IVBSAXLexicalHandler_startCDATA(lexical
->vbhandler
);
1786 hr
= ISAXLexicalHandler_startCDATA(lexical
->handler
);
1791 format_error_message_from_id(This
, hr
);
1795 realLen
= This
->pParserCtxt
->input
->cur
-beg
-3;
1801 while(end
-beg
<realLen
&& *end
!='\r') end
++;
1802 if(end
-beg
==realLen
)
1807 else if(end
-beg
==realLen
-1 && *end
=='\r' && *(end
+1)=='\n')
1810 if(*end
== '\r') change
= TRUE
;
1811 else change
= FALSE
;
1813 if(change
) *end
= '\n';
1815 if (saxreader_has_handler(This
, SAXContentHandler
))
1817 Chars
= pooled_bstr_from_xmlCharN(&This
->saxreader
->pool
, cur
, end
-cur
+1);
1818 if (This
->vbInterface
)
1819 hr
= IVBSAXContentHandler_characters(content
->vbhandler
, &Chars
);
1821 hr
= ISAXContentHandler_characters(content
->handler
, Chars
, SysStringLen(Chars
));
1824 if(change
) *end
= '\r';
1829 This
->column
+= end
-cur
+2;
1834 if (saxreader_has_handler(This
, SAXLexicalHandler
))
1836 if (This
->vbInterface
)
1837 hr
= IVBSAXLexicalHandler_endCDATA(lexical
->vbhandler
);
1839 hr
= ISAXLexicalHandler_endCDATA(lexical
->handler
);
1843 format_error_message_from_id(This
, hr
);
1845 This
->column
+= 4+end
-cur
;
1848 static xmlParserInputPtr
libxmlresolveentity(void *ctx
, const xmlChar
*publicid
, const xmlChar
*systemid
)
1850 FIXME("entity resolving not implemented, %s, %s\n", publicid
, systemid
);
1851 return xmlSAX2ResolveEntity(ctx
, publicid
, systemid
);
1854 /*** IVBSAXLocator interface ***/
1855 /*** IUnknown methods ***/
1856 static HRESULT WINAPI
ivbsaxlocator_QueryInterface(IVBSAXLocator
* iface
, REFIID riid
, void **ppvObject
)
1858 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1860 TRACE("%p %s %p\n", This
, debugstr_guid( riid
), ppvObject
);
1864 if ( IsEqualGUID( riid
, &IID_IUnknown
) ||
1865 IsEqualGUID( riid
, &IID_IDispatch
) ||
1866 IsEqualGUID( riid
, &IID_IVBSAXLocator
))
1870 else if ( IsEqualGUID( riid
, &IID_IVBSAXAttributes
))
1872 *ppvObject
= &This
->IVBSAXAttributes_iface
;
1876 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
1877 return E_NOINTERFACE
;
1880 IVBSAXLocator_AddRef( iface
);
1885 static ULONG WINAPI
ivbsaxlocator_AddRef(IVBSAXLocator
* iface
)
1887 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1888 TRACE("%p\n", This
);
1889 return InterlockedIncrement( &This
->ref
);
1892 static ULONG WINAPI
ivbsaxlocator_Release(
1893 IVBSAXLocator
* iface
)
1895 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1896 return ISAXLocator_Release((ISAXLocator
*)&This
->IVBSAXLocator_iface
);
1899 /*** IDispatch methods ***/
1900 static HRESULT WINAPI
ivbsaxlocator_GetTypeInfoCount( IVBSAXLocator
*iface
, UINT
* pctinfo
)
1902 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1904 TRACE("(%p)->(%p)\n", This
, pctinfo
);
1911 static HRESULT WINAPI
ivbsaxlocator_GetTypeInfo(
1912 IVBSAXLocator
*iface
,
1913 UINT iTInfo
, LCID lcid
, ITypeInfo
** ti
)
1915 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1918 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ti
);
1920 hr
= get_typeinfo(IVBSAXLocator_tid
, ti
);
1921 ITypeInfo_AddRef(*ti
);
1925 static HRESULT WINAPI
ivbsaxlocator_GetIDsOfNames(
1926 IVBSAXLocator
*iface
,
1928 LPOLESTR
* rgszNames
,
1933 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1934 ITypeInfo
*typeinfo
;
1937 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
1940 if(!rgszNames
|| cNames
== 0 || !rgDispId
)
1941 return E_INVALIDARG
;
1943 hr
= get_typeinfo(IVBSAXLocator_tid
, &typeinfo
);
1945 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
1950 static HRESULT WINAPI
ivbsaxlocator_Invoke(
1951 IVBSAXLocator
*iface
,
1952 DISPID dispIdMember
,
1956 DISPPARAMS
* pDispParams
,
1957 VARIANT
* pVarResult
,
1958 EXCEPINFO
* pExcepInfo
,
1961 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1962 ITypeInfo
*typeinfo
;
1965 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
1966 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1968 hr
= get_typeinfo(IVBSAXLocator_tid
, &typeinfo
);
1970 hr
= ITypeInfo_Invoke(typeinfo
, &This
->IVBSAXLocator_iface
, dispIdMember
, wFlags
,
1971 pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1976 /*** IVBSAXLocator methods ***/
1977 static HRESULT WINAPI
ivbsaxlocator_get_columnNumber(
1978 IVBSAXLocator
* iface
,
1981 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1982 return ISAXLocator_getColumnNumber((ISAXLocator
*)&This
->IVBSAXLocator_iface
, pnColumn
);
1985 static HRESULT WINAPI
ivbsaxlocator_get_lineNumber(
1986 IVBSAXLocator
* iface
,
1989 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1990 return ISAXLocator_getLineNumber((ISAXLocator
*)&This
->IVBSAXLocator_iface
, pnLine
);
1993 static HRESULT WINAPI
ivbsaxlocator_get_publicId(
1994 IVBSAXLocator
* iface
,
1997 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1998 return ISAXLocator_getPublicId((ISAXLocator
*)&This
->IVBSAXLocator_iface
,
1999 (const WCHAR
**)publicId
);
2002 static HRESULT WINAPI
ivbsaxlocator_get_systemId(
2003 IVBSAXLocator
* iface
,
2006 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
2007 return ISAXLocator_getSystemId((ISAXLocator
*)&This
->IVBSAXLocator_iface
,
2008 (const WCHAR
**)systemId
);
2011 static const struct IVBSAXLocatorVtbl VBSAXLocatorVtbl
=
2013 ivbsaxlocator_QueryInterface
,
2014 ivbsaxlocator_AddRef
,
2015 ivbsaxlocator_Release
,
2016 ivbsaxlocator_GetTypeInfoCount
,
2017 ivbsaxlocator_GetTypeInfo
,
2018 ivbsaxlocator_GetIDsOfNames
,
2019 ivbsaxlocator_Invoke
,
2020 ivbsaxlocator_get_columnNumber
,
2021 ivbsaxlocator_get_lineNumber
,
2022 ivbsaxlocator_get_publicId
,
2023 ivbsaxlocator_get_systemId
2026 /*** ISAXLocator interface ***/
2027 /*** IUnknown methods ***/
2028 static HRESULT WINAPI
isaxlocator_QueryInterface(ISAXLocator
* iface
, REFIID riid
, void **ppvObject
)
2030 saxlocator
*This
= impl_from_ISAXLocator( iface
);
2032 TRACE("%p %s %p\n", This
, debugstr_guid( riid
), ppvObject
);
2036 if ( IsEqualGUID( riid
, &IID_IUnknown
) ||
2037 IsEqualGUID( riid
, &IID_ISAXLocator
))
2041 else if ( IsEqualGUID( riid
, &IID_ISAXAttributes
))
2043 *ppvObject
= &This
->ISAXAttributes_iface
;
2047 WARN("interface %s not implemented\n", debugstr_guid(riid
));
2048 return E_NOINTERFACE
;
2051 ISAXLocator_AddRef( iface
);
2056 static ULONG WINAPI
isaxlocator_AddRef(ISAXLocator
* iface
)
2058 saxlocator
*This
= impl_from_ISAXLocator( iface
);
2059 ULONG ref
= InterlockedIncrement( &This
->ref
);
2060 TRACE("(%p)->(%d)\n", This
, ref
);
2064 static ULONG WINAPI
isaxlocator_Release(
2067 saxlocator
*This
= impl_from_ISAXLocator( iface
);
2068 LONG ref
= InterlockedDecrement( &This
->ref
);
2070 TRACE("(%p)->(%d)\n", This
, ref
);
2074 element_entry
*element
, *element2
;
2077 SysFreeString(This
->publicId
);
2078 SysFreeString(This
->systemId
);
2079 SysFreeString(This
->namespaceUri
);
2081 for(index
=0; index
<This
->nb_attributes
; index
++)
2083 SysFreeString(This
->attributes
[index
].szLocalname
);
2084 SysFreeString(This
->attributes
[index
].szValue
);
2085 SysFreeString(This
->attributes
[index
].szQName
);
2087 heap_free(This
->attributes
);
2090 LIST_FOR_EACH_ENTRY_SAFE(element
, element2
, &This
->elements
, element_entry
, entry
)
2092 list_remove(&element
->entry
);
2093 free_element_entry(element
);
2096 ISAXXMLReader_Release(&This
->saxreader
->ISAXXMLReader_iface
);
2103 /*** ISAXLocator methods ***/
2104 static HRESULT WINAPI
isaxlocator_getColumnNumber(
2108 saxlocator
*This
= impl_from_ISAXLocator( iface
);
2110 *pnColumn
= This
->column
;
2114 static HRESULT WINAPI
isaxlocator_getLineNumber(
2118 saxlocator
*This
= impl_from_ISAXLocator( iface
);
2120 *pnLine
= This
->line
;
2124 static HRESULT WINAPI
isaxlocator_getPublicId(
2126 const WCHAR
** ppwchPublicId
)
2129 saxlocator
*This
= impl_from_ISAXLocator( iface
);
2131 SysFreeString(This
->publicId
);
2133 publicId
= bstr_from_xmlChar(xmlSAX2GetPublicId(This
->pParserCtxt
));
2134 if(SysStringLen(publicId
))
2135 This
->publicId
= publicId
;
2138 SysFreeString(publicId
);
2139 This
->publicId
= NULL
;
2142 *ppwchPublicId
= This
->publicId
;
2146 static HRESULT WINAPI
isaxlocator_getSystemId(
2148 const WCHAR
** ppwchSystemId
)
2151 saxlocator
*This
= impl_from_ISAXLocator( iface
);
2153 SysFreeString(This
->systemId
);
2155 systemId
= bstr_from_xmlChar(xmlSAX2GetSystemId(This
->pParserCtxt
));
2156 if(SysStringLen(systemId
))
2157 This
->systemId
= systemId
;
2160 SysFreeString(systemId
);
2161 This
->systemId
= NULL
;
2164 *ppwchSystemId
= This
->systemId
;
2168 static const struct ISAXLocatorVtbl SAXLocatorVtbl
=
2170 isaxlocator_QueryInterface
,
2172 isaxlocator_Release
,
2173 isaxlocator_getColumnNumber
,
2174 isaxlocator_getLineNumber
,
2175 isaxlocator_getPublicId
,
2176 isaxlocator_getSystemId
2179 static HRESULT
SAXLocator_create(saxreader
*reader
, saxlocator
**ppsaxlocator
, BOOL vbInterface
)
2181 static const WCHAR w3xmlns
[] = { 'h','t','t','p',':','/','/', 'w','w','w','.','w','3','.',
2182 'o','r','g','/','2','0','0','0','/','x','m','l','n','s','/',0 };
2184 saxlocator
*locator
;
2186 locator
= heap_alloc( sizeof (*locator
) );
2188 return E_OUTOFMEMORY
;
2190 locator
->IVBSAXLocator_iface
.lpVtbl
= &VBSAXLocatorVtbl
;
2191 locator
->ISAXLocator_iface
.lpVtbl
= &SAXLocatorVtbl
;
2192 locator
->IVBSAXAttributes_iface
.lpVtbl
= &ivbsaxattributes_vtbl
;
2193 locator
->ISAXAttributes_iface
.lpVtbl
= &isaxattributes_vtbl
;
2195 locator
->vbInterface
= vbInterface
;
2197 locator
->saxreader
= reader
;
2198 ISAXXMLReader_AddRef(&reader
->ISAXXMLReader_iface
);
2200 locator
->pParserCtxt
= NULL
;
2201 locator
->publicId
= NULL
;
2202 locator
->systemId
= NULL
;
2203 locator
->line
= reader
->version
< MSXML4
? 0 : 1;
2204 locator
->column
= 0;
2205 locator
->ret
= S_OK
;
2206 if (locator
->saxreader
->version
>= MSXML6
)
2207 locator
->namespaceUri
= SysAllocString(w3xmlns
);
2209 locator
->namespaceUri
= SysAllocStringLen(NULL
, 0);
2210 if(!locator
->namespaceUri
)
2212 ISAXXMLReader_Release(&reader
->ISAXXMLReader_iface
);
2214 return E_OUTOFMEMORY
;
2217 locator
->attributesSize
= 8;
2218 locator
->nb_attributes
= 0;
2219 locator
->attributes
= heap_alloc(sizeof(struct _attributes
)*locator
->attributesSize
);
2220 if(!locator
->attributes
)
2222 ISAXXMLReader_Release(&reader
->ISAXXMLReader_iface
);
2223 SysFreeString(locator
->namespaceUri
);
2225 return E_OUTOFMEMORY
;
2228 list_init(&locator
->elements
);
2230 *ppsaxlocator
= locator
;
2232 TRACE("returning %p\n", *ppsaxlocator
);
2237 /*** SAXXMLReader internal functions ***/
2238 static HRESULT
internal_parseBuffer(saxreader
*This
, const char *buffer
, int size
, BOOL vbInterface
)
2240 xmlCharEncoding encoding
= XML_CHAR_ENCODING_NONE
;
2241 xmlChar
*enc_name
= NULL
;
2242 saxlocator
*locator
;
2245 TRACE("(%p)->(%p %d)\n", This
, buffer
, size
);
2247 hr
= SAXLocator_create(This
, &locator
, vbInterface
);
2253 const unsigned char *buff
= (unsigned char*)buffer
;
2255 encoding
= xmlDetectCharEncoding((xmlChar
*)buffer
, 4);
2256 enc_name
= (xmlChar
*)xmlGetCharEncodingName(encoding
);
2257 TRACE("detected encoding: %s\n", enc_name
);
2258 /* skip BOM, parser won't switch encodings and so won't skip it on its own */
2259 if ((encoding
== XML_CHAR_ENCODING_UTF8
) &&
2260 buff
[0] == 0xEF && buff
[1] == 0xBB && buff
[2] == 0xBF)
2267 /* if libxml2 detection failed try to guess */
2268 if (encoding
== XML_CHAR_ENCODING_NONE
)
2270 const WCHAR
*ptr
= (WCHAR
*)buffer
;
2271 /* xml declaration with possibly specfied encoding will be still handled by parser */
2272 if ((size
>= 2) && *ptr
== '<' && ptr
[1] != '?')
2274 enc_name
= (xmlChar
*)xmlGetCharEncodingName(XML_CHAR_ENCODING_UTF16LE
);
2275 encoding
= XML_CHAR_ENCODING_UTF16LE
;
2278 else if (encoding
== XML_CHAR_ENCODING_UTF8
)
2279 enc_name
= (xmlChar
*)xmlGetCharEncodingName(encoding
);
2283 locator
->pParserCtxt
= xmlCreateMemoryParserCtxt(buffer
, size
);
2284 if (!locator
->pParserCtxt
)
2286 ISAXLocator_Release(&locator
->ISAXLocator_iface
);
2292 locator
->pParserCtxt
->encoding
= xmlStrdup(enc_name
);
2293 if (encoding
== XML_CHAR_ENCODING_UTF16LE
) {
2294 TRACE("switching to %s\n", enc_name
);
2295 xmlSwitchEncoding(locator
->pParserCtxt
, encoding
);
2299 xmlFree(locator
->pParserCtxt
->sax
);
2300 locator
->pParserCtxt
->sax
= &locator
->saxreader
->sax
;
2301 locator
->pParserCtxt
->userData
= locator
;
2303 This
->isParsing
= TRUE
;
2304 if(xmlParseDocument(locator
->pParserCtxt
) == -1 && locator
->ret
== S_OK
)
2308 This
->isParsing
= FALSE
;
2310 if(locator
->pParserCtxt
)
2312 locator
->pParserCtxt
->sax
= NULL
;
2313 xmlFreeParserCtxt(locator
->pParserCtxt
);
2314 locator
->pParserCtxt
= NULL
;
2317 ISAXLocator_Release(&locator
->ISAXLocator_iface
);
2321 static HRESULT
internal_parseStream(saxreader
*This
, ISequentialStream
*stream
, BOOL vbInterface
)
2323 saxlocator
*locator
;
2330 hr
= ISequentialStream_Read(stream
, data
, sizeof(data
), &dataRead
);
2331 if(FAILED(hr
)) return hr
;
2333 hr
= SAXLocator_create(This
, &locator
, vbInterface
);
2334 if(FAILED(hr
)) return hr
;
2336 locator
->pParserCtxt
= xmlCreatePushParserCtxt(
2337 &locator
->saxreader
->sax
, locator
,
2338 data
, dataRead
, NULL
);
2339 if(!locator
->pParserCtxt
)
2341 ISAXLocator_Release(&locator
->ISAXLocator_iface
);
2345 This
->isParsing
= TRUE
;
2347 if(dataRead
!= sizeof(data
))
2349 ret
= xmlParseChunk(locator
->pParserCtxt
, data
, 0, 1);
2350 hr
= ret
!=XML_ERR_OK
&& locator
->ret
==S_OK
? E_FAIL
: locator
->ret
;
2357 hr
= ISequentialStream_Read(stream
, data
, sizeof(data
), &dataRead
);
2358 if (FAILED(hr
)) break;
2360 ret
= xmlParseChunk(locator
->pParserCtxt
, data
, dataRead
, 0);
2361 hr
= ret
!=XML_ERR_OK
&& locator
->ret
==S_OK
? E_FAIL
: locator
->ret
;
2363 if (hr
!= S_OK
) break;
2365 if (dataRead
!= sizeof(data
))
2367 ret
= xmlParseChunk(locator
->pParserCtxt
, data
, 0, 1);
2368 hr
= ret
!=XML_ERR_OK
&& locator
->ret
==S_OK
? E_FAIL
: locator
->ret
;
2374 This
->isParsing
= FALSE
;
2376 xmlFreeParserCtxt(locator
->pParserCtxt
);
2377 locator
->pParserCtxt
= NULL
;
2378 ISAXLocator_Release(&locator
->ISAXLocator_iface
);
2382 static HRESULT
internal_parse(
2389 TRACE("(%p)->(%s)\n", This
, debugstr_variant(&varInput
));
2391 /* Dispose of the BSTRs in the pool from a prior run, if any. */
2392 free_bstr_pool(&This
->pool
);
2394 switch(V_VT(&varInput
))
2397 hr
= internal_parseBuffer(This
, (const char*)V_BSTR(&varInput
),
2398 strlenW(V_BSTR(&varInput
))*sizeof(WCHAR
), vbInterface
);
2400 case VT_ARRAY
|VT_UI1
: {
2402 LONG lBound
, uBound
;
2405 hr
= SafeArrayGetLBound(V_ARRAY(&varInput
), 1, &lBound
);
2406 if(hr
!= S_OK
) break;
2407 hr
= SafeArrayGetUBound(V_ARRAY(&varInput
), 1, &uBound
);
2408 if(hr
!= S_OK
) break;
2409 dataRead
= (uBound
-lBound
)*SafeArrayGetElemsize(V_ARRAY(&varInput
));
2410 hr
= SafeArrayAccessData(V_ARRAY(&varInput
), &pSAData
);
2411 if(hr
!= S_OK
) break;
2412 hr
= internal_parseBuffer(This
, pSAData
, dataRead
, vbInterface
);
2413 SafeArrayUnaccessData(V_ARRAY(&varInput
));
2418 IPersistStream
*persistStream
;
2419 ISequentialStream
*stream
= NULL
;
2420 IXMLDOMDocument
*xmlDoc
;
2422 if(IUnknown_QueryInterface(V_UNKNOWN(&varInput
),
2423 &IID_IXMLDOMDocument
, (void**)&xmlDoc
) == S_OK
)
2427 IXMLDOMDocument_get_xml(xmlDoc
, &bstrData
);
2428 hr
= internal_parseBuffer(This
, (const char*)bstrData
,
2429 SysStringByteLen(bstrData
), vbInterface
);
2430 IXMLDOMDocument_Release(xmlDoc
);
2431 SysFreeString(bstrData
);
2435 if(IUnknown_QueryInterface(V_UNKNOWN(&varInput
),
2436 &IID_IPersistStream
, (void**)&persistStream
) == S_OK
)
2438 IStream
*stream_copy
;
2440 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &stream_copy
);
2443 IPersistStream_Release(persistStream
);
2447 hr
= IPersistStream_Save(persistStream
, stream_copy
, TRUE
);
2448 IPersistStream_Release(persistStream
);
2450 IStream_QueryInterface(stream_copy
, &IID_ISequentialStream
, (void**)&stream
);
2452 IStream_Release(stream_copy
);
2455 /* try base interface first */
2458 IUnknown_QueryInterface(V_UNKNOWN(&varInput
), &IID_ISequentialStream
, (void**)&stream
);
2460 /* this should never happen if IStream is implemented properly, but just in case */
2461 IUnknown_QueryInterface(V_UNKNOWN(&varInput
), &IID_IStream
, (void**)&stream
);
2466 hr
= internal_parseStream(This
, stream
, vbInterface
);
2467 ISequentialStream_Release(stream
);
2471 WARN("IUnknown* input doesn't support any of expected interfaces\n");
2478 WARN("vt %d not implemented\n", V_VT(&varInput
));
2485 static HRESULT
internal_vbonDataAvailable(void *obj
, char *ptr
, DWORD len
)
2487 saxreader
*This
= obj
;
2489 return internal_parseBuffer(This
, ptr
, len
, TRUE
);
2492 static HRESULT
internal_onDataAvailable(void *obj
, char *ptr
, DWORD len
)
2494 saxreader
*This
= obj
;
2496 return internal_parseBuffer(This
, ptr
, len
, FALSE
);
2499 static HRESULT
internal_parseURL(
2508 TRACE("(%p)->(%s)\n", This
, debugstr_w(url
));
2510 hr
= create_moniker_from_url(url
, &mon
);
2514 if(vbInterface
) hr
= bind_url(mon
, internal_vbonDataAvailable
, This
, &bsc
);
2515 else hr
= bind_url(mon
, internal_onDataAvailable
, This
, &bsc
);
2516 IMoniker_Release(mon
);
2521 return detach_bsc(bsc
);
2524 static HRESULT
internal_putProperty(
2530 TRACE("(%p)->(%s %s)\n", This
, debugstr_w(prop
), debugstr_variant(&value
));
2532 if(!memcmp(prop
, PropertyDeclHandlerW
, sizeof(PropertyDeclHandlerW
)))
2534 if(This
->isParsing
) return E_FAIL
;
2536 switch (V_VT(&value
))
2539 saxreader_put_handler(This
, SAXDeclHandler
, NULL
, vbInterface
);
2543 IUnknown
*handler
= NULL
;
2545 if (V_UNKNOWN(&value
))
2550 hr
= IUnknown_QueryInterface(V_UNKNOWN(&value
), &IID_IVBSAXDeclHandler
, (void**)&handler
);
2552 hr
= IUnknown_QueryInterface(V_UNKNOWN(&value
), &IID_ISAXDeclHandler
, (void**)&handler
);
2553 if (FAILED(hr
)) return hr
;
2556 saxreader_put_handler(This
, SAXDeclHandler
, handler
, vbInterface
);
2557 if (handler
) IUnknown_Release(handler
);
2561 return E_INVALIDARG
;
2567 if(!memcmp(prop
, PropertyLexicalHandlerW
, sizeof(PropertyLexicalHandlerW
)))
2569 if(This
->isParsing
) return E_FAIL
;
2571 switch (V_VT(&value
))
2574 saxreader_put_handler(This
, SAXLexicalHandler
, NULL
, vbInterface
);
2578 IUnknown
*handler
= NULL
;
2580 if (V_UNKNOWN(&value
))
2585 hr
= IUnknown_QueryInterface(V_UNKNOWN(&value
), &IID_IVBSAXLexicalHandler
, (void**)&handler
);
2587 hr
= IUnknown_QueryInterface(V_UNKNOWN(&value
), &IID_ISAXLexicalHandler
, (void**)&handler
);
2588 if (FAILED(hr
)) return hr
;
2591 saxreader_put_handler(This
, SAXLexicalHandler
, handler
, vbInterface
);
2592 if (handler
) IUnknown_Release(handler
);
2596 return E_INVALIDARG
;
2602 if(!memcmp(prop
, PropertyMaxXMLSizeW
, sizeof(PropertyMaxXMLSizeW
)))
2604 if (V_VT(&value
) == VT_I4
&& V_I4(&value
) == 0) return S_OK
;
2605 FIXME("(%p)->(%s): max-xml-size unsupported\n", This
, debugstr_variant(&value
));
2609 if(!memcmp(prop
, PropertyMaxElementDepthW
, sizeof(PropertyMaxElementDepthW
)))
2611 if (V_VT(&value
) == VT_I4
&& V_I4(&value
) == 0) return S_OK
;
2612 FIXME("(%p)->(%s): max-element-depth unsupported\n", This
, debugstr_variant(&value
));
2616 FIXME("(%p)->(%s:%s): unsupported property\n", This
, debugstr_w(prop
), debugstr_variant(&value
));
2618 if(!memcmp(prop
, PropertyCharsetW
, sizeof(PropertyCharsetW
)))
2621 if(!memcmp(prop
, PropertyDomNodeW
, sizeof(PropertyDomNodeW
)))
2624 if(!memcmp(prop
, PropertyInputSourceW
, sizeof(PropertyInputSourceW
)))
2627 if(!memcmp(prop
, PropertySchemaDeclHandlerW
, sizeof(PropertySchemaDeclHandlerW
)))
2630 if(!memcmp(prop
, PropertyXMLDeclEncodingW
, sizeof(PropertyXMLDeclEncodingW
)))
2633 if(!memcmp(prop
, PropertyXMLDeclStandaloneW
, sizeof(PropertyXMLDeclStandaloneW
)))
2636 if(!memcmp(prop
, PropertyXMLDeclVersionW
, sizeof(PropertyXMLDeclVersionW
)))
2639 return E_INVALIDARG
;
2642 static HRESULT
internal_getProperty(const saxreader
* This
, const WCHAR
*prop
, VARIANT
*value
, BOOL vb
)
2644 TRACE("(%p)->(%s)\n", This
, debugstr_w(prop
));
2646 if (!value
) return E_POINTER
;
2648 if (!memcmp(PropertyLexicalHandlerW
, prop
, sizeof(PropertyLexicalHandlerW
)))
2650 V_VT(value
) = VT_UNKNOWN
;
2651 saxreader_get_handler(This
, SAXLexicalHandler
, vb
, (void**)&V_UNKNOWN(value
));
2655 if (!memcmp(PropertyDeclHandlerW
, prop
, sizeof(PropertyDeclHandlerW
)))
2657 V_VT(value
) = VT_UNKNOWN
;
2658 saxreader_get_handler(This
, SAXDeclHandler
, vb
, (void**)&V_UNKNOWN(value
));
2662 if (!memcmp(PropertyXmlDeclVersionW
, prop
, sizeof(PropertyXmlDeclVersionW
)))
2664 V_VT(value
) = VT_BSTR
;
2665 V_BSTR(value
) = SysAllocString(This
->xmldecl_version
);
2669 FIXME("(%p)->(%s) unsupported property\n", This
, debugstr_w(prop
));
2674 /*** IVBSAXXMLReader interface ***/
2675 /*** IUnknown methods ***/
2676 static HRESULT WINAPI
saxxmlreader_QueryInterface(IVBSAXXMLReader
* iface
, REFIID riid
, void **ppvObject
)
2678 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2680 TRACE("%p %s %p\n", This
, debugstr_guid( riid
), ppvObject
);
2684 if ( IsEqualGUID( riid
, &IID_IUnknown
) ||
2685 IsEqualGUID( riid
, &IID_IDispatch
) ||
2686 IsEqualGUID( riid
, &IID_IVBSAXXMLReader
))
2690 else if( IsEqualGUID( riid
, &IID_ISAXXMLReader
))
2692 *ppvObject
= &This
->ISAXXMLReader_iface
;
2694 else if (dispex_query_interface(&This
->dispex
, riid
, ppvObject
))
2696 return *ppvObject
? S_OK
: E_NOINTERFACE
;
2700 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
2701 return E_NOINTERFACE
;
2704 IVBSAXXMLReader_AddRef( iface
);
2709 static ULONG WINAPI
saxxmlreader_AddRef(IVBSAXXMLReader
* iface
)
2711 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2712 TRACE("%p\n", This
);
2713 return InterlockedIncrement( &This
->ref
);
2716 static ULONG WINAPI
saxxmlreader_Release(
2717 IVBSAXXMLReader
* iface
)
2719 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2722 TRACE("%p\n", This
);
2724 ref
= InterlockedDecrement( &This
->ref
);
2729 for (i
= 0; i
< SAXHandler_Last
; i
++)
2731 struct saxanyhandler_iface
*iface
= &This
->saxhandlers
[i
].u
.anyhandler
;
2734 IUnknown_Release(iface
->handler
);
2736 if (iface
->vbhandler
)
2737 IUnknown_Release(iface
->vbhandler
);
2740 SysFreeString(This
->xmldecl_version
);
2741 free_bstr_pool(&This
->pool
);
2743 release_dispex(&This
->dispex
);
2750 static HRESULT WINAPI
saxxmlreader_GetTypeInfoCount( IVBSAXXMLReader
*iface
, UINT
* pctinfo
)
2752 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2753 return IDispatchEx_GetTypeInfoCount(&This
->dispex
.IDispatchEx_iface
, pctinfo
);
2756 static HRESULT WINAPI
saxxmlreader_GetTypeInfo(
2757 IVBSAXXMLReader
*iface
,
2758 UINT iTInfo
, LCID lcid
, ITypeInfo
** ppTInfo
)
2760 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2761 return IDispatchEx_GetTypeInfo(&This
->dispex
.IDispatchEx_iface
,
2762 iTInfo
, lcid
, ppTInfo
);
2765 static HRESULT WINAPI
saxxmlreader_GetIDsOfNames(
2766 IVBSAXXMLReader
*iface
,
2768 LPOLESTR
* rgszNames
,
2773 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2774 return IDispatchEx_GetIDsOfNames(&This
->dispex
.IDispatchEx_iface
,
2775 riid
, rgszNames
, cNames
, lcid
, rgDispId
);
2778 static HRESULT WINAPI
saxxmlreader_Invoke(
2779 IVBSAXXMLReader
*iface
,
2780 DISPID dispIdMember
,
2784 DISPPARAMS
* pDispParams
,
2785 VARIANT
* pVarResult
,
2786 EXCEPINFO
* pExcepInfo
,
2789 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2790 return IDispatchEx_Invoke(&This
->dispex
.IDispatchEx_iface
,
2791 dispIdMember
, riid
, lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
2794 /*** IVBSAXXMLReader methods ***/
2795 static HRESULT WINAPI
saxxmlreader_getFeature(
2796 IVBSAXXMLReader
* iface
,
2797 const WCHAR
*feature_name
,
2798 VARIANT_BOOL
*value
)
2800 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2801 saxreader_feature feature
;
2803 TRACE("(%p)->(%s %p)\n", This
, debugstr_w(feature_name
), value
);
2805 feature
= get_saxreader_feature(feature_name
);
2806 if (feature
== Namespaces
|| feature
== NamespacePrefixes
)
2807 return get_feature_value(This
, feature
, value
);
2809 FIXME("(%p)->(%s %p) stub\n", This
, debugstr_w(feature_name
), value
);
2813 static HRESULT WINAPI
saxxmlreader_putFeature(
2814 IVBSAXXMLReader
* iface
,
2815 const WCHAR
*feature_name
,
2818 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2819 saxreader_feature feature
;
2821 TRACE("(%p)->(%s %x)\n", This
, debugstr_w(feature_name
), value
);
2823 feature
= get_saxreader_feature(feature_name
);
2825 /* accepted cases */
2826 if ((feature
== ExternalGeneralEntities
&& value
== VARIANT_FALSE
) ||
2827 (feature
== ExternalParameterEntities
&& value
== VARIANT_FALSE
) ||
2828 feature
== Namespaces
||
2829 feature
== NamespacePrefixes
)
2831 return set_feature_value(This
, feature
, value
);
2834 if (feature
== LexicalHandlerParEntities
|| feature
== ProhibitDTD
)
2836 FIXME("(%p)->(%s %x) stub\n", This
, debugstr_w(feature_name
), value
);
2837 return set_feature_value(This
, feature
, value
);
2840 FIXME("(%p)->(%s %x) stub\n", This
, debugstr_w(feature_name
), value
);
2844 static HRESULT WINAPI
saxxmlreader_getProperty(
2845 IVBSAXXMLReader
* iface
,
2849 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2850 return internal_getProperty(This
, prop
, value
, TRUE
);
2853 static HRESULT WINAPI
saxxmlreader_putProperty(
2854 IVBSAXXMLReader
* iface
,
2858 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2859 return internal_putProperty(This
, pProp
, value
, TRUE
);
2862 static HRESULT WINAPI
saxxmlreader_get_entityResolver(
2863 IVBSAXXMLReader
* iface
,
2864 IVBSAXEntityResolver
**resolver
)
2866 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2867 return saxreader_get_handler(This
, SAXEntityResolver
, TRUE
, (void**)resolver
);
2870 static HRESULT WINAPI
saxxmlreader_put_entityResolver(
2871 IVBSAXXMLReader
* iface
,
2872 IVBSAXEntityResolver
*resolver
)
2874 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2875 return saxreader_put_handler(This
, SAXEntityResolver
, resolver
, TRUE
);
2878 static HRESULT WINAPI
saxxmlreader_get_contentHandler(
2879 IVBSAXXMLReader
* iface
,
2880 IVBSAXContentHandler
**handler
)
2882 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2883 return saxreader_get_handler(This
, SAXContentHandler
, TRUE
, (void**)handler
);
2886 static HRESULT WINAPI
saxxmlreader_put_contentHandler(
2887 IVBSAXXMLReader
* iface
,
2888 IVBSAXContentHandler
*handler
)
2890 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2891 return saxreader_put_handler(This
, SAXContentHandler
, handler
, TRUE
);
2894 static HRESULT WINAPI
saxxmlreader_get_dtdHandler(
2895 IVBSAXXMLReader
* iface
,
2896 IVBSAXDTDHandler
**handler
)
2898 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2899 return saxreader_get_handler(This
, SAXDTDHandler
, TRUE
, (void**)handler
);
2902 static HRESULT WINAPI
saxxmlreader_put_dtdHandler(
2903 IVBSAXXMLReader
* iface
,
2904 IVBSAXDTDHandler
*handler
)
2906 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2907 return saxreader_put_handler(This
, SAXDTDHandler
, handler
, TRUE
);
2910 static HRESULT WINAPI
saxxmlreader_get_errorHandler(
2911 IVBSAXXMLReader
* iface
,
2912 IVBSAXErrorHandler
**handler
)
2914 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2915 return saxreader_get_handler(This
, SAXErrorHandler
, TRUE
, (void**)handler
);
2918 static HRESULT WINAPI
saxxmlreader_put_errorHandler(
2919 IVBSAXXMLReader
* iface
,
2920 IVBSAXErrorHandler
*handler
)
2922 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2923 return saxreader_put_handler(This
, SAXErrorHandler
, handler
, TRUE
);
2926 static HRESULT WINAPI
saxxmlreader_get_baseURL(
2927 IVBSAXXMLReader
* iface
,
2928 const WCHAR
**pBaseUrl
)
2930 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2932 FIXME("(%p)->(%p) stub\n", This
, pBaseUrl
);
2936 static HRESULT WINAPI
saxxmlreader_put_baseURL(
2937 IVBSAXXMLReader
* iface
,
2938 const WCHAR
*pBaseUrl
)
2940 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2942 FIXME("(%p)->(%s) stub\n", This
, debugstr_w(pBaseUrl
));
2946 static HRESULT WINAPI
saxxmlreader_get_secureBaseURL(
2947 IVBSAXXMLReader
* iface
,
2948 const WCHAR
**pSecureBaseUrl
)
2950 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2952 FIXME("(%p)->(%p) stub\n", This
, pSecureBaseUrl
);
2957 static HRESULT WINAPI
saxxmlreader_put_secureBaseURL(
2958 IVBSAXXMLReader
* iface
,
2959 const WCHAR
*secureBaseUrl
)
2961 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2963 FIXME("(%p)->(%s) stub\n", This
, debugstr_w(secureBaseUrl
));
2967 static HRESULT WINAPI
saxxmlreader_parse(
2968 IVBSAXXMLReader
* iface
,
2971 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2972 return internal_parse(This
, varInput
, TRUE
);
2975 static HRESULT WINAPI
saxxmlreader_parseURL(
2976 IVBSAXXMLReader
* iface
,
2979 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2980 return internal_parseURL(This
, url
, TRUE
);
2983 static const struct IVBSAXXMLReaderVtbl VBSAXXMLReaderVtbl
=
2985 saxxmlreader_QueryInterface
,
2986 saxxmlreader_AddRef
,
2987 saxxmlreader_Release
,
2988 saxxmlreader_GetTypeInfoCount
,
2989 saxxmlreader_GetTypeInfo
,
2990 saxxmlreader_GetIDsOfNames
,
2991 saxxmlreader_Invoke
,
2992 saxxmlreader_getFeature
,
2993 saxxmlreader_putFeature
,
2994 saxxmlreader_getProperty
,
2995 saxxmlreader_putProperty
,
2996 saxxmlreader_get_entityResolver
,
2997 saxxmlreader_put_entityResolver
,
2998 saxxmlreader_get_contentHandler
,
2999 saxxmlreader_put_contentHandler
,
3000 saxxmlreader_get_dtdHandler
,
3001 saxxmlreader_put_dtdHandler
,
3002 saxxmlreader_get_errorHandler
,
3003 saxxmlreader_put_errorHandler
,
3004 saxxmlreader_get_baseURL
,
3005 saxxmlreader_put_baseURL
,
3006 saxxmlreader_get_secureBaseURL
,
3007 saxxmlreader_put_secureBaseURL
,
3009 saxxmlreader_parseURL
3012 /*** ISAXXMLReader interface ***/
3013 /*** IUnknown methods ***/
3014 static HRESULT WINAPI
isaxxmlreader_QueryInterface(ISAXXMLReader
* iface
, REFIID riid
, void **ppvObject
)
3016 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3017 return saxxmlreader_QueryInterface(&This
->IVBSAXXMLReader_iface
, riid
, ppvObject
);
3020 static ULONG WINAPI
isaxxmlreader_AddRef(ISAXXMLReader
* iface
)
3022 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3023 return saxxmlreader_AddRef(&This
->IVBSAXXMLReader_iface
);
3026 static ULONG WINAPI
isaxxmlreader_Release(ISAXXMLReader
* iface
)
3028 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3029 return saxxmlreader_Release(&This
->IVBSAXXMLReader_iface
);
3032 /*** ISAXXMLReader methods ***/
3033 static HRESULT WINAPI
isaxxmlreader_getFeature(
3034 ISAXXMLReader
* iface
,
3035 const WCHAR
*pFeature
,
3036 VARIANT_BOOL
*pValue
)
3038 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3039 return IVBSAXXMLReader_getFeature(&This
->IVBSAXXMLReader_iface
, pFeature
, pValue
);
3042 static HRESULT WINAPI
isaxxmlreader_putFeature(
3043 ISAXXMLReader
* iface
,
3044 const WCHAR
*pFeature
,
3045 VARIANT_BOOL vfValue
)
3047 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3048 return IVBSAXXMLReader_putFeature(&This
->IVBSAXXMLReader_iface
, pFeature
, vfValue
);
3051 static HRESULT WINAPI
isaxxmlreader_getProperty(
3052 ISAXXMLReader
* iface
,
3056 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3057 return internal_getProperty(This
, prop
, value
, FALSE
);
3060 static HRESULT WINAPI
isaxxmlreader_putProperty(
3061 ISAXXMLReader
* iface
,
3065 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3066 return internal_putProperty(This
, pProp
, value
, FALSE
);
3069 static HRESULT WINAPI
isaxxmlreader_getEntityResolver(
3070 ISAXXMLReader
* iface
,
3071 ISAXEntityResolver
**resolver
)
3073 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3074 return saxreader_get_handler(This
, SAXEntityResolver
, FALSE
, (void**)resolver
);
3077 static HRESULT WINAPI
isaxxmlreader_putEntityResolver(
3078 ISAXXMLReader
* iface
,
3079 ISAXEntityResolver
*resolver
)
3081 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3082 return saxreader_put_handler(This
, SAXEntityResolver
, resolver
, FALSE
);
3085 static HRESULT WINAPI
isaxxmlreader_getContentHandler(
3086 ISAXXMLReader
* iface
,
3087 ISAXContentHandler
**handler
)
3089 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3090 return saxreader_get_handler(This
, SAXContentHandler
, FALSE
, (void**)handler
);
3093 static HRESULT WINAPI
isaxxmlreader_putContentHandler(
3094 ISAXXMLReader
* iface
,
3095 ISAXContentHandler
*handler
)
3097 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3098 return saxreader_put_handler(This
, SAXContentHandler
, handler
, FALSE
);
3101 static HRESULT WINAPI
isaxxmlreader_getDTDHandler(
3102 ISAXXMLReader
* iface
,
3103 ISAXDTDHandler
**handler
)
3105 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3106 return saxreader_get_handler(This
, SAXDTDHandler
, FALSE
, (void**)handler
);
3109 static HRESULT WINAPI
isaxxmlreader_putDTDHandler(
3110 ISAXXMLReader
* iface
,
3111 ISAXDTDHandler
*handler
)
3113 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3114 return saxreader_put_handler(This
, SAXDTDHandler
, handler
, FALSE
);
3117 static HRESULT WINAPI
isaxxmlreader_getErrorHandler(
3118 ISAXXMLReader
* iface
,
3119 ISAXErrorHandler
**handler
)
3121 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3122 return saxreader_get_handler(This
, SAXErrorHandler
, FALSE
, (void**)handler
);
3125 static HRESULT WINAPI
isaxxmlreader_putErrorHandler(ISAXXMLReader
* iface
, ISAXErrorHandler
*handler
)
3127 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3128 return saxreader_put_handler(This
, SAXErrorHandler
, handler
, FALSE
);
3131 static HRESULT WINAPI
isaxxmlreader_getBaseURL(
3132 ISAXXMLReader
* iface
,
3133 const WCHAR
**pBaseUrl
)
3135 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3136 return IVBSAXXMLReader_get_baseURL(&This
->IVBSAXXMLReader_iface
, pBaseUrl
);
3139 static HRESULT WINAPI
isaxxmlreader_putBaseURL(
3140 ISAXXMLReader
* iface
,
3141 const WCHAR
*pBaseUrl
)
3143 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3144 return IVBSAXXMLReader_put_baseURL(&This
->IVBSAXXMLReader_iface
, pBaseUrl
);
3147 static HRESULT WINAPI
isaxxmlreader_getSecureBaseURL(
3148 ISAXXMLReader
* iface
,
3149 const WCHAR
**pSecureBaseUrl
)
3151 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3152 return IVBSAXXMLReader_get_secureBaseURL(&This
->IVBSAXXMLReader_iface
, pSecureBaseUrl
);
3155 static HRESULT WINAPI
isaxxmlreader_putSecureBaseURL(
3156 ISAXXMLReader
* iface
,
3157 const WCHAR
*secureBaseUrl
)
3159 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3160 return IVBSAXXMLReader_put_secureBaseURL(&This
->IVBSAXXMLReader_iface
, secureBaseUrl
);
3163 static HRESULT WINAPI
isaxxmlreader_parse(
3164 ISAXXMLReader
* iface
,
3167 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3168 return internal_parse(This
, varInput
, FALSE
);
3171 static HRESULT WINAPI
isaxxmlreader_parseURL(
3172 ISAXXMLReader
* iface
,
3175 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3176 return internal_parseURL(This
, url
, FALSE
);
3179 static const struct ISAXXMLReaderVtbl SAXXMLReaderVtbl
=
3181 isaxxmlreader_QueryInterface
,
3182 isaxxmlreader_AddRef
,
3183 isaxxmlreader_Release
,
3184 isaxxmlreader_getFeature
,
3185 isaxxmlreader_putFeature
,
3186 isaxxmlreader_getProperty
,
3187 isaxxmlreader_putProperty
,
3188 isaxxmlreader_getEntityResolver
,
3189 isaxxmlreader_putEntityResolver
,
3190 isaxxmlreader_getContentHandler
,
3191 isaxxmlreader_putContentHandler
,
3192 isaxxmlreader_getDTDHandler
,
3193 isaxxmlreader_putDTDHandler
,
3194 isaxxmlreader_getErrorHandler
,
3195 isaxxmlreader_putErrorHandler
,
3196 isaxxmlreader_getBaseURL
,
3197 isaxxmlreader_putBaseURL
,
3198 isaxxmlreader_getSecureBaseURL
,
3199 isaxxmlreader_putSecureBaseURL
,
3200 isaxxmlreader_parse
,
3201 isaxxmlreader_parseURL
3204 static const tid_t saxreader_iface_tids
[] = {
3205 IVBSAXXMLReader_tid
,
3208 static dispex_static_data_t saxreader_dispex
= {
3210 IVBSAXXMLReader_tid
,
3212 saxreader_iface_tids
3215 HRESULT
SAXXMLReader_create(MSXML_VERSION version
, IUnknown
*outer
, LPVOID
*ppObj
)
3219 TRACE("(%p, %p)\n", outer
, ppObj
);
3221 reader
= heap_alloc( sizeof (*reader
) );
3223 return E_OUTOFMEMORY
;
3225 reader
->IVBSAXXMLReader_iface
.lpVtbl
= &VBSAXXMLReaderVtbl
;
3226 reader
->ISAXXMLReader_iface
.lpVtbl
= &SAXXMLReaderVtbl
;
3228 memset(reader
->saxhandlers
, 0, sizeof(reader
->saxhandlers
));
3229 reader
->isParsing
= FALSE
;
3230 reader
->xmldecl_version
= NULL
;
3231 reader
->pool
.pool
= NULL
;
3232 reader
->pool
.index
= 0;
3233 reader
->pool
.len
= 0;
3234 reader
->features
= Namespaces
| NamespacePrefixes
;
3235 reader
->version
= version
;
3237 init_dispex(&reader
->dispex
, (IUnknown
*)&reader
->IVBSAXXMLReader_iface
, &saxreader_dispex
);
3239 memset(&reader
->sax
, 0, sizeof(xmlSAXHandler
));
3240 reader
->sax
.initialized
= XML_SAX2_MAGIC
;
3241 reader
->sax
.startDocument
= libxmlStartDocument
;
3242 reader
->sax
.endDocument
= libxmlEndDocument
;
3243 reader
->sax
.startElementNs
= libxmlStartElementNS
;
3244 reader
->sax
.endElementNs
= libxmlEndElementNS
;
3245 reader
->sax
.characters
= libxmlCharacters
;
3246 reader
->sax
.setDocumentLocator
= libxmlSetDocumentLocator
;
3247 reader
->sax
.comment
= libxmlComment
;
3248 reader
->sax
.error
= libxmlFatalError
;
3249 reader
->sax
.fatalError
= libxmlFatalError
;
3250 reader
->sax
.cdataBlock
= libxmlCDataBlock
;
3251 reader
->sax
.resolveEntity
= libxmlresolveentity
;
3253 *ppObj
= &reader
->IVBSAXXMLReader_iface
;
3255 TRACE("returning iface %p\n", *ppObj
);
3262 HRESULT
SAXXMLReader_create(MSXML_VERSION version
, IUnknown
*pUnkOuter
, LPVOID
*ppObj
)
3264 MESSAGE("This program tried to use a SAX XML Reader object, but\n"
3265 "libxml2 support was not present at compile time.\n");