2 * MXWriter implementation
4 * Copyright 2011-2012 Nikolay Sivov for CodeWeavers
5 * Copyright 2011 Thomas Mullaly
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
22 #define WIN32_NO_STATUS
30 # include <libxml/parser.h>
39 #include <wine/debug.h>
41 #include "msxml_private.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(msxml
);
45 static const WCHAR emptyW
[] = {0};
46 static const WCHAR spaceW
[] = {' '};
47 static const WCHAR quotW
[] = {'\"'};
48 static const WCHAR closetagW
[] = {'>','\r','\n'};
50 /* should be ordered as encoding names are sorted */
53 XmlEncoding_ISO_8859_1
= 0,
54 XmlEncoding_ISO_8859_13
,
55 XmlEncoding_ISO_8859_15
,
56 XmlEncoding_ISO_8859_2
,
57 XmlEncoding_ISO_8859_3
,
58 XmlEncoding_ISO_8859_4
,
59 XmlEncoding_ISO_8859_5
,
60 XmlEncoding_ISO_8859_7
,
61 XmlEncoding_ISO_8859_9
,
67 struct xml_encoding_data
69 const WCHAR
*encoding
;
74 static const WCHAR iso_8859_1W
[] = {'i','s','o','-','8','8','5','9','-','1',0};
75 static const WCHAR iso_8859_2W
[] = {'i','s','o','-','8','8','5','9','-','2',0};
76 static const WCHAR iso_8859_3W
[] = {'i','s','o','-','8','8','5','9','-','3',0};
77 static const WCHAR iso_8859_4W
[] = {'i','s','o','-','8','8','5','9','-','4',0};
78 static const WCHAR iso_8859_5W
[] = {'i','s','o','-','8','8','5','9','-','5',0};
79 static const WCHAR iso_8859_7W
[] = {'i','s','o','-','8','8','5','9','-','7',0};
80 static const WCHAR iso_8859_9W
[] = {'i','s','o','-','8','8','5','9','-','9',0};
81 static const WCHAR iso_8859_13W
[] = {'i','s','o','-','8','8','5','9','-','1','3',0};
82 static const WCHAR iso_8859_15W
[] = {'i','s','o','-','8','8','5','9','-','1','5',0};
83 static const WCHAR utf16W
[] = {'U','T','F','-','1','6',0};
84 static const WCHAR utf8W
[] = {'U','T','F','-','8',0};
86 static const struct xml_encoding_data xml_encoding_map
[] = {
87 { iso_8859_1W
, XmlEncoding_ISO_8859_1
, 28591 },
88 { iso_8859_13W
, XmlEncoding_ISO_8859_13
, 28603 },
89 { iso_8859_15W
, XmlEncoding_ISO_8859_15
, 28605 },
90 { iso_8859_2W
, XmlEncoding_ISO_8859_2
, 28592 },
91 { iso_8859_3W
, XmlEncoding_ISO_8859_3
, 28593 },
92 { iso_8859_4W
, XmlEncoding_ISO_8859_4
, 28594 },
93 { iso_8859_5W
, XmlEncoding_ISO_8859_5
, 28595 },
94 { iso_8859_7W
, XmlEncoding_ISO_8859_7
, 28597 },
95 { iso_8859_9W
, XmlEncoding_ISO_8859_9
, 28599 },
96 { utf16W
, XmlEncoding_UTF16
, ~0 },
97 { utf8W
, XmlEncoding_UTF8
, CP_UTF8
}
102 OutputBuffer_Native
= 0x001,
103 OutputBuffer_Encoded
= 0x010,
104 OutputBuffer_Both
= 0x100
110 MXWriter_DisableEscaping
,
112 MXWriter_OmitXmlDecl
,
126 unsigned int allocated
;
127 unsigned int written
;
132 encoded_buffer utf16
;
133 encoded_buffer encoded
;
140 IMXWriter IMXWriter_iface
;
141 ISAXContentHandler ISAXContentHandler_iface
;
142 ISAXLexicalHandler ISAXLexicalHandler_iface
;
143 ISAXDeclHandler ISAXDeclHandler_iface
;
146 MSXML_VERSION class_version
;
148 VARIANT_BOOL props
[MXWriter_LastProp
];
154 BSTR encoding
; /* exact property value */
155 xml_encoding xml_enc
;
157 /* contains a pending (or not closed yet) element name or NULL if
158 we don't have to close */
164 output_buffer
*buffer
;
179 IMXAttributes IMXAttributes_iface
;
180 ISAXAttributes ISAXAttributes_iface
;
181 IVBSAXAttributes IVBSAXAttributes_iface
;
184 MSXML_VERSION class_version
;
191 static inline mxattributes
*impl_from_IMXAttributes( IMXAttributes
*iface
)
193 return CONTAINING_RECORD(iface
, mxattributes
, IMXAttributes_iface
);
196 static inline mxattributes
*impl_from_ISAXAttributes( ISAXAttributes
*iface
)
198 return CONTAINING_RECORD(iface
, mxattributes
, ISAXAttributes_iface
);
201 static inline mxattributes
*impl_from_IVBSAXAttributes( IVBSAXAttributes
*iface
)
203 return CONTAINING_RECORD(iface
, mxattributes
, IVBSAXAttributes_iface
);
206 static HRESULT
mxattributes_grow(mxattributes
*This
)
208 if (This
->length
< This
->allocated
) return S_OK
;
210 This
->allocated
*= 2;
211 This
->attr
= heap_realloc(This
->attr
, This
->allocated
*sizeof(mxattribute
));
213 return This
->attr
? S_OK
: E_OUTOFMEMORY
;
216 static xml_encoding
parse_encoding_name(const WCHAR
*encoding
)
221 max
= sizeof(xml_encoding_map
)/sizeof(struct xml_encoding_data
) - 1;
227 c
= strcmpiW(xml_encoding_map
[n
].encoding
, encoding
);
229 return xml_encoding_map
[n
].enc
;
237 return XmlEncoding_Unknown
;
240 static HRESULT
init_encoded_buffer(encoded_buffer
*buffer
)
242 const int initial_len
= 0x2000;
243 buffer
->data
= heap_alloc(initial_len
);
244 if (!buffer
->data
) return E_OUTOFMEMORY
;
246 memset(buffer
->data
, 0, 4);
247 buffer
->allocated
= initial_len
;
253 static void free_encoded_buffer(encoded_buffer
*buffer
)
255 heap_free(buffer
->data
);
258 static HRESULT
get_code_page(xml_encoding encoding
, UINT
*cp
)
260 const struct xml_encoding_data
*data
;
262 if (encoding
== XmlEncoding_Unknown
)
264 FIXME("unsupported encoding %d\n", encoding
);
268 data
= &xml_encoding_map
[encoding
];
274 static HRESULT
alloc_output_buffer(xml_encoding encoding
, output_buffer
**buffer
)
279 ret
= heap_alloc(sizeof(*ret
));
280 if (!ret
) return E_OUTOFMEMORY
;
282 hr
= get_code_page(encoding
, &ret
->code_page
);
288 hr
= init_encoded_buffer(&ret
->utf16
);
294 /* currently we always create a default output buffer that is UTF-16 only,
295 but it's possible to allocate with specific encoding too */
296 if (encoding
!= XmlEncoding_UTF16
) {
297 hr
= init_encoded_buffer(&ret
->encoded
);
299 free_encoded_buffer(&ret
->utf16
);
305 memset(&ret
->encoded
, 0, sizeof(ret
->encoded
));
312 static void free_output_buffer(output_buffer
*buffer
)
314 free_encoded_buffer(&buffer
->encoded
);
315 free_encoded_buffer(&buffer
->utf16
);
319 static void grow_buffer(encoded_buffer
*buffer
, int length
)
321 /* grow if needed, plus 4 bytes to be sure null terminator will fit in */
322 if (buffer
->allocated
< buffer
->written
+ length
+ 4)
324 int grown_size
= max(2*buffer
->allocated
, buffer
->allocated
+ length
);
325 buffer
->data
= heap_realloc(buffer
->data
, grown_size
);
326 buffer
->allocated
= grown_size
;
330 static HRESULT
write_output_buffer_mode(output_buffer
*buffer
, output_mode mode
, const WCHAR
*data
, int len
)
335 if (mode
& (OutputBuffer_Encoded
| OutputBuffer_Both
)) {
336 if (buffer
->code_page
!= ~0)
338 length
= WideCharToMultiByte(buffer
->code_page
, 0, data
, len
, NULL
, 0, NULL
, NULL
);
339 grow_buffer(&buffer
->encoded
, length
);
340 ptr
= buffer
->encoded
.data
+ buffer
->encoded
.written
;
341 length
= WideCharToMultiByte(buffer
->code_page
, 0, data
, len
, ptr
, length
, NULL
, NULL
);
342 buffer
->encoded
.written
+= len
== -1 ? length
-1 : length
;
346 if (mode
& (OutputBuffer_Native
| OutputBuffer_Both
)) {
347 /* WCHAR data just copied */
348 length
= len
== -1 ? strlenW(data
) : len
;
351 length
*= sizeof(WCHAR
);
353 grow_buffer(&buffer
->utf16
, length
);
354 ptr
= buffer
->utf16
.data
+ buffer
->utf16
.written
;
356 memcpy(ptr
, data
, length
);
357 buffer
->utf16
.written
+= length
;
359 /* null termination */
360 memset(ptr
, 0, sizeof(WCHAR
));
367 static HRESULT
write_output_buffer(output_buffer
*buffer
, const WCHAR
*data
, int len
)
369 return write_output_buffer_mode(buffer
, OutputBuffer_Both
, data
, len
);
372 static HRESULT
write_output_buffer_quoted(output_buffer
*buffer
, const WCHAR
*data
, int len
)
374 write_output_buffer(buffer
, quotW
, 1);
375 write_output_buffer(buffer
, data
, len
);
376 write_output_buffer(buffer
, quotW
, 1);
381 /* frees buffer data, reallocates with a default lengths */
382 static void close_output_buffer(mxwriter
*This
)
384 heap_free(This
->buffer
->utf16
.data
);
385 heap_free(This
->buffer
->encoded
.data
);
386 init_encoded_buffer(&This
->buffer
->utf16
);
387 init_encoded_buffer(&This
->buffer
->encoded
);
388 get_code_page(This
->xml_enc
, &This
->buffer
->code_page
);
391 /* escapes special characters like:
397 static WCHAR
*get_escaped_string(const WCHAR
*str
, escape_mode mode
, int *len
)
399 static const WCHAR ltW
[] = {'&','l','t',';'};
400 static const WCHAR ampW
[] = {'&','a','m','p',';'};
401 static const WCHAR equotW
[] = {'&','q','u','o','t',';'};
402 static const WCHAR gtW
[] = {'&','g','t',';'};
404 const int default_alloc
= 100;
405 const int grow_thresh
= 10;
406 int p
= *len
, conv_len
;
409 /* default buffer size to something if length is unknown */
410 conv_len
= *len
== -1 ? default_alloc
: max(2**len
, default_alloc
);
411 ptr
= ret
= heap_alloc(conv_len
*sizeof(WCHAR
));
415 if (ptr
- ret
> conv_len
- grow_thresh
)
417 int written
= ptr
- ret
;
419 ptr
= ret
= heap_realloc(ret
, conv_len
*sizeof(WCHAR
));
426 memcpy(ptr
, ltW
, sizeof(ltW
));
427 ptr
+= sizeof(ltW
)/sizeof(WCHAR
);
430 memcpy(ptr
, ampW
, sizeof(ampW
));
431 ptr
+= sizeof(ampW
)/sizeof(WCHAR
);
434 memcpy(ptr
, gtW
, sizeof(gtW
));
435 ptr
+= sizeof(gtW
)/sizeof(WCHAR
);
438 if (mode
== EscapeValue
)
440 memcpy(ptr
, equotW
, sizeof(equotW
));
441 ptr
+= sizeof(equotW
)/sizeof(WCHAR
);
444 /* fallthrough for text mode */
454 if (*len
!= -1) *len
= ptr
-ret
;
460 static void write_prolog_buffer(const mxwriter
*This
)
462 static const WCHAR versionW
[] = {'<','?','x','m','l',' ','v','e','r','s','i','o','n','='};
463 static const WCHAR encodingW
[] = {' ','e','n','c','o','d','i','n','g','=','\"'};
464 static const WCHAR standaloneW
[] = {' ','s','t','a','n','d','a','l','o','n','e','=','\"'};
465 static const WCHAR yesW
[] = {'y','e','s','\"','?','>'};
466 static const WCHAR noW
[] = {'n','o','\"','?','>'};
467 static const WCHAR crlfW
[] = {'\r','\n'};
470 write_output_buffer(This
->buffer
, versionW
, sizeof(versionW
)/sizeof(WCHAR
));
471 write_output_buffer_quoted(This
->buffer
, This
->version
, -1);
474 write_output_buffer(This
->buffer
, encodingW
, sizeof(encodingW
)/sizeof(WCHAR
));
476 /* always write UTF-16 to WCHAR buffer */
477 write_output_buffer_mode(This
->buffer
, OutputBuffer_Native
, utf16W
, sizeof(utf16W
)/sizeof(WCHAR
) - 1);
478 write_output_buffer_mode(This
->buffer
, OutputBuffer_Encoded
, This
->encoding
, -1);
479 write_output_buffer(This
->buffer
, quotW
, 1);
482 write_output_buffer(This
->buffer
, standaloneW
, sizeof(standaloneW
)/sizeof(WCHAR
));
483 if (This
->props
[MXWriter_Standalone
] == VARIANT_TRUE
)
484 write_output_buffer(This
->buffer
, yesW
, sizeof(yesW
)/sizeof(WCHAR
));
486 write_output_buffer(This
->buffer
, noW
, sizeof(noW
)/sizeof(WCHAR
));
488 write_output_buffer(This
->buffer
, crlfW
, sizeof(crlfW
)/sizeof(WCHAR
));
491 /* Attempts to the write data from the mxwriter's buffer to
492 * the destination stream (if there is one).
494 static HRESULT
write_data_to_stream(mxwriter
*This
)
496 encoded_buffer
*buffer
;
503 if (This
->xml_enc
!= XmlEncoding_UTF16
)
504 buffer
= &This
->buffer
->encoded
;
506 buffer
= &This
->buffer
->utf16
;
508 if (This
->dest_written
> buffer
->written
) {
509 ERR("Failed sanity check! Not sure what to do... (%d > %d)\n", This
->dest_written
, buffer
->written
);
511 } else if (This
->dest_written
== buffer
->written
&& This
->xml_enc
!= XmlEncoding_UTF8
)
512 /* Windows seems to make an empty write call when the encoding is UTF-8 and
513 * all the data has been written to the stream. It doesn't seem make this call
514 * for any other encodings.
518 /* Write the current content from the output buffer into 'dest'.
519 * TODO: Check what Windows does if the IStream doesn't write all of
520 * the data we give it at once.
522 hr
= IStream_Write(This
->dest
, buffer
->data
+This
->dest_written
,
523 buffer
->written
-This
->dest_written
, &written
);
525 WARN("Failed to write data to IStream (0x%08x)\n", hr
);
529 This
->dest_written
+= written
;
533 /* Newly added element start tag left unclosed cause for empty elements
534 we have to close it differently. */
535 static void close_element_starttag(const mxwriter
*This
)
537 static const WCHAR gtW
[] = {'>'};
538 if (!This
->element
) return;
539 write_output_buffer(This
->buffer
, gtW
, 1);
542 static void set_element_name(mxwriter
*This
, const WCHAR
*name
, int len
)
544 SysFreeString(This
->element
);
546 This
->element
= len
!= -1 ? SysAllocStringLen(name
, len
) : SysAllocString(name
);
548 This
->element
= NULL
;
551 static inline HRESULT
flush_output_buffer(mxwriter
*This
)
553 close_element_starttag(This
);
554 set_element_name(This
, NULL
, 0);
556 return write_data_to_stream(This
);
559 /* Resets the mxwriter's output buffer by closing it, then creating a new
560 * output buffer using the given encoding.
562 static inline void reset_output_buffer(mxwriter
*This
)
564 close_output_buffer(This
);
565 This
->dest_written
= 0;
568 static HRESULT
writer_set_property(mxwriter
*writer
, mxwriter_prop property
, VARIANT_BOOL value
)
570 writer
->props
[property
] = value
;
571 writer
->prop_changed
= TRUE
;
575 static HRESULT
writer_get_property(const mxwriter
*writer
, mxwriter_prop property
, VARIANT_BOOL
*value
)
577 if (!value
) return E_POINTER
;
578 *value
= writer
->props
[property
];
582 static inline mxwriter
*impl_from_IMXWriter(IMXWriter
*iface
)
584 return CONTAINING_RECORD(iface
, mxwriter
, IMXWriter_iface
);
587 static inline mxwriter
*impl_from_ISAXContentHandler(ISAXContentHandler
*iface
)
589 return CONTAINING_RECORD(iface
, mxwriter
, ISAXContentHandler_iface
);
592 static inline mxwriter
*impl_from_ISAXLexicalHandler(ISAXLexicalHandler
*iface
)
594 return CONTAINING_RECORD(iface
, mxwriter
, ISAXLexicalHandler_iface
);
597 static inline mxwriter
*impl_from_ISAXDeclHandler(ISAXDeclHandler
*iface
)
599 return CONTAINING_RECORD(iface
, mxwriter
, ISAXDeclHandler_iface
);
602 static HRESULT WINAPI
mxwriter_QueryInterface(IMXWriter
*iface
, REFIID riid
, void **obj
)
604 mxwriter
*This
= impl_from_IMXWriter( iface
);
606 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), obj
);
610 if ( IsEqualGUID( riid
, &IID_IMXWriter
) ||
611 IsEqualGUID( riid
, &IID_IDispatch
) ||
612 IsEqualGUID( riid
, &IID_IUnknown
) )
614 *obj
= &This
->IMXWriter_iface
;
616 else if ( IsEqualGUID( riid
, &IID_ISAXContentHandler
) )
618 *obj
= &This
->ISAXContentHandler_iface
;
620 else if ( IsEqualGUID( riid
, &IID_ISAXLexicalHandler
) )
622 *obj
= &This
->ISAXLexicalHandler_iface
;
624 else if ( IsEqualGUID( riid
, &IID_ISAXDeclHandler
) )
626 *obj
= &This
->ISAXDeclHandler_iface
;
628 else if (dispex_query_interface(&This
->dispex
, riid
, obj
))
630 return *obj
? S_OK
: E_NOINTERFACE
;
634 ERR("interface %s not implemented\n", debugstr_guid(riid
));
636 return E_NOINTERFACE
;
639 IMXWriter_AddRef(iface
);
643 static ULONG WINAPI
mxwriter_AddRef(IMXWriter
*iface
)
645 mxwriter
*This
= impl_from_IMXWriter( iface
);
646 LONG ref
= InterlockedIncrement(&This
->ref
);
648 TRACE("(%p)->(%d)\n", This
, ref
);
653 static ULONG WINAPI
mxwriter_Release(IMXWriter
*iface
)
655 mxwriter
*This
= impl_from_IMXWriter( iface
);
656 ULONG ref
= InterlockedDecrement(&This
->ref
);
658 TRACE("(%p)->(%d)\n", This
, ref
);
662 /* Windows flushes the buffer when the interface is destroyed. */
663 flush_output_buffer(This
);
664 free_output_buffer(This
->buffer
);
666 if (This
->dest
) IStream_Release(This
->dest
);
667 SysFreeString(This
->version
);
668 SysFreeString(This
->encoding
);
670 SysFreeString(This
->element
);
671 release_dispex(&This
->dispex
);
678 static HRESULT WINAPI
mxwriter_GetTypeInfoCount(IMXWriter
*iface
, UINT
* pctinfo
)
680 mxwriter
*This
= impl_from_IMXWriter( iface
);
681 return IDispatchEx_GetTypeInfoCount(&This
->dispex
.IDispatchEx_iface
, pctinfo
);
684 static HRESULT WINAPI
mxwriter_GetTypeInfo(
686 UINT iTInfo
, LCID lcid
,
687 ITypeInfo
** ppTInfo
)
689 mxwriter
*This
= impl_from_IMXWriter( iface
);
690 return IDispatchEx_GetTypeInfo(&This
->dispex
.IDispatchEx_iface
,
691 iTInfo
, lcid
, ppTInfo
);
694 static HRESULT WINAPI
mxwriter_GetIDsOfNames(
696 REFIID riid
, LPOLESTR
* rgszNames
,
697 UINT cNames
, LCID lcid
, DISPID
* rgDispId
)
699 mxwriter
*This
= impl_from_IMXWriter( iface
);
700 return IDispatchEx_GetIDsOfNames(&This
->dispex
.IDispatchEx_iface
,
701 riid
, rgszNames
, cNames
, lcid
, rgDispId
);
704 static HRESULT WINAPI
mxwriter_Invoke(
706 DISPID dispIdMember
, REFIID riid
, LCID lcid
,
707 WORD wFlags
, DISPPARAMS
* pDispParams
, VARIANT
* pVarResult
,
708 EXCEPINFO
* pExcepInfo
, UINT
* puArgErr
)
710 mxwriter
*This
= impl_from_IMXWriter( iface
);
711 return IDispatchEx_Invoke(&This
->dispex
.IDispatchEx_iface
,
712 dispIdMember
, riid
, lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
715 static HRESULT WINAPI
mxwriter_put_output(IMXWriter
*iface
, VARIANT dest
)
717 mxwriter
*This
= impl_from_IMXWriter( iface
);
720 TRACE("(%p)->(%s)\n", This
, debugstr_variant(&dest
));
722 hr
= flush_output_buffer(This
);
730 if (This
->dest
) IStream_Release(This
->dest
);
732 reset_output_buffer(This
);
739 hr
= IUnknown_QueryInterface(V_UNKNOWN(&dest
), &IID_IStream
, (void**)&stream
);
742 /* Recreate the output buffer to make sure it's using the correct encoding. */
743 reset_output_buffer(This
);
745 if (This
->dest
) IStream_Release(This
->dest
);
750 FIXME("unhandled interface type for VT_UNKNOWN destination\n");
754 FIXME("unhandled destination type %s\n", debugstr_variant(&dest
));
761 static HRESULT WINAPI
mxwriter_get_output(IMXWriter
*iface
, VARIANT
*dest
)
763 mxwriter
*This
= impl_from_IMXWriter( iface
);
765 TRACE("(%p)->(%p)\n", This
, dest
);
767 if (!dest
) return E_POINTER
;
771 HRESULT hr
= flush_output_buffer(This
);
775 V_VT(dest
) = VT_BSTR
;
776 V_BSTR(dest
) = SysAllocString((WCHAR
*)This
->buffer
->utf16
.data
);
781 /* we only support IStream output so far */
782 V_VT(dest
) = VT_UNKNOWN
;
783 V_UNKNOWN(dest
) = (IUnknown
*)This
->dest
;
784 IStream_AddRef(This
->dest
);
789 static HRESULT WINAPI
mxwriter_put_encoding(IMXWriter
*iface
, BSTR encoding
)
791 mxwriter
*This
= impl_from_IMXWriter( iface
);
795 TRACE("(%p)->(%s)\n", This
, debugstr_w(encoding
));
797 enc
= parse_encoding_name(encoding
);
798 if (enc
== XmlEncoding_Unknown
)
800 FIXME("unsupported encoding %s\n", debugstr_w(encoding
));
804 hr
= flush_output_buffer(This
);
808 SysReAllocString(&This
->encoding
, encoding
);
811 TRACE("got encoding %d\n", This
->xml_enc
);
812 reset_output_buffer(This
);
816 static HRESULT WINAPI
mxwriter_get_encoding(IMXWriter
*iface
, BSTR
*encoding
)
818 mxwriter
*This
= impl_from_IMXWriter( iface
);
820 TRACE("(%p)->(%p)\n", This
, encoding
);
822 if (!encoding
) return E_POINTER
;
824 *encoding
= SysAllocString(This
->encoding
);
825 if (!*encoding
) return E_OUTOFMEMORY
;
830 static HRESULT WINAPI
mxwriter_put_byteOrderMark(IMXWriter
*iface
, VARIANT_BOOL value
)
832 mxwriter
*This
= impl_from_IMXWriter( iface
);
834 TRACE("(%p)->(%d)\n", This
, value
);
835 return writer_set_property(This
, MXWriter_BOM
, value
);
838 static HRESULT WINAPI
mxwriter_get_byteOrderMark(IMXWriter
*iface
, VARIANT_BOOL
*value
)
840 mxwriter
*This
= impl_from_IMXWriter( iface
);
842 TRACE("(%p)->(%p)\n", This
, value
);
843 return writer_get_property(This
, MXWriter_BOM
, value
);
846 static HRESULT WINAPI
mxwriter_put_indent(IMXWriter
*iface
, VARIANT_BOOL value
)
848 mxwriter
*This
= impl_from_IMXWriter( iface
);
850 TRACE("(%p)->(%d)\n", This
, value
);
851 return writer_set_property(This
, MXWriter_Indent
, value
);
854 static HRESULT WINAPI
mxwriter_get_indent(IMXWriter
*iface
, VARIANT_BOOL
*value
)
856 mxwriter
*This
= impl_from_IMXWriter( iface
);
858 TRACE("(%p)->(%p)\n", This
, value
);
859 return writer_get_property(This
, MXWriter_Indent
, value
);
862 static HRESULT WINAPI
mxwriter_put_standalone(IMXWriter
*iface
, VARIANT_BOOL value
)
864 mxwriter
*This
= impl_from_IMXWriter( iface
);
866 TRACE("(%p)->(%d)\n", This
, value
);
867 return writer_set_property(This
, MXWriter_Standalone
, value
);
870 static HRESULT WINAPI
mxwriter_get_standalone(IMXWriter
*iface
, VARIANT_BOOL
*value
)
872 mxwriter
*This
= impl_from_IMXWriter( iface
);
874 TRACE("(%p)->(%p)\n", This
, value
);
875 return writer_get_property(This
, MXWriter_Standalone
, value
);
878 static HRESULT WINAPI
mxwriter_put_omitXMLDeclaration(IMXWriter
*iface
, VARIANT_BOOL value
)
880 mxwriter
*This
= impl_from_IMXWriter( iface
);
882 TRACE("(%p)->(%d)\n", This
, value
);
883 return writer_set_property(This
, MXWriter_OmitXmlDecl
, value
);
886 static HRESULT WINAPI
mxwriter_get_omitXMLDeclaration(IMXWriter
*iface
, VARIANT_BOOL
*value
)
888 mxwriter
*This
= impl_from_IMXWriter( iface
);
890 TRACE("(%p)->(%p)\n", This
, value
);
891 return writer_get_property(This
, MXWriter_OmitXmlDecl
, value
);
894 static HRESULT WINAPI
mxwriter_put_version(IMXWriter
*iface
, BSTR version
)
896 mxwriter
*This
= impl_from_IMXWriter( iface
);
898 TRACE("(%p)->(%s)\n", This
, debugstr_w(version
));
900 if (!version
) return E_INVALIDARG
;
902 SysFreeString(This
->version
);
903 This
->version
= SysAllocString(version
);
908 static HRESULT WINAPI
mxwriter_get_version(IMXWriter
*iface
, BSTR
*version
)
910 mxwriter
*This
= impl_from_IMXWriter( iface
);
912 TRACE("(%p)->(%p)\n", This
, version
);
914 if (!version
) return E_POINTER
;
916 return return_bstr(This
->version
, version
);
919 static HRESULT WINAPI
mxwriter_put_disableOutputEscaping(IMXWriter
*iface
, VARIANT_BOOL value
)
921 mxwriter
*This
= impl_from_IMXWriter( iface
);
923 TRACE("(%p)->(%d)\n", This
, value
);
924 return writer_set_property(This
, MXWriter_DisableEscaping
, value
);
927 static HRESULT WINAPI
mxwriter_get_disableOutputEscaping(IMXWriter
*iface
, VARIANT_BOOL
*value
)
929 mxwriter
*This
= impl_from_IMXWriter( iface
);
931 TRACE("(%p)->(%p)\n", This
, value
);
932 return writer_get_property(This
, MXWriter_DisableEscaping
, value
);
935 static HRESULT WINAPI
mxwriter_flush(IMXWriter
*iface
)
937 mxwriter
*This
= impl_from_IMXWriter( iface
);
938 TRACE("(%p)\n", This
);
939 return flush_output_buffer(This
);
942 static const struct IMXWriterVtbl MXWriterVtbl
=
944 mxwriter_QueryInterface
,
947 mxwriter_GetTypeInfoCount
,
948 mxwriter_GetTypeInfo
,
949 mxwriter_GetIDsOfNames
,
953 mxwriter_put_encoding
,
954 mxwriter_get_encoding
,
955 mxwriter_put_byteOrderMark
,
956 mxwriter_get_byteOrderMark
,
959 mxwriter_put_standalone
,
960 mxwriter_get_standalone
,
961 mxwriter_put_omitXMLDeclaration
,
962 mxwriter_get_omitXMLDeclaration
,
963 mxwriter_put_version
,
964 mxwriter_get_version
,
965 mxwriter_put_disableOutputEscaping
,
966 mxwriter_get_disableOutputEscaping
,
970 /*** ISAXContentHandler ***/
971 static HRESULT WINAPI
SAXContentHandler_QueryInterface(
972 ISAXContentHandler
*iface
,
976 mxwriter
*This
= impl_from_ISAXContentHandler( iface
);
977 return IMXWriter_QueryInterface(&This
->IMXWriter_iface
, riid
, obj
);
980 static ULONG WINAPI
SAXContentHandler_AddRef(ISAXContentHandler
*iface
)
982 mxwriter
*This
= impl_from_ISAXContentHandler( iface
);
983 return IMXWriter_AddRef(&This
->IMXWriter_iface
);
986 static ULONG WINAPI
SAXContentHandler_Release(ISAXContentHandler
*iface
)
988 mxwriter
*This
= impl_from_ISAXContentHandler( iface
);
989 return IMXWriter_Release(&This
->IMXWriter_iface
);
992 static HRESULT WINAPI
SAXContentHandler_putDocumentLocator(
993 ISAXContentHandler
*iface
,
994 ISAXLocator
*locator
)
996 mxwriter
*This
= impl_from_ISAXContentHandler( iface
);
997 FIXME("(%p)->(%p)\n", This
, locator
);
1001 static HRESULT WINAPI
SAXContentHandler_startDocument(ISAXContentHandler
*iface
)
1003 mxwriter
*This
= impl_from_ISAXContentHandler( iface
);
1005 TRACE("(%p)\n", This
);
1007 /* If properties have been changed since the last "endDocument" call
1008 * we need to reset the output buffer. If we don't the output buffer
1009 * could end up with multiple XML documents in it, plus this seems to
1010 * be how Windows works.
1012 if (This
->prop_changed
) {
1013 reset_output_buffer(This
);
1014 This
->prop_changed
= FALSE
;
1017 if (This
->props
[MXWriter_OmitXmlDecl
] == VARIANT_TRUE
) return S_OK
;
1019 write_prolog_buffer(This
);
1021 if (This
->dest
&& This
->xml_enc
== XmlEncoding_UTF16
) {
1022 static const char utf16BOM
[] = {0xff,0xfe};
1024 if (This
->props
[MXWriter_BOM
] == VARIANT_TRUE
)
1025 /* Windows passes a NULL pointer as the pcbWritten parameter and
1026 * ignores any error codes returned from this Write call.
1028 IStream_Write(This
->dest
, utf16BOM
, sizeof(utf16BOM
), NULL
);
1034 static HRESULT WINAPI
SAXContentHandler_endDocument(ISAXContentHandler
*iface
)
1036 mxwriter
*This
= impl_from_ISAXContentHandler( iface
);
1037 TRACE("(%p)\n", This
);
1038 This
->prop_changed
= FALSE
;
1039 return flush_output_buffer(This
);
1042 static HRESULT WINAPI
SAXContentHandler_startPrefixMapping(
1043 ISAXContentHandler
*iface
,
1044 const WCHAR
*prefix
,
1049 mxwriter
*This
= impl_from_ISAXContentHandler( iface
);
1050 FIXME("(%p)->(%s %s)\n", This
, debugstr_wn(prefix
, nprefix
), debugstr_wn(uri
, nuri
));
1054 static HRESULT WINAPI
SAXContentHandler_endPrefixMapping(
1055 ISAXContentHandler
*iface
,
1056 const WCHAR
*prefix
,
1059 mxwriter
*This
= impl_from_ISAXContentHandler( iface
);
1060 FIXME("(%p)->(%s)\n", This
, debugstr_wn(prefix
, nprefix
));
1064 static HRESULT WINAPI
SAXContentHandler_startElement(
1065 ISAXContentHandler
*iface
,
1066 const WCHAR
*namespaceUri
,
1068 const WCHAR
*local_name
,
1072 ISAXAttributes
*attr
)
1074 mxwriter
*This
= impl_from_ISAXContentHandler( iface
);
1075 static const WCHAR ltW
[] = {'<'};
1077 TRACE("(%p)->(%s %s %s %p)\n", This
, debugstr_wn(namespaceUri
, nnamespaceUri
),
1078 debugstr_wn(local_name
, nlocal_name
), debugstr_wn(QName
, nQName
), attr
);
1080 if (((!namespaceUri
|| !local_name
|| !QName
) && This
->class_version
!= MSXML6
) ||
1081 (nQName
== -1 && This
->class_version
== MSXML6
))
1082 return E_INVALIDARG
;
1084 close_element_starttag(This
);
1085 set_element_name(This
, QName
? QName
: emptyW
,
1086 QName
? nQName
: 0);
1088 write_output_buffer(This
->buffer
, ltW
, 1);
1089 write_output_buffer(This
->buffer
, QName
, nQName
);
1093 int length
, i
, escape
;
1096 hr
= ISAXAttributes_getLength(attr
, &length
);
1097 if (FAILED(hr
)) return hr
;
1099 escape
= This
->props
[MXWriter_DisableEscaping
] == VARIANT_FALSE
||
1100 (This
->class_version
== MSXML4
|| This
->class_version
== MSXML6
);
1102 for (i
= 0; i
< length
; i
++)
1104 static const WCHAR eqW
[] = {'='};
1108 hr
= ISAXAttributes_getQName(attr
, i
, &str
, &len
);
1109 if (FAILED(hr
)) return hr
;
1111 /* space separator in front of every attribute */
1112 write_output_buffer(This
->buffer
, spaceW
, 1);
1113 write_output_buffer(This
->buffer
, str
, len
);
1115 write_output_buffer(This
->buffer
, eqW
, 1);
1118 hr
= ISAXAttributes_getValue(attr
, i
, &str
, &len
);
1119 if (FAILED(hr
)) return hr
;
1123 WCHAR
*escaped
= get_escaped_string(str
, EscapeValue
, &len
);
1124 write_output_buffer_quoted(This
->buffer
, escaped
, len
);
1128 write_output_buffer_quoted(This
->buffer
, str
, len
);
1135 static HRESULT WINAPI
SAXContentHandler_endElement(
1136 ISAXContentHandler
*iface
,
1137 const WCHAR
*namespaceUri
,
1139 const WCHAR
* local_name
,
1144 mxwriter
*This
= impl_from_ISAXContentHandler( iface
);
1146 TRACE("(%p)->(%s:%d %s:%d %s:%d)\n", This
, debugstr_wn(namespaceUri
, nnamespaceUri
), nnamespaceUri
,
1147 debugstr_wn(local_name
, nlocal_name
), nlocal_name
, debugstr_wn(QName
, nQName
), nQName
);
1149 if (((!namespaceUri
|| !local_name
|| !QName
) && This
->class_version
!= MSXML6
) ||
1150 (nQName
== -1 && This
->class_version
== MSXML6
))
1151 return E_INVALIDARG
;
1155 static const WCHAR closeW
[] = {'/','>'};
1156 write_output_buffer(This
->buffer
, closeW
, 2);
1160 static const WCHAR closetagW
[] = {'<','/'};
1161 static const WCHAR gtW
[] = {'>'};
1163 write_output_buffer(This
->buffer
, closetagW
, 2);
1164 write_output_buffer(This
->buffer
, QName
, nQName
);
1165 write_output_buffer(This
->buffer
, gtW
, 1);
1168 set_element_name(This
, NULL
, 0);
1173 static HRESULT WINAPI
SAXContentHandler_characters(
1174 ISAXContentHandler
*iface
,
1178 mxwriter
*This
= impl_from_ISAXContentHandler( iface
);
1180 TRACE("(%p)->(%s:%d)\n", This
, debugstr_wn(chars
, nchars
), nchars
);
1182 if (!chars
) return E_INVALIDARG
;
1184 close_element_starttag(This
);
1185 set_element_name(This
, NULL
, 0);
1189 if (This
->cdata
|| This
->props
[MXWriter_DisableEscaping
] == VARIANT_TRUE
)
1190 write_output_buffer(This
->buffer
, chars
, nchars
);
1196 escaped
= get_escaped_string(chars
, EscapeText
, &len
);
1197 write_output_buffer(This
->buffer
, escaped
, len
);
1205 static HRESULT WINAPI
SAXContentHandler_ignorableWhitespace(
1206 ISAXContentHandler
*iface
,
1210 mxwriter
*This
= impl_from_ISAXContentHandler( iface
);
1212 TRACE("(%p)->(%s)\n", This
, debugstr_wn(chars
, nchars
));
1214 if (!chars
) return E_INVALIDARG
;
1216 write_output_buffer(This
->buffer
, chars
, nchars
);
1221 static HRESULT WINAPI
SAXContentHandler_processingInstruction(
1222 ISAXContentHandler
*iface
,
1223 const WCHAR
*target
,
1228 mxwriter
*This
= impl_from_ISAXContentHandler( iface
);
1229 static const WCHAR openpiW
[] = {'<','?'};
1230 static const WCHAR closepiW
[] = {'?','>','\r','\n'};
1232 TRACE("(%p)->(%s %s)\n", This
, debugstr_wn(target
, ntarget
), debugstr_wn(data
, ndata
));
1234 if (!target
) return E_INVALIDARG
;
1236 write_output_buffer(This
->buffer
, openpiW
, sizeof(openpiW
)/sizeof(WCHAR
));
1239 write_output_buffer(This
->buffer
, target
, ntarget
);
1241 if (data
&& *data
&& ndata
)
1243 write_output_buffer(This
->buffer
, spaceW
, 1);
1244 write_output_buffer(This
->buffer
, data
, ndata
);
1247 write_output_buffer(This
->buffer
, closepiW
, sizeof(closepiW
)/sizeof(WCHAR
));
1252 static HRESULT WINAPI
SAXContentHandler_skippedEntity(
1253 ISAXContentHandler
*iface
,
1257 mxwriter
*This
= impl_from_ISAXContentHandler( iface
);
1258 FIXME("(%p)->(%s)\n", This
, debugstr_wn(name
, nname
));
1262 static const struct ISAXContentHandlerVtbl SAXContentHandlerVtbl
=
1264 SAXContentHandler_QueryInterface
,
1265 SAXContentHandler_AddRef
,
1266 SAXContentHandler_Release
,
1267 SAXContentHandler_putDocumentLocator
,
1268 SAXContentHandler_startDocument
,
1269 SAXContentHandler_endDocument
,
1270 SAXContentHandler_startPrefixMapping
,
1271 SAXContentHandler_endPrefixMapping
,
1272 SAXContentHandler_startElement
,
1273 SAXContentHandler_endElement
,
1274 SAXContentHandler_characters
,
1275 SAXContentHandler_ignorableWhitespace
,
1276 SAXContentHandler_processingInstruction
,
1277 SAXContentHandler_skippedEntity
1280 /*** ISAXLexicalHandler ***/
1281 static HRESULT WINAPI
SAXLexicalHandler_QueryInterface(ISAXLexicalHandler
*iface
,
1282 REFIID riid
, void **obj
)
1284 mxwriter
*This
= impl_from_ISAXLexicalHandler( iface
);
1285 return IMXWriter_QueryInterface(&This
->IMXWriter_iface
, riid
, obj
);
1288 static ULONG WINAPI
SAXLexicalHandler_AddRef(ISAXLexicalHandler
*iface
)
1290 mxwriter
*This
= impl_from_ISAXLexicalHandler( iface
);
1291 return IMXWriter_AddRef(&This
->IMXWriter_iface
);
1294 static ULONG WINAPI
SAXLexicalHandler_Release(ISAXLexicalHandler
*iface
)
1296 mxwriter
*This
= impl_from_ISAXLexicalHandler( iface
);
1297 return IMXWriter_Release(&This
->IMXWriter_iface
);
1300 static HRESULT WINAPI
SAXLexicalHandler_startDTD(ISAXLexicalHandler
*iface
,
1301 const WCHAR
*name
, int name_len
, const WCHAR
*publicId
, int publicId_len
,
1302 const WCHAR
*systemId
, int systemId_len
)
1304 static const WCHAR doctypeW
[] = {'<','!','D','O','C','T','Y','P','E',' '};
1305 static const WCHAR openintW
[] = {'[','\r','\n'};
1307 mxwriter
*This
= impl_from_ISAXLexicalHandler( iface
);
1309 TRACE("(%p)->(%s %s %s)\n", This
, debugstr_wn(name
, name_len
), debugstr_wn(publicId
, publicId_len
),
1310 debugstr_wn(systemId
, systemId_len
));
1312 if (!name
) return E_INVALIDARG
;
1314 write_output_buffer(This
->buffer
, doctypeW
, sizeof(doctypeW
)/sizeof(WCHAR
));
1318 write_output_buffer(This
->buffer
, name
, name_len
);
1319 write_output_buffer(This
->buffer
, spaceW
, 1);
1324 static const WCHAR publicW
[] = {'P','U','B','L','I','C',' '};
1326 write_output_buffer(This
->buffer
, publicW
, sizeof(publicW
)/sizeof(WCHAR
));
1327 write_output_buffer_quoted(This
->buffer
, publicId
, publicId_len
);
1329 if (!systemId
) return E_INVALIDARG
;
1332 write_output_buffer(This
->buffer
, spaceW
, 1);
1334 write_output_buffer_quoted(This
->buffer
, systemId
, systemId_len
);
1337 write_output_buffer(This
->buffer
, spaceW
, 1);
1341 static const WCHAR systemW
[] = {'S','Y','S','T','E','M',' '};
1343 write_output_buffer(This
->buffer
, systemW
, sizeof(systemW
)/sizeof(WCHAR
));
1344 write_output_buffer_quoted(This
->buffer
, systemId
, systemId_len
);
1346 write_output_buffer(This
->buffer
, spaceW
, 1);
1349 write_output_buffer(This
->buffer
, openintW
, sizeof(openintW
)/sizeof(WCHAR
));
1354 static HRESULT WINAPI
SAXLexicalHandler_endDTD(ISAXLexicalHandler
*iface
)
1356 mxwriter
*This
= impl_from_ISAXLexicalHandler( iface
);
1357 static const WCHAR closedtdW
[] = {']','>','\r','\n'};
1359 TRACE("(%p)\n", This
);
1361 write_output_buffer(This
->buffer
, closedtdW
, sizeof(closedtdW
)/sizeof(WCHAR
));
1366 static HRESULT WINAPI
SAXLexicalHandler_startEntity(ISAXLexicalHandler
*iface
, const WCHAR
*name
, int len
)
1368 mxwriter
*This
= impl_from_ISAXLexicalHandler( iface
);
1369 FIXME("(%p)->(%s): stub\n", This
, debugstr_wn(name
, len
));
1373 static HRESULT WINAPI
SAXLexicalHandler_endEntity(ISAXLexicalHandler
*iface
, const WCHAR
*name
, int len
)
1375 mxwriter
*This
= impl_from_ISAXLexicalHandler( iface
);
1376 FIXME("(%p)->(%s): stub\n", This
, debugstr_wn(name
, len
));
1380 static HRESULT WINAPI
SAXLexicalHandler_startCDATA(ISAXLexicalHandler
*iface
)
1382 static const WCHAR scdataW
[] = {'<','!','[','C','D','A','T','A','['};
1383 mxwriter
*This
= impl_from_ISAXLexicalHandler( iface
);
1385 TRACE("(%p)\n", This
);
1387 write_output_buffer(This
->buffer
, scdataW
, sizeof(scdataW
)/sizeof(WCHAR
));
1393 static HRESULT WINAPI
SAXLexicalHandler_endCDATA(ISAXLexicalHandler
*iface
)
1395 mxwriter
*This
= impl_from_ISAXLexicalHandler( iface
);
1396 static const WCHAR ecdataW
[] = {']',']','>'};
1398 TRACE("(%p)\n", This
);
1400 write_output_buffer(This
->buffer
, ecdataW
, sizeof(ecdataW
)/sizeof(WCHAR
));
1401 This
->cdata
= FALSE
;
1406 static HRESULT WINAPI
SAXLexicalHandler_comment(ISAXLexicalHandler
*iface
, const WCHAR
*chars
, int nchars
)
1408 mxwriter
*This
= impl_from_ISAXLexicalHandler( iface
);
1409 static const WCHAR copenW
[] = {'<','!','-','-'};
1410 static const WCHAR ccloseW
[] = {'-','-','>','\r','\n'};
1412 TRACE("(%p)->(%s:%d)\n", This
, debugstr_wn(chars
, nchars
), nchars
);
1414 if (!chars
) return E_INVALIDARG
;
1416 close_element_starttag(This
);
1418 write_output_buffer(This
->buffer
, copenW
, sizeof(copenW
)/sizeof(WCHAR
));
1420 write_output_buffer(This
->buffer
, chars
, nchars
);
1421 write_output_buffer(This
->buffer
, ccloseW
, sizeof(ccloseW
)/sizeof(WCHAR
));
1426 static const struct ISAXLexicalHandlerVtbl SAXLexicalHandlerVtbl
=
1428 SAXLexicalHandler_QueryInterface
,
1429 SAXLexicalHandler_AddRef
,
1430 SAXLexicalHandler_Release
,
1431 SAXLexicalHandler_startDTD
,
1432 SAXLexicalHandler_endDTD
,
1433 SAXLexicalHandler_startEntity
,
1434 SAXLexicalHandler_endEntity
,
1435 SAXLexicalHandler_startCDATA
,
1436 SAXLexicalHandler_endCDATA
,
1437 SAXLexicalHandler_comment
1440 /*** ISAXDeclHandler ***/
1441 static HRESULT WINAPI
SAXDeclHandler_QueryInterface(ISAXDeclHandler
*iface
,
1442 REFIID riid
, void **obj
)
1444 mxwriter
*This
= impl_from_ISAXDeclHandler( iface
);
1445 return IMXWriter_QueryInterface(&This
->IMXWriter_iface
, riid
, obj
);
1448 static ULONG WINAPI
SAXDeclHandler_AddRef(ISAXDeclHandler
*iface
)
1450 mxwriter
*This
= impl_from_ISAXDeclHandler( iface
);
1451 return IMXWriter_AddRef(&This
->IMXWriter_iface
);
1454 static ULONG WINAPI
SAXDeclHandler_Release(ISAXDeclHandler
*iface
)
1456 mxwriter
*This
= impl_from_ISAXDeclHandler( iface
);
1457 return IMXWriter_Release(&This
->IMXWriter_iface
);
1460 static HRESULT WINAPI
SAXDeclHandler_elementDecl(ISAXDeclHandler
*iface
,
1461 const WCHAR
*name
, int n_name
, const WCHAR
*model
, int n_model
)
1463 static const WCHAR elementW
[] = {'<','!','E','L','E','M','E','N','T',' '};
1464 mxwriter
*This
= impl_from_ISAXDeclHandler( iface
);
1466 TRACE("(%p)->(%s:%d %s:%d)\n", This
, debugstr_wn(name
, n_name
), n_name
,
1467 debugstr_wn(model
, n_model
), n_model
);
1469 if (!name
|| !model
) return E_INVALIDARG
;
1471 write_output_buffer(This
->buffer
, elementW
, sizeof(elementW
)/sizeof(WCHAR
));
1473 write_output_buffer(This
->buffer
, name
, n_name
);
1474 write_output_buffer(This
->buffer
, spaceW
, sizeof(spaceW
)/sizeof(WCHAR
));
1477 write_output_buffer(This
->buffer
, model
, n_model
);
1478 write_output_buffer(This
->buffer
, closetagW
, sizeof(closetagW
)/sizeof(WCHAR
));
1483 static HRESULT WINAPI
SAXDeclHandler_attributeDecl(ISAXDeclHandler
*iface
,
1484 const WCHAR
*element
, int n_element
, const WCHAR
*attr
, int n_attr
,
1485 const WCHAR
*type
, int n_type
, const WCHAR
*Default
, int n_default
,
1486 const WCHAR
*value
, int n_value
)
1488 mxwriter
*This
= impl_from_ISAXDeclHandler( iface
);
1489 static const WCHAR attlistW
[] = {'<','!','A','T','T','L','I','S','T',' '};
1490 static const WCHAR closetagW
[] = {'>','\r','\n'};
1492 TRACE("(%p)->(%s:%d %s:%d %s:%d %s:%d %s:%d)\n", This
, debugstr_wn(element
, n_element
), n_element
,
1493 debugstr_wn(attr
, n_attr
), n_attr
, debugstr_wn(type
, n_type
), n_type
, debugstr_wn(Default
, n_default
), n_default
,
1494 debugstr_wn(value
, n_value
), n_value
);
1496 write_output_buffer(This
->buffer
, attlistW
, sizeof(attlistW
)/sizeof(WCHAR
));
1498 write_output_buffer(This
->buffer
, element
, n_element
);
1499 write_output_buffer(This
->buffer
, spaceW
, sizeof(spaceW
)/sizeof(WCHAR
));
1503 write_output_buffer(This
->buffer
, attr
, n_attr
);
1504 write_output_buffer(This
->buffer
, spaceW
, sizeof(spaceW
)/sizeof(WCHAR
));
1508 write_output_buffer(This
->buffer
, type
, n_type
);
1509 write_output_buffer(This
->buffer
, spaceW
, sizeof(spaceW
)/sizeof(WCHAR
));
1513 write_output_buffer(This
->buffer
, Default
, n_default
);
1514 write_output_buffer(This
->buffer
, spaceW
, sizeof(spaceW
)/sizeof(WCHAR
));
1518 write_output_buffer_quoted(This
->buffer
, value
, n_value
);
1520 write_output_buffer(This
->buffer
, closetagW
, sizeof(closetagW
)/sizeof(WCHAR
));
1525 static HRESULT WINAPI
SAXDeclHandler_internalEntityDecl(ISAXDeclHandler
*iface
,
1526 const WCHAR
*name
, int n_name
, const WCHAR
*value
, int n_value
)
1528 mxwriter
*This
= impl_from_ISAXDeclHandler( iface
);
1529 static const WCHAR entityW
[] = {'<','!','E','N','T','I','T','Y',' '};
1531 TRACE("(%p)->(%s:%d %s:%d)\n", This
, debugstr_wn(name
, n_name
), n_name
,
1532 debugstr_wn(value
, n_value
), n_value
);
1534 if (!name
|| !value
) return E_INVALIDARG
;
1536 write_output_buffer(This
->buffer
, entityW
, sizeof(entityW
)/sizeof(WCHAR
));
1538 write_output_buffer(This
->buffer
, name
, n_name
);
1539 write_output_buffer(This
->buffer
, spaceW
, sizeof(spaceW
)/sizeof(WCHAR
));
1543 write_output_buffer_quoted(This
->buffer
, value
, n_value
);
1545 write_output_buffer(This
->buffer
, closetagW
, sizeof(closetagW
)/sizeof(WCHAR
));
1550 static HRESULT WINAPI
SAXDeclHandler_externalEntityDecl(ISAXDeclHandler
*iface
,
1551 const WCHAR
*name
, int n_name
, const WCHAR
*publicId
, int n_publicId
,
1552 const WCHAR
*systemId
, int n_systemId
)
1554 mxwriter
*This
= impl_from_ISAXDeclHandler( iface
);
1555 FIXME("(%p)->(%s:%d %s:%d %s:%d): stub\n", This
, debugstr_wn(name
, n_name
), n_name
,
1556 debugstr_wn(publicId
, n_publicId
), n_publicId
, debugstr_wn(systemId
, n_systemId
), n_systemId
);
1560 static const ISAXDeclHandlerVtbl SAXDeclHandlerVtbl
= {
1561 SAXDeclHandler_QueryInterface
,
1562 SAXDeclHandler_AddRef
,
1563 SAXDeclHandler_Release
,
1564 SAXDeclHandler_elementDecl
,
1565 SAXDeclHandler_attributeDecl
,
1566 SAXDeclHandler_internalEntityDecl
,
1567 SAXDeclHandler_externalEntityDecl
1570 static const tid_t mxwriter_iface_tids
[] = {
1575 static dispex_static_data_t mxwriter_dispex
= {
1582 HRESULT
MXWriter_create(MSXML_VERSION version
, IUnknown
*outer
, void **ppObj
)
1584 static const WCHAR version10W
[] = {'1','.','0',0};
1588 TRACE("(%p, %p)\n", outer
, ppObj
);
1590 if (outer
) FIXME("support aggregation, outer\n");
1592 This
= heap_alloc( sizeof (*This
) );
1594 return E_OUTOFMEMORY
;
1596 This
->IMXWriter_iface
.lpVtbl
= &MXWriterVtbl
;
1597 This
->ISAXContentHandler_iface
.lpVtbl
= &SAXContentHandlerVtbl
;
1598 This
->ISAXLexicalHandler_iface
.lpVtbl
= &SAXLexicalHandlerVtbl
;
1599 This
->ISAXDeclHandler_iface
.lpVtbl
= &SAXDeclHandlerVtbl
;
1601 This
->class_version
= version
;
1603 This
->props
[MXWriter_BOM
] = VARIANT_TRUE
;
1604 This
->props
[MXWriter_DisableEscaping
] = VARIANT_FALSE
;
1605 This
->props
[MXWriter_Indent
] = VARIANT_FALSE
;
1606 This
->props
[MXWriter_OmitXmlDecl
] = VARIANT_FALSE
;
1607 This
->props
[MXWriter_Standalone
] = VARIANT_FALSE
;
1608 This
->prop_changed
= FALSE
;
1609 This
->encoding
= SysAllocString(utf16W
);
1610 This
->version
= SysAllocString(version10W
);
1611 This
->xml_enc
= XmlEncoding_UTF16
;
1613 This
->element
= NULL
;
1614 This
->cdata
= FALSE
;
1617 This
->dest_written
= 0;
1619 hr
= alloc_output_buffer(This
->xml_enc
, &This
->buffer
);
1621 SysFreeString(This
->encoding
);
1622 SysFreeString(This
->version
);
1627 init_dispex(&This
->dispex
, (IUnknown
*)&This
->IMXWriter_iface
, &mxwriter_dispex
);
1629 *ppObj
= &This
->IMXWriter_iface
;
1631 TRACE("returning iface %p\n", *ppObj
);
1636 static HRESULT WINAPI
MXAttributes_QueryInterface(IMXAttributes
*iface
, REFIID riid
, void **ppObj
)
1638 mxattributes
*This
= impl_from_IMXAttributes( iface
);
1640 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid( riid
), ppObj
);
1644 if ( IsEqualGUID( riid
, &IID_IUnknown
) ||
1645 IsEqualGUID( riid
, &IID_IDispatch
) ||
1646 IsEqualGUID( riid
, &IID_IMXAttributes
))
1650 else if ( IsEqualGUID( riid
, &IID_ISAXAttributes
))
1652 *ppObj
= &This
->ISAXAttributes_iface
;
1654 else if ( IsEqualGUID( riid
, &IID_IVBSAXAttributes
))
1656 *ppObj
= &This
->IVBSAXAttributes_iface
;
1658 else if (dispex_query_interface(&This
->dispex
, riid
, ppObj
))
1660 return *ppObj
? S_OK
: E_NOINTERFACE
;
1664 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
1665 return E_NOINTERFACE
;
1668 IMXAttributes_AddRef( iface
);
1673 static ULONG WINAPI
MXAttributes_AddRef(IMXAttributes
*iface
)
1675 mxattributes
*This
= impl_from_IMXAttributes( iface
);
1676 ULONG ref
= InterlockedIncrement( &This
->ref
);
1677 TRACE("(%p)->(%d)\n", This
, ref
);
1681 static ULONG WINAPI
MXAttributes_Release(IMXAttributes
*iface
)
1683 mxattributes
*This
= impl_from_IMXAttributes( iface
);
1684 LONG ref
= InterlockedDecrement( &This
->ref
);
1686 TRACE("(%p)->(%d)\n", This
, ref
);
1692 for (i
= 0; i
< This
->length
; i
++)
1694 SysFreeString(This
->attr
[i
].qname
);
1695 SysFreeString(This
->attr
[i
].local
);
1696 SysFreeString(This
->attr
[i
].uri
);
1697 SysFreeString(This
->attr
[i
].type
);
1698 SysFreeString(This
->attr
[i
].value
);
1701 release_dispex(&This
->dispex
);
1702 heap_free(This
->attr
);
1709 static HRESULT WINAPI
MXAttributes_GetTypeInfoCount(IMXAttributes
*iface
, UINT
* pctinfo
)
1711 mxattributes
*This
= impl_from_IMXAttributes( iface
);
1712 return IDispatchEx_GetTypeInfoCount(&This
->dispex
.IDispatchEx_iface
, pctinfo
);
1715 static HRESULT WINAPI
MXAttributes_GetTypeInfo(IMXAttributes
*iface
, UINT iTInfo
, LCID lcid
, ITypeInfo
** ppTInfo
)
1717 mxattributes
*This
= impl_from_IMXAttributes( iface
);
1718 return IDispatchEx_GetTypeInfo(&This
->dispex
.IDispatchEx_iface
, iTInfo
, lcid
, ppTInfo
);
1721 static HRESULT WINAPI
MXAttributes_GetIDsOfNames(
1722 IMXAttributes
*iface
,
1724 LPOLESTR
* rgszNames
,
1729 mxattributes
*This
= impl_from_IMXAttributes( iface
);
1730 return IDispatchEx_GetIDsOfNames(&This
->dispex
.IDispatchEx_iface
,
1731 riid
, rgszNames
, cNames
, lcid
, rgDispId
);
1734 static HRESULT WINAPI
MXAttributes_Invoke(
1735 IMXAttributes
*iface
,
1736 DISPID dispIdMember
,
1740 DISPPARAMS
* pDispParams
,
1741 VARIANT
* pVarResult
,
1742 EXCEPINFO
* pExcepInfo
,
1745 mxattributes
*This
= impl_from_IMXAttributes( iface
);
1746 return IDispatchEx_Invoke(&This
->dispex
.IDispatchEx_iface
,
1747 dispIdMember
, riid
, lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1750 static HRESULT WINAPI
MXAttributes_addAttribute(IMXAttributes
*iface
,
1751 BSTR uri
, BSTR localName
, BSTR QName
, BSTR type
, BSTR value
)
1753 mxattributes
*This
= impl_from_IMXAttributes( iface
);
1757 TRACE("(%p)->(%s %s %s %s %s)\n", This
, debugstr_w(uri
), debugstr_w(localName
),
1758 debugstr_w(QName
), debugstr_w(type
), debugstr_w(value
));
1760 if ((!uri
|| !localName
|| !QName
|| !type
|| !value
) && This
->class_version
!= MSXML6
)
1761 return E_INVALIDARG
;
1763 /* ensure array is large enough */
1764 hr
= mxattributes_grow(This
);
1765 if (hr
!= S_OK
) return hr
;
1767 attr
= &This
->attr
[This
->length
];
1769 attr
->qname
= SysAllocString(QName
);
1770 attr
->local
= SysAllocString(localName
);
1771 attr
->uri
= SysAllocString(uri
);
1772 attr
->type
= SysAllocString(type
? type
: emptyW
);
1773 attr
->value
= SysAllocString(value
);
1779 static HRESULT WINAPI
MXAttributes_addAttributeFromIndex(IMXAttributes
*iface
,
1780 VARIANT atts
, int index
)
1782 mxattributes
*This
= impl_from_IMXAttributes( iface
);
1783 FIXME("(%p)->(%s %d): stub\n", This
, debugstr_variant(&atts
), index
);
1787 static HRESULT WINAPI
MXAttributes_clear(IMXAttributes
*iface
)
1789 mxattributes
*This
= impl_from_IMXAttributes( iface
);
1792 TRACE("(%p)\n", This
);
1794 for (i
= 0; i
< This
->length
; i
++)
1796 SysFreeString(This
->attr
[i
].qname
);
1797 SysFreeString(This
->attr
[i
].local
);
1798 SysFreeString(This
->attr
[i
].uri
);
1799 SysFreeString(This
->attr
[i
].type
);
1800 SysFreeString(This
->attr
[i
].value
);
1801 memset(&This
->attr
[i
], 0, sizeof(mxattribute
));
1809 static HRESULT WINAPI
MXAttributes_removeAttribute(IMXAttributes
*iface
, int index
)
1811 mxattributes
*This
= impl_from_IMXAttributes( iface
);
1812 FIXME("(%p)->(%d): stub\n", This
, index
);
1816 static HRESULT WINAPI
MXAttributes_setAttribute(IMXAttributes
*iface
, int index
,
1817 BSTR uri
, BSTR localName
, BSTR QName
, BSTR type
, BSTR value
)
1819 mxattributes
*This
= impl_from_IMXAttributes( iface
);
1820 FIXME("(%p)->(%d %s %s %s %s %s): stub\n", This
, index
, debugstr_w(uri
),
1821 debugstr_w(localName
), debugstr_w(QName
), debugstr_w(type
), debugstr_w(value
));
1825 static HRESULT WINAPI
MXAttributes_setAttributes(IMXAttributes
*iface
, VARIANT atts
)
1827 mxattributes
*This
= impl_from_IMXAttributes( iface
);
1828 FIXME("(%p)->(%s): stub\n", This
, debugstr_variant(&atts
));
1832 static HRESULT WINAPI
MXAttributes_setLocalName(IMXAttributes
*iface
, int index
,
1835 mxattributes
*This
= impl_from_IMXAttributes( iface
);
1836 FIXME("(%p)->(%d %s): stub\n", This
, index
, debugstr_w(localName
));
1840 static HRESULT WINAPI
MXAttributes_setQName(IMXAttributes
*iface
, int index
, BSTR QName
)
1842 mxattributes
*This
= impl_from_IMXAttributes( iface
);
1843 FIXME("(%p)->(%d %s): stub\n", This
, index
, debugstr_w(QName
));
1847 static HRESULT WINAPI
MXAttributes_setURI(IMXAttributes
*iface
, int index
, BSTR uri
)
1849 mxattributes
*This
= impl_from_IMXAttributes( iface
);
1850 FIXME("(%p)->(%d %s): stub\n", This
, index
, debugstr_w(uri
));
1854 static HRESULT WINAPI
MXAttributes_setValue(IMXAttributes
*iface
, int index
, BSTR value
)
1856 mxattributes
*This
= impl_from_IMXAttributes( iface
);
1857 FIXME("(%p)->(%d %s): stub\n", This
, index
, debugstr_w(value
));
1861 static const IMXAttributesVtbl MXAttributesVtbl
= {
1862 MXAttributes_QueryInterface
,
1863 MXAttributes_AddRef
,
1864 MXAttributes_Release
,
1865 MXAttributes_GetTypeInfoCount
,
1866 MXAttributes_GetTypeInfo
,
1867 MXAttributes_GetIDsOfNames
,
1868 MXAttributes_Invoke
,
1869 MXAttributes_addAttribute
,
1870 MXAttributes_addAttributeFromIndex
,
1872 MXAttributes_removeAttribute
,
1873 MXAttributes_setAttribute
,
1874 MXAttributes_setAttributes
,
1875 MXAttributes_setLocalName
,
1876 MXAttributes_setQName
,
1877 MXAttributes_setURI
,
1878 MXAttributes_setValue
1881 static HRESULT WINAPI
SAXAttributes_QueryInterface(ISAXAttributes
*iface
, REFIID riid
, void **ppObj
)
1883 mxattributes
*This
= impl_from_ISAXAttributes( iface
);
1884 return IMXAttributes_QueryInterface(&This
->IMXAttributes_iface
, riid
, ppObj
);
1887 static ULONG WINAPI
SAXAttributes_AddRef(ISAXAttributes
*iface
)
1889 mxattributes
*This
= impl_from_ISAXAttributes( iface
);
1890 return IMXAttributes_AddRef(&This
->IMXAttributes_iface
);
1893 static ULONG WINAPI
SAXAttributes_Release(ISAXAttributes
*iface
)
1895 mxattributes
*This
= impl_from_ISAXAttributes( iface
);
1896 return IMXAttributes_Release(&This
->IMXAttributes_iface
);
1899 static HRESULT WINAPI
SAXAttributes_getLength(ISAXAttributes
*iface
, int *length
)
1901 mxattributes
*This
= impl_from_ISAXAttributes( iface
);
1902 TRACE("(%p)->(%p)\n", This
, length
);
1904 if (!length
&& (This
->class_version
== MSXML_DEFAULT
|| This
->class_version
== MSXML3
))
1907 *length
= This
->length
;
1912 static HRESULT WINAPI
SAXAttributes_getURI(ISAXAttributes
*iface
, int index
, const WCHAR
**uri
,
1915 mxattributes
*This
= impl_from_ISAXAttributes( iface
);
1917 TRACE("(%p)->(%d %p %p)\n", This
, index
, uri
, len
);
1919 if (index
>= This
->length
|| index
< 0) return E_INVALIDARG
;
1920 if (!uri
|| !len
) return E_POINTER
;
1922 *len
= SysStringLen(This
->attr
[index
].uri
);
1923 *uri
= This
->attr
[index
].uri
;
1928 static HRESULT WINAPI
SAXAttributes_getLocalName(ISAXAttributes
*iface
, int index
, const WCHAR
**name
,
1931 mxattributes
*This
= impl_from_ISAXAttributes( iface
);
1933 TRACE("(%p)->(%d %p %p)\n", This
, index
, name
, len
);
1935 if (index
>= This
->length
|| index
< 0) return E_INVALIDARG
;
1936 if (!name
|| !len
) return E_POINTER
;
1938 *len
= SysStringLen(This
->attr
[index
].local
);
1939 *name
= This
->attr
[index
].local
;
1944 static HRESULT WINAPI
SAXAttributes_getQName(ISAXAttributes
*iface
, int index
, const WCHAR
**qname
, int *length
)
1946 mxattributes
*This
= impl_from_ISAXAttributes( iface
);
1948 TRACE("(%p)->(%d %p %p)\n", This
, index
, qname
, length
);
1950 if (index
>= This
->length
) return E_INVALIDARG
;
1951 if (!qname
|| !length
) return E_POINTER
;
1953 *qname
= This
->attr
[index
].qname
;
1954 *length
= SysStringLen(This
->attr
[index
].qname
);
1959 static HRESULT WINAPI
SAXAttributes_getName(ISAXAttributes
*iface
, int index
, const WCHAR
**uri
, int *uri_len
,
1960 const WCHAR
**local
, int *local_len
, const WCHAR
**qname
, int *qname_len
)
1962 mxattributes
*This
= impl_from_ISAXAttributes( iface
);
1964 TRACE("(%p)->(%d %p %p %p %p %p %p)\n", This
, index
, uri
, uri_len
, local
, local_len
, qname
, qname_len
);
1966 if (index
>= This
->length
|| index
< 0)
1967 return E_INVALIDARG
;
1969 if (!uri
|| !uri_len
|| !local
|| !local_len
|| !qname
|| !qname_len
)
1972 *uri_len
= SysStringLen(This
->attr
[index
].uri
);
1973 *uri
= This
->attr
[index
].uri
;
1975 *local_len
= SysStringLen(This
->attr
[index
].local
);
1976 *local
= This
->attr
[index
].local
;
1978 *qname_len
= SysStringLen(This
->attr
[index
].qname
);
1979 *qname
= This
->attr
[index
].qname
;
1981 TRACE("(%s, %s, %s)\n", debugstr_w(*uri
), debugstr_w(*local
), debugstr_w(*qname
));
1986 static HRESULT WINAPI
SAXAttributes_getIndexFromName(ISAXAttributes
*iface
, const WCHAR
*uri
, int uri_len
,
1987 const WCHAR
*name
, int len
, int *index
)
1989 mxattributes
*This
= impl_from_ISAXAttributes( iface
);
1992 TRACE("(%p)->(%s:%d %s:%d %p)\n", This
, debugstr_wn(uri
, uri_len
), uri_len
,
1993 debugstr_wn(name
, len
), len
, index
);
1995 if (!index
&& (This
->class_version
== MSXML_DEFAULT
|| This
->class_version
== MSXML3
))
1998 if (!uri
|| !name
|| !index
) return E_INVALIDARG
;
2000 for (i
= 0; i
< This
->length
; i
++)
2002 if (uri_len
!= SysStringLen(This
->attr
[i
].uri
)) continue;
2003 if (strncmpW(uri
, This
->attr
[i
].uri
, uri_len
)) continue;
2005 if (len
!= SysStringLen(This
->attr
[i
].local
)) continue;
2006 if (strncmpW(name
, This
->attr
[i
].local
, len
)) continue;
2012 return E_INVALIDARG
;
2015 static HRESULT WINAPI
SAXAttributes_getIndexFromQName(ISAXAttributes
*iface
, const WCHAR
*qname
,
2016 int len
, int *index
)
2018 mxattributes
*This
= impl_from_ISAXAttributes( iface
);
2021 TRACE("(%p)->(%s:%d %p)\n", This
, debugstr_wn(qname
, len
), len
, index
);
2023 if (!index
&& (This
->class_version
== MSXML_DEFAULT
|| This
->class_version
== MSXML3
))
2026 if (!qname
|| !index
|| !len
) return E_INVALIDARG
;
2028 for (i
= 0; i
< This
->length
; i
++)
2030 if (len
!= SysStringLen(This
->attr
[i
].qname
)) continue;
2031 if (strncmpW(qname
, This
->attr
[i
].qname
, len
)) continue;
2037 return E_INVALIDARG
;
2040 static HRESULT WINAPI
SAXAttributes_getType(ISAXAttributes
*iface
, int index
, const WCHAR
**type
,
2043 mxattributes
*This
= impl_from_ISAXAttributes( iface
);
2045 TRACE("(%p)->(%d %p %p)\n", This
, index
, type
, len
);
2047 if (index
>= This
->length
) return E_INVALIDARG
;
2049 if ((!type
|| !len
) && (This
->class_version
== MSXML_DEFAULT
|| This
->class_version
== MSXML3
))
2052 *type
= This
->attr
[index
].type
;
2053 *len
= SysStringLen(This
->attr
[index
].type
);
2058 static HRESULT WINAPI
SAXAttributes_getTypeFromName(ISAXAttributes
*iface
, const WCHAR
* pUri
, int nUri
,
2059 const WCHAR
* pLocalName
, int nLocalName
, const WCHAR
** pType
, int * nType
)
2061 mxattributes
*This
= impl_from_ISAXAttributes( iface
);
2062 FIXME("(%p)->(%s:%d %s:%d %p %p): stub\n", This
, debugstr_wn(pUri
, nUri
), nUri
,
2063 debugstr_wn(pLocalName
, nLocalName
), nLocalName
, pType
, nType
);
2067 static HRESULT WINAPI
SAXAttributes_getTypeFromQName(ISAXAttributes
*iface
, const WCHAR
* pQName
,
2068 int nQName
, const WCHAR
** pType
, int * nType
)
2070 mxattributes
*This
= impl_from_ISAXAttributes( iface
);
2071 FIXME("(%p)->(%s:%d %p %p): stub\n", This
, debugstr_wn(pQName
, nQName
), nQName
, pType
, nType
);
2075 static HRESULT WINAPI
SAXAttributes_getValue(ISAXAttributes
*iface
, int index
, const WCHAR
**value
,
2078 mxattributes
*This
= impl_from_ISAXAttributes( iface
);
2080 TRACE("(%p)->(%d %p %p)\n", This
, index
, value
, len
);
2082 if (index
>= This
->length
) return E_INVALIDARG
;
2084 if ((!value
|| !len
) && (This
->class_version
== MSXML_DEFAULT
|| This
->class_version
== MSXML3
))
2087 *value
= This
->attr
[index
].value
;
2088 *len
= SysStringLen(This
->attr
[index
].value
);
2093 static HRESULT WINAPI
SAXAttributes_getValueFromName(ISAXAttributes
*iface
, const WCHAR
*uri
,
2094 int uri_len
, const WCHAR
*name
, int name_len
, const WCHAR
**value
, int *value_len
)
2096 mxattributes
*This
= impl_from_ISAXAttributes( iface
);
2100 TRACE("(%p)->(%s:%d %s:%d %p %p)\n", This
, debugstr_wn(uri
, uri_len
), uri_len
,
2101 debugstr_wn(name
, name_len
), name_len
, value
, value_len
);
2103 if (!uri
|| !name
|| !value
|| !value_len
)
2104 return (This
->class_version
== MSXML_DEFAULT
|| This
->class_version
== MSXML3
) ? E_POINTER
: E_INVALIDARG
;
2106 hr
= ISAXAttributes_getIndexFromName(iface
, uri
, uri_len
, name
, name_len
, &index
);
2108 hr
= ISAXAttributes_getValue(iface
, index
, value
, value_len
);
2113 static HRESULT WINAPI
SAXAttributes_getValueFromQName(ISAXAttributes
*iface
, const WCHAR
*qname
,
2114 int qname_len
, const WCHAR
**value
, int *value_len
)
2116 mxattributes
*This
= impl_from_ISAXAttributes( iface
);
2120 TRACE("(%p)->(%s:%d %p %p)\n", This
, debugstr_wn(qname
, qname_len
), qname_len
, value
, value_len
);
2122 if (!qname
|| !value
|| !value_len
)
2123 return (This
->class_version
== MSXML_DEFAULT
|| This
->class_version
== MSXML3
) ? E_POINTER
: E_INVALIDARG
;
2125 hr
= ISAXAttributes_getIndexFromQName(iface
, qname
, qname_len
, &index
);
2127 hr
= ISAXAttributes_getValue(iface
, index
, value
, value_len
);
2132 static const ISAXAttributesVtbl SAXAttributesVtbl
= {
2133 SAXAttributes_QueryInterface
,
2134 SAXAttributes_AddRef
,
2135 SAXAttributes_Release
,
2136 SAXAttributes_getLength
,
2137 SAXAttributes_getURI
,
2138 SAXAttributes_getLocalName
,
2139 SAXAttributes_getQName
,
2140 SAXAttributes_getName
,
2141 SAXAttributes_getIndexFromName
,
2142 SAXAttributes_getIndexFromQName
,
2143 SAXAttributes_getType
,
2144 SAXAttributes_getTypeFromName
,
2145 SAXAttributes_getTypeFromQName
,
2146 SAXAttributes_getValue
,
2147 SAXAttributes_getValueFromName
,
2148 SAXAttributes_getValueFromQName
2151 static HRESULT WINAPI
VBSAXAttributes_QueryInterface(
2152 IVBSAXAttributes
* iface
,
2156 mxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
2157 TRACE("%p %s %p\n", This
, debugstr_guid(riid
), ppvObject
);
2158 return ISAXAttributes_QueryInterface(&This
->ISAXAttributes_iface
, riid
, ppvObject
);
2161 static ULONG WINAPI
VBSAXAttributes_AddRef(IVBSAXAttributes
* iface
)
2163 mxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
2164 return ISAXAttributes_AddRef(&This
->ISAXAttributes_iface
);
2167 static ULONG WINAPI
VBSAXAttributes_Release(IVBSAXAttributes
* iface
)
2169 mxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
2170 return ISAXAttributes_Release(&This
->ISAXAttributes_iface
);
2173 static HRESULT WINAPI
VBSAXAttributes_GetTypeInfoCount( IVBSAXAttributes
*iface
, UINT
* pctinfo
)
2175 mxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
2177 TRACE("(%p)->(%p)\n", This
, pctinfo
);
2184 static HRESULT WINAPI
VBSAXAttributes_GetTypeInfo(
2185 IVBSAXAttributes
*iface
,
2186 UINT iTInfo
, LCID lcid
, ITypeInfo
** ppTInfo
)
2188 mxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
2189 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
2190 return get_typeinfo(IVBSAXAttributes_tid
, ppTInfo
);
2193 static HRESULT WINAPI
VBSAXAttributes_GetIDsOfNames(
2194 IVBSAXAttributes
*iface
,
2196 LPOLESTR
* rgszNames
,
2201 mxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
2202 ITypeInfo
*typeinfo
;
2205 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
2208 if(!rgszNames
|| cNames
== 0 || !rgDispId
)
2209 return E_INVALIDARG
;
2211 hr
= get_typeinfo(IVBSAXAttributes_tid
, &typeinfo
);
2214 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
2215 ITypeInfo_Release(typeinfo
);
2221 static HRESULT WINAPI
VBSAXAttributes_Invoke(
2222 IVBSAXAttributes
*iface
,
2223 DISPID dispIdMember
,
2227 DISPPARAMS
* pDispParams
,
2228 VARIANT
* pVarResult
,
2229 EXCEPINFO
* pExcepInfo
,
2232 mxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
2233 ITypeInfo
*typeinfo
;
2236 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
2237 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
2239 hr
= get_typeinfo(IVBSAXAttributes_tid
, &typeinfo
);
2242 hr
= ITypeInfo_Invoke(typeinfo
, &This
->IVBSAXAttributes_iface
, dispIdMember
, wFlags
,
2243 pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
2244 ITypeInfo_Release(typeinfo
);
2250 static HRESULT WINAPI
VBSAXAttributes_get_length(IVBSAXAttributes
* iface
, int *len
)
2252 mxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
2253 return ISAXAttributes_getLength(&This
->ISAXAttributes_iface
, len
);
2256 static HRESULT WINAPI
VBSAXAttributes_getURI(IVBSAXAttributes
* iface
, int index
, BSTR
*uri
)
2258 mxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
2261 return ISAXAttributes_getURI(&This
->ISAXAttributes_iface
, index
, (const WCHAR
**)uri
, &len
);
2264 static HRESULT WINAPI
VBSAXAttributes_getLocalName(IVBSAXAttributes
* iface
, int index
, BSTR
*name
)
2266 mxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
2269 return ISAXAttributes_getLocalName(&This
->ISAXAttributes_iface
, index
, (const WCHAR
**)name
, &len
);
2272 static HRESULT WINAPI
VBSAXAttributes_getQName(IVBSAXAttributes
* iface
, int index
, BSTR
*qname
)
2274 mxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
2277 return ISAXAttributes_getQName(&This
->ISAXAttributes_iface
, index
, (const WCHAR
**)qname
, &len
);
2280 static HRESULT WINAPI
VBSAXAttributes_getIndexFromName(IVBSAXAttributes
* iface
, BSTR uri
, BSTR name
, int *index
)
2282 mxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
2283 return ISAXAttributes_getIndexFromName(&This
->ISAXAttributes_iface
, uri
, SysStringLen(uri
),
2284 name
, SysStringLen(name
), index
);
2287 static HRESULT WINAPI
VBSAXAttributes_getIndexFromQName(IVBSAXAttributes
* iface
, BSTR qname
, int *index
)
2289 mxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
2290 return ISAXAttributes_getIndexFromQName(&This
->ISAXAttributes_iface
, qname
,
2291 SysStringLen(qname
), index
);
2294 static HRESULT WINAPI
VBSAXAttributes_getType(IVBSAXAttributes
* iface
, int index
,BSTR
*type
)
2296 mxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
2299 return ISAXAttributes_getType(&This
->ISAXAttributes_iface
, index
, (const WCHAR
**)type
, &len
);
2302 static HRESULT WINAPI
VBSAXAttributes_getTypeFromName(IVBSAXAttributes
* iface
, BSTR uri
,
2303 BSTR name
, BSTR
*type
)
2305 mxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
2308 return ISAXAttributes_getTypeFromName(&This
->ISAXAttributes_iface
, uri
, SysStringLen(uri
),
2309 name
, SysStringLen(name
), (const WCHAR
**)type
, &len
);
2312 static HRESULT WINAPI
VBSAXAttributes_getTypeFromQName(IVBSAXAttributes
* iface
, BSTR qname
, BSTR
*type
)
2314 mxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
2317 return ISAXAttributes_getTypeFromQName(&This
->ISAXAttributes_iface
, qname
, SysStringLen(qname
),
2318 (const WCHAR
**)type
, &len
);
2321 static HRESULT WINAPI
VBSAXAttributes_getValue(IVBSAXAttributes
* iface
, int index
, BSTR
*value
)
2323 mxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
2326 return ISAXAttributes_getValue(&This
->ISAXAttributes_iface
, index
, (const WCHAR
**)value
, &len
);
2329 static HRESULT WINAPI
VBSAXAttributes_getValueFromName(IVBSAXAttributes
* iface
, BSTR uri
, BSTR name
,
2332 mxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
2335 return ISAXAttributes_getValueFromName(&This
->ISAXAttributes_iface
, uri
, SysStringLen(uri
),
2336 name
, SysStringLen(name
), (const WCHAR
**)value
, &len
);
2339 static HRESULT WINAPI
VBSAXAttributes_getValueFromQName(IVBSAXAttributes
* iface
, BSTR qname
, BSTR
*value
)
2341 mxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
2344 return ISAXAttributes_getValueFromQName(&This
->ISAXAttributes_iface
, qname
, SysStringLen(qname
),
2345 (const WCHAR
**)value
, &len
);
2348 static const struct IVBSAXAttributesVtbl VBSAXAttributesVtbl
=
2350 VBSAXAttributes_QueryInterface
,
2351 VBSAXAttributes_AddRef
,
2352 VBSAXAttributes_Release
,
2353 VBSAXAttributes_GetTypeInfoCount
,
2354 VBSAXAttributes_GetTypeInfo
,
2355 VBSAXAttributes_GetIDsOfNames
,
2356 VBSAXAttributes_Invoke
,
2357 VBSAXAttributes_get_length
,
2358 VBSAXAttributes_getURI
,
2359 VBSAXAttributes_getLocalName
,
2360 VBSAXAttributes_getQName
,
2361 VBSAXAttributes_getIndexFromName
,
2362 VBSAXAttributes_getIndexFromQName
,
2363 VBSAXAttributes_getType
,
2364 VBSAXAttributes_getTypeFromName
,
2365 VBSAXAttributes_getTypeFromQName
,
2366 VBSAXAttributes_getValue
,
2367 VBSAXAttributes_getValueFromName
,
2368 VBSAXAttributes_getValueFromQName
2371 static const tid_t mxattrs_iface_tids
[] = {
2376 static dispex_static_data_t mxattrs_dispex
= {
2383 HRESULT
SAXAttributes_create(MSXML_VERSION version
, IUnknown
*outer
, void **ppObj
)
2385 static const int default_count
= 10;
2388 TRACE("(%p, %p)\n", outer
, ppObj
);
2390 This
= heap_alloc( sizeof (*This
) );
2392 return E_OUTOFMEMORY
;
2394 This
->IMXAttributes_iface
.lpVtbl
= &MXAttributesVtbl
;
2395 This
->ISAXAttributes_iface
.lpVtbl
= &SAXAttributesVtbl
;
2396 This
->IVBSAXAttributes_iface
.lpVtbl
= &VBSAXAttributesVtbl
;
2399 This
->class_version
= version
;
2401 This
->attr
= heap_alloc(default_count
*sizeof(mxattribute
));
2403 This
->allocated
= default_count
;
2405 *ppObj
= &This
->IMXAttributes_iface
;
2407 init_dispex(&This
->dispex
, (IUnknown
*)&This
->IMXAttributes_iface
, &mxattrs_dispex
);
2409 TRACE("returning iface %p\n", *ppObj
);