2 * MXWriter implementation
4 * Copyright 2011-2013 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
27 # include <libxml/parser.h>
36 #include "wine/debug.h"
38 #include "msxml_private.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(msxml
);
42 static const WCHAR emptyW
[] = {0};
43 static const WCHAR spaceW
[] = {' '};
44 static const WCHAR quotW
[] = {'\"'};
45 static const WCHAR closetagW
[] = {'>','\r','\n'};
46 static const WCHAR crlfW
[] = {'\r','\n'};
47 static const WCHAR entityW
[] = {'<','!','E','N','T','I','T','Y',' '};
49 /* should be ordered as encoding names are sorted */
52 XmlEncoding_ISO_8859_1
= 0,
53 XmlEncoding_ISO_8859_13
,
54 XmlEncoding_ISO_8859_15
,
55 XmlEncoding_ISO_8859_2
,
56 XmlEncoding_ISO_8859_3
,
57 XmlEncoding_ISO_8859_4
,
58 XmlEncoding_ISO_8859_5
,
59 XmlEncoding_ISO_8859_7
,
60 XmlEncoding_ISO_8859_9
,
66 struct xml_encoding_data
68 const WCHAR
*encoding
;
73 static const WCHAR iso_8859_1W
[] = {'i','s','o','-','8','8','5','9','-','1',0};
74 static const WCHAR iso_8859_2W
[] = {'i','s','o','-','8','8','5','9','-','2',0};
75 static const WCHAR iso_8859_3W
[] = {'i','s','o','-','8','8','5','9','-','3',0};
76 static const WCHAR iso_8859_4W
[] = {'i','s','o','-','8','8','5','9','-','4',0};
77 static const WCHAR iso_8859_5W
[] = {'i','s','o','-','8','8','5','9','-','5',0};
78 static const WCHAR iso_8859_7W
[] = {'i','s','o','-','8','8','5','9','-','7',0};
79 static const WCHAR iso_8859_9W
[] = {'i','s','o','-','8','8','5','9','-','9',0};
80 static const WCHAR iso_8859_13W
[] = {'i','s','o','-','8','8','5','9','-','1','3',0};
81 static const WCHAR iso_8859_15W
[] = {'i','s','o','-','8','8','5','9','-','1','5',0};
82 static const WCHAR utf16W
[] = {'U','T','F','-','1','6',0};
83 static const WCHAR utf8W
[] = {'U','T','F','-','8',0};
85 static const struct xml_encoding_data xml_encoding_map
[] = {
86 { iso_8859_1W
, XmlEncoding_ISO_8859_1
, 28591 },
87 { iso_8859_13W
, XmlEncoding_ISO_8859_13
, 28603 },
88 { iso_8859_15W
, XmlEncoding_ISO_8859_15
, 28605 },
89 { iso_8859_2W
, XmlEncoding_ISO_8859_2
, 28592 },
90 { iso_8859_3W
, XmlEncoding_ISO_8859_3
, 28593 },
91 { iso_8859_4W
, XmlEncoding_ISO_8859_4
, 28594 },
92 { iso_8859_5W
, XmlEncoding_ISO_8859_5
, 28595 },
93 { iso_8859_7W
, XmlEncoding_ISO_8859_7
, 28597 },
94 { iso_8859_9W
, XmlEncoding_ISO_8859_9
, 28599 },
95 { utf16W
, XmlEncoding_UTF16
, ~0 },
96 { utf8W
, XmlEncoding_UTF8
, CP_UTF8
}
101 OutputBuffer_Native
= 0x001,
102 OutputBuffer_Encoded
= 0x010,
103 OutputBuffer_Both
= 0x100
109 MXWriter_DisableEscaping
,
111 MXWriter_OmitXmlDecl
,
125 unsigned int allocated
;
126 unsigned int written
;
131 encoded_buffer utf16
;
132 encoded_buffer encoded
;
139 IMXWriter IMXWriter_iface
;
140 ISAXContentHandler ISAXContentHandler_iface
;
141 ISAXLexicalHandler ISAXLexicalHandler_iface
;
142 ISAXDeclHandler ISAXDeclHandler_iface
;
145 MSXML_VERSION class_version
;
147 VARIANT_BOOL props
[MXWriter_LastProp
];
151 BOOL text
; /* last node was text node, so we shouldn't indent next node */
152 BOOL newline
; /* newline was already added as a part of previous call */
153 UINT indent
; /* indentation level for next node */
157 BSTR encoding
; /* exact property value */
158 xml_encoding xml_enc
;
160 /* contains a pending (or not closed yet) element name or NULL if
161 we don't have to close */
167 output_buffer
*buffer
;
182 IMXAttributes IMXAttributes_iface
;
183 ISAXAttributes ISAXAttributes_iface
;
184 IVBSAXAttributes IVBSAXAttributes_iface
;
187 MSXML_VERSION class_version
;
194 static inline mxattributes
*impl_from_IMXAttributes( IMXAttributes
*iface
)
196 return CONTAINING_RECORD(iface
, mxattributes
, IMXAttributes_iface
);
199 static inline mxattributes
*impl_from_ISAXAttributes( ISAXAttributes
*iface
)
201 return CONTAINING_RECORD(iface
, mxattributes
, ISAXAttributes_iface
);
204 static inline mxattributes
*impl_from_IVBSAXAttributes( IVBSAXAttributes
*iface
)
206 return CONTAINING_RECORD(iface
, mxattributes
, IVBSAXAttributes_iface
);
209 static HRESULT
mxattributes_grow(mxattributes
*This
)
211 if (This
->length
< This
->allocated
) return S_OK
;
213 This
->allocated
*= 2;
214 This
->attr
= heap_realloc(This
->attr
, This
->allocated
*sizeof(mxattribute
));
216 return This
->attr
? S_OK
: E_OUTOFMEMORY
;
219 static xml_encoding
parse_encoding_name(const WCHAR
*encoding
)
224 max
= sizeof(xml_encoding_map
)/sizeof(struct xml_encoding_data
) - 1;
230 c
= strcmpiW(xml_encoding_map
[n
].encoding
, encoding
);
232 return xml_encoding_map
[n
].enc
;
240 return XmlEncoding_Unknown
;
243 static HRESULT
init_encoded_buffer(encoded_buffer
*buffer
)
245 const int initial_len
= 0x2000;
246 buffer
->data
= heap_alloc(initial_len
);
247 if (!buffer
->data
) return E_OUTOFMEMORY
;
249 memset(buffer
->data
, 0, 4);
250 buffer
->allocated
= initial_len
;
256 static void free_encoded_buffer(encoded_buffer
*buffer
)
258 heap_free(buffer
->data
);
261 static HRESULT
get_code_page(xml_encoding encoding
, UINT
*cp
)
263 const struct xml_encoding_data
*data
;
265 if (encoding
== XmlEncoding_Unknown
)
267 FIXME("unsupported encoding %d\n", encoding
);
271 data
= &xml_encoding_map
[encoding
];
277 static HRESULT
alloc_output_buffer(xml_encoding encoding
, output_buffer
**buffer
)
282 ret
= heap_alloc(sizeof(*ret
));
283 if (!ret
) return E_OUTOFMEMORY
;
285 hr
= get_code_page(encoding
, &ret
->code_page
);
291 hr
= init_encoded_buffer(&ret
->utf16
);
297 /* currently we always create a default output buffer that is UTF-16 only,
298 but it's possible to allocate with specific encoding too */
299 if (encoding
!= XmlEncoding_UTF16
) {
300 hr
= init_encoded_buffer(&ret
->encoded
);
302 free_encoded_buffer(&ret
->utf16
);
308 memset(&ret
->encoded
, 0, sizeof(ret
->encoded
));
315 static void free_output_buffer(output_buffer
*buffer
)
317 free_encoded_buffer(&buffer
->encoded
);
318 free_encoded_buffer(&buffer
->utf16
);
322 static void grow_buffer(encoded_buffer
*buffer
, int length
)
324 /* grow if needed, plus 4 bytes to be sure null terminator will fit in */
325 if (buffer
->allocated
< buffer
->written
+ length
+ 4)
327 int grown_size
= max(2*buffer
->allocated
, buffer
->allocated
+ length
);
328 buffer
->data
= heap_realloc(buffer
->data
, grown_size
);
329 buffer
->allocated
= grown_size
;
333 static HRESULT
write_output_buffer_mode(output_buffer
*buffer
, output_mode mode
, const WCHAR
*data
, int len
)
338 if (mode
& (OutputBuffer_Encoded
| OutputBuffer_Both
)) {
339 if (buffer
->code_page
!= ~0)
341 length
= WideCharToMultiByte(buffer
->code_page
, 0, data
, len
, NULL
, 0, NULL
, NULL
);
342 grow_buffer(&buffer
->encoded
, length
);
343 ptr
= buffer
->encoded
.data
+ buffer
->encoded
.written
;
344 length
= WideCharToMultiByte(buffer
->code_page
, 0, data
, len
, ptr
, length
, NULL
, NULL
);
345 buffer
->encoded
.written
+= len
== -1 ? length
-1 : length
;
349 if (mode
& (OutputBuffer_Native
| OutputBuffer_Both
)) {
350 /* WCHAR data just copied */
351 length
= len
== -1 ? strlenW(data
) : len
;
354 length
*= sizeof(WCHAR
);
356 grow_buffer(&buffer
->utf16
, length
);
357 ptr
= buffer
->utf16
.data
+ buffer
->utf16
.written
;
359 memcpy(ptr
, data
, length
);
360 buffer
->utf16
.written
+= length
;
362 /* null termination */
363 memset(ptr
, 0, sizeof(WCHAR
));
370 static HRESULT
write_output_buffer(output_buffer
*buffer
, const WCHAR
*data
, int len
)
372 return write_output_buffer_mode(buffer
, OutputBuffer_Both
, data
, len
);
375 static HRESULT
write_output_buffer_quoted(output_buffer
*buffer
, const WCHAR
*data
, int len
)
377 write_output_buffer(buffer
, quotW
, 1);
378 write_output_buffer(buffer
, data
, len
);
379 write_output_buffer(buffer
, quotW
, 1);
384 /* frees buffer data, reallocates with a default lengths */
385 static void close_output_buffer(mxwriter
*This
)
387 heap_free(This
->buffer
->utf16
.data
);
388 heap_free(This
->buffer
->encoded
.data
);
389 init_encoded_buffer(&This
->buffer
->utf16
);
390 init_encoded_buffer(&This
->buffer
->encoded
);
391 get_code_page(This
->xml_enc
, &This
->buffer
->code_page
);
394 /* escapes special characters like:
400 static WCHAR
*get_escaped_string(const WCHAR
*str
, escape_mode mode
, int *len
)
402 static const WCHAR ltW
[] = {'&','l','t',';'};
403 static const WCHAR ampW
[] = {'&','a','m','p',';'};
404 static const WCHAR equotW
[] = {'&','q','u','o','t',';'};
405 static const WCHAR gtW
[] = {'&','g','t',';'};
407 const int default_alloc
= 100;
408 const int grow_thresh
= 10;
409 int p
= *len
, conv_len
;
412 /* default buffer size to something if length is unknown */
413 conv_len
= *len
== -1 ? default_alloc
: max(2**len
, default_alloc
);
414 ptr
= ret
= heap_alloc(conv_len
*sizeof(WCHAR
));
418 if (ptr
- ret
> conv_len
- grow_thresh
)
420 int written
= ptr
- ret
;
422 ptr
= ret
= heap_realloc(ret
, conv_len
*sizeof(WCHAR
));
429 memcpy(ptr
, ltW
, sizeof(ltW
));
430 ptr
+= sizeof(ltW
)/sizeof(WCHAR
);
433 memcpy(ptr
, ampW
, sizeof(ampW
));
434 ptr
+= sizeof(ampW
)/sizeof(WCHAR
);
437 memcpy(ptr
, gtW
, sizeof(gtW
));
438 ptr
+= sizeof(gtW
)/sizeof(WCHAR
);
441 if (mode
== EscapeValue
)
443 memcpy(ptr
, equotW
, sizeof(equotW
));
444 ptr
+= sizeof(equotW
)/sizeof(WCHAR
);
447 /* fallthrough for text mode */
457 if (*len
!= -1) *len
= ptr
-ret
;
463 static void write_prolog_buffer(mxwriter
*This
)
465 static const WCHAR versionW
[] = {'<','?','x','m','l',' ','v','e','r','s','i','o','n','='};
466 static const WCHAR encodingW
[] = {' ','e','n','c','o','d','i','n','g','=','\"'};
467 static const WCHAR standaloneW
[] = {' ','s','t','a','n','d','a','l','o','n','e','=','\"'};
468 static const WCHAR yesW
[] = {'y','e','s','\"','?','>'};
469 static const WCHAR noW
[] = {'n','o','\"','?','>'};
472 write_output_buffer(This
->buffer
, versionW
, sizeof(versionW
)/sizeof(WCHAR
));
473 write_output_buffer_quoted(This
->buffer
, This
->version
, -1);
476 write_output_buffer(This
->buffer
, encodingW
, sizeof(encodingW
)/sizeof(WCHAR
));
478 /* always write UTF-16 to WCHAR buffer */
479 write_output_buffer_mode(This
->buffer
, OutputBuffer_Native
, utf16W
, sizeof(utf16W
)/sizeof(WCHAR
) - 1);
480 write_output_buffer_mode(This
->buffer
, OutputBuffer_Encoded
, This
->encoding
, -1);
481 write_output_buffer(This
->buffer
, quotW
, 1);
484 write_output_buffer(This
->buffer
, standaloneW
, sizeof(standaloneW
)/sizeof(WCHAR
));
485 if (This
->props
[MXWriter_Standalone
] == VARIANT_TRUE
)
486 write_output_buffer(This
->buffer
, yesW
, sizeof(yesW
)/sizeof(WCHAR
));
488 write_output_buffer(This
->buffer
, noW
, sizeof(noW
)/sizeof(WCHAR
));
490 write_output_buffer(This
->buffer
, crlfW
, sizeof(crlfW
)/sizeof(WCHAR
));
491 This
->newline
= TRUE
;
494 /* Attempts to the write data from the mxwriter's buffer to
495 * the destination stream (if there is one).
497 static HRESULT
write_data_to_stream(mxwriter
*This
)
499 encoded_buffer
*buffer
;
506 if (This
->xml_enc
!= XmlEncoding_UTF16
)
507 buffer
= &This
->buffer
->encoded
;
509 buffer
= &This
->buffer
->utf16
;
511 if (This
->dest_written
> buffer
->written
) {
512 ERR("Failed sanity check! Not sure what to do... (%d > %d)\n", This
->dest_written
, buffer
->written
);
514 } else if (This
->dest_written
== buffer
->written
&& This
->xml_enc
!= XmlEncoding_UTF8
)
515 /* Windows seems to make an empty write call when the encoding is UTF-8 and
516 * all the data has been written to the stream. It doesn't seem make this call
517 * for any other encodings.
521 /* Write the current content from the output buffer into 'dest'.
522 * TODO: Check what Windows does if the IStream doesn't write all of
523 * the data we give it at once.
525 hr
= IStream_Write(This
->dest
, buffer
->data
+This
->dest_written
,
526 buffer
->written
-This
->dest_written
, &written
);
528 WARN("Failed to write data to IStream (0x%08x)\n", hr
);
532 This
->dest_written
+= written
;
536 /* Newly added element start tag left unclosed cause for empty elements
537 we have to close it differently. */
538 static void close_element_starttag(const mxwriter
*This
)
540 static const WCHAR gtW
[] = {'>'};
541 if (!This
->element
) return;
542 write_output_buffer(This
->buffer
, gtW
, 1);
545 static void write_node_indent(mxwriter
*This
)
547 static const WCHAR tabW
[] = {'\t'};
548 int indent
= This
->indent
;
550 if (!This
->props
[MXWriter_Indent
] || This
->text
)
556 /* This is to workaround PI output logic that always puts newline chars,
557 document prolog PI does that too. */
559 write_output_buffer(This
->buffer
, crlfW
, sizeof(crlfW
)/sizeof(WCHAR
));
561 write_output_buffer(This
->buffer
, tabW
, 1);
563 This
->newline
= FALSE
;
567 static inline void writer_inc_indent(mxwriter
*This
)
572 static inline void writer_dec_indent(mxwriter
*This
)
574 if (This
->indent
) This
->indent
--;
575 /* depth is decreased only when element is closed, meaning it's not a text node
580 static void set_element_name(mxwriter
*This
, const WCHAR
*name
, int len
)
582 SysFreeString(This
->element
);
584 This
->element
= len
!= -1 ? SysAllocStringLen(name
, len
) : SysAllocString(name
);
586 This
->element
= NULL
;
589 static inline HRESULT
flush_output_buffer(mxwriter
*This
)
591 close_element_starttag(This
);
592 set_element_name(This
, NULL
, 0);
594 return write_data_to_stream(This
);
597 /* Resets the mxwriter's output buffer by closing it, then creating a new
598 * output buffer using the given encoding.
600 static inline void reset_output_buffer(mxwriter
*This
)
602 close_output_buffer(This
);
603 This
->dest_written
= 0;
606 static HRESULT
writer_set_property(mxwriter
*writer
, mxwriter_prop property
, VARIANT_BOOL value
)
608 writer
->props
[property
] = value
;
609 writer
->prop_changed
= TRUE
;
613 static HRESULT
writer_get_property(const mxwriter
*writer
, mxwriter_prop property
, VARIANT_BOOL
*value
)
615 if (!value
) return E_POINTER
;
616 *value
= writer
->props
[property
];
620 static inline mxwriter
*impl_from_IMXWriter(IMXWriter
*iface
)
622 return CONTAINING_RECORD(iface
, mxwriter
, IMXWriter_iface
);
625 static inline mxwriter
*impl_from_ISAXContentHandler(ISAXContentHandler
*iface
)
627 return CONTAINING_RECORD(iface
, mxwriter
, ISAXContentHandler_iface
);
630 static inline mxwriter
*impl_from_ISAXLexicalHandler(ISAXLexicalHandler
*iface
)
632 return CONTAINING_RECORD(iface
, mxwriter
, ISAXLexicalHandler_iface
);
635 static inline mxwriter
*impl_from_ISAXDeclHandler(ISAXDeclHandler
*iface
)
637 return CONTAINING_RECORD(iface
, mxwriter
, ISAXDeclHandler_iface
);
640 static HRESULT WINAPI
mxwriter_QueryInterface(IMXWriter
*iface
, REFIID riid
, void **obj
)
642 mxwriter
*This
= impl_from_IMXWriter( iface
);
644 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), obj
);
648 if ( IsEqualGUID( riid
, &IID_IMXWriter
) ||
649 IsEqualGUID( riid
, &IID_IDispatch
) ||
650 IsEqualGUID( riid
, &IID_IUnknown
) )
652 *obj
= &This
->IMXWriter_iface
;
654 else if ( IsEqualGUID( riid
, &IID_ISAXContentHandler
) )
656 *obj
= &This
->ISAXContentHandler_iface
;
658 else if ( IsEqualGUID( riid
, &IID_ISAXLexicalHandler
) )
660 *obj
= &This
->ISAXLexicalHandler_iface
;
662 else if ( IsEqualGUID( riid
, &IID_ISAXDeclHandler
) )
664 *obj
= &This
->ISAXDeclHandler_iface
;
666 else if (dispex_query_interface(&This
->dispex
, riid
, obj
))
668 return *obj
? S_OK
: E_NOINTERFACE
;
672 ERR("interface %s not implemented\n", debugstr_guid(riid
));
674 return E_NOINTERFACE
;
677 IMXWriter_AddRef(iface
);
681 static ULONG WINAPI
mxwriter_AddRef(IMXWriter
*iface
)
683 mxwriter
*This
= impl_from_IMXWriter( iface
);
684 LONG ref
= InterlockedIncrement(&This
->ref
);
686 TRACE("(%p)->(%d)\n", This
, ref
);
691 static ULONG WINAPI
mxwriter_Release(IMXWriter
*iface
)
693 mxwriter
*This
= impl_from_IMXWriter( iface
);
694 ULONG ref
= InterlockedDecrement(&This
->ref
);
696 TRACE("(%p)->(%d)\n", This
, ref
);
700 /* Windows flushes the buffer when the interface is destroyed. */
701 flush_output_buffer(This
);
702 free_output_buffer(This
->buffer
);
704 if (This
->dest
) IStream_Release(This
->dest
);
705 SysFreeString(This
->version
);
706 SysFreeString(This
->encoding
);
708 SysFreeString(This
->element
);
709 release_dispex(&This
->dispex
);
716 static HRESULT WINAPI
mxwriter_GetTypeInfoCount(IMXWriter
*iface
, UINT
* pctinfo
)
718 mxwriter
*This
= impl_from_IMXWriter( iface
);
719 return IDispatchEx_GetTypeInfoCount(&This
->dispex
.IDispatchEx_iface
, pctinfo
);
722 static HRESULT WINAPI
mxwriter_GetTypeInfo(
724 UINT iTInfo
, LCID lcid
,
725 ITypeInfo
** ppTInfo
)
727 mxwriter
*This
= impl_from_IMXWriter( iface
);
728 return IDispatchEx_GetTypeInfo(&This
->dispex
.IDispatchEx_iface
,
729 iTInfo
, lcid
, ppTInfo
);
732 static HRESULT WINAPI
mxwriter_GetIDsOfNames(
734 REFIID riid
, LPOLESTR
* rgszNames
,
735 UINT cNames
, LCID lcid
, DISPID
* rgDispId
)
737 mxwriter
*This
= impl_from_IMXWriter( iface
);
738 return IDispatchEx_GetIDsOfNames(&This
->dispex
.IDispatchEx_iface
,
739 riid
, rgszNames
, cNames
, lcid
, rgDispId
);
742 static HRESULT WINAPI
mxwriter_Invoke(
744 DISPID dispIdMember
, REFIID riid
, LCID lcid
,
745 WORD wFlags
, DISPPARAMS
* pDispParams
, VARIANT
* pVarResult
,
746 EXCEPINFO
* pExcepInfo
, UINT
* puArgErr
)
748 mxwriter
*This
= impl_from_IMXWriter( iface
);
749 return IDispatchEx_Invoke(&This
->dispex
.IDispatchEx_iface
,
750 dispIdMember
, riid
, lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
753 static HRESULT WINAPI
mxwriter_put_output(IMXWriter
*iface
, VARIANT dest
)
755 mxwriter
*This
= impl_from_IMXWriter( iface
);
758 TRACE("(%p)->(%s)\n", This
, debugstr_variant(&dest
));
760 hr
= flush_output_buffer(This
);
768 if (This
->dest
) IStream_Release(This
->dest
);
770 reset_output_buffer(This
);
777 hr
= IUnknown_QueryInterface(V_UNKNOWN(&dest
), &IID_IStream
, (void**)&stream
);
780 /* Recreate the output buffer to make sure it's using the correct encoding. */
781 reset_output_buffer(This
);
783 if (This
->dest
) IStream_Release(This
->dest
);
788 FIXME("unhandled interface type for VT_UNKNOWN destination\n");
792 FIXME("unhandled destination type %s\n", debugstr_variant(&dest
));
799 static HRESULT WINAPI
mxwriter_get_output(IMXWriter
*iface
, VARIANT
*dest
)
801 mxwriter
*This
= impl_from_IMXWriter( iface
);
803 TRACE("(%p)->(%p)\n", This
, dest
);
805 if (!dest
) return E_POINTER
;
809 HRESULT hr
= flush_output_buffer(This
);
813 V_VT(dest
) = VT_BSTR
;
814 V_BSTR(dest
) = SysAllocString((WCHAR
*)This
->buffer
->utf16
.data
);
819 /* we only support IStream output so far */
820 V_VT(dest
) = VT_UNKNOWN
;
821 V_UNKNOWN(dest
) = (IUnknown
*)This
->dest
;
822 IStream_AddRef(This
->dest
);
827 static HRESULT WINAPI
mxwriter_put_encoding(IMXWriter
*iface
, BSTR encoding
)
829 mxwriter
*This
= impl_from_IMXWriter( iface
);
833 TRACE("(%p)->(%s)\n", This
, debugstr_w(encoding
));
835 enc
= parse_encoding_name(encoding
);
836 if (enc
== XmlEncoding_Unknown
)
838 FIXME("unsupported encoding %s\n", debugstr_w(encoding
));
842 hr
= flush_output_buffer(This
);
846 SysReAllocString(&This
->encoding
, encoding
);
849 TRACE("got encoding %d\n", This
->xml_enc
);
850 reset_output_buffer(This
);
854 static HRESULT WINAPI
mxwriter_get_encoding(IMXWriter
*iface
, BSTR
*encoding
)
856 mxwriter
*This
= impl_from_IMXWriter( iface
);
858 TRACE("(%p)->(%p)\n", This
, encoding
);
860 if (!encoding
) return E_POINTER
;
862 *encoding
= SysAllocString(This
->encoding
);
863 if (!*encoding
) return E_OUTOFMEMORY
;
868 static HRESULT WINAPI
mxwriter_put_byteOrderMark(IMXWriter
*iface
, VARIANT_BOOL value
)
870 mxwriter
*This
= impl_from_IMXWriter( iface
);
872 TRACE("(%p)->(%d)\n", This
, value
);
873 return writer_set_property(This
, MXWriter_BOM
, value
);
876 static HRESULT WINAPI
mxwriter_get_byteOrderMark(IMXWriter
*iface
, VARIANT_BOOL
*value
)
878 mxwriter
*This
= impl_from_IMXWriter( iface
);
880 TRACE("(%p)->(%p)\n", This
, value
);
881 return writer_get_property(This
, MXWriter_BOM
, value
);
884 static HRESULT WINAPI
mxwriter_put_indent(IMXWriter
*iface
, VARIANT_BOOL value
)
886 mxwriter
*This
= impl_from_IMXWriter( iface
);
888 TRACE("(%p)->(%d)\n", This
, value
);
889 return writer_set_property(This
, MXWriter_Indent
, value
);
892 static HRESULT WINAPI
mxwriter_get_indent(IMXWriter
*iface
, VARIANT_BOOL
*value
)
894 mxwriter
*This
= impl_from_IMXWriter( iface
);
896 TRACE("(%p)->(%p)\n", This
, value
);
897 return writer_get_property(This
, MXWriter_Indent
, value
);
900 static HRESULT WINAPI
mxwriter_put_standalone(IMXWriter
*iface
, VARIANT_BOOL value
)
902 mxwriter
*This
= impl_from_IMXWriter( iface
);
904 TRACE("(%p)->(%d)\n", This
, value
);
905 return writer_set_property(This
, MXWriter_Standalone
, value
);
908 static HRESULT WINAPI
mxwriter_get_standalone(IMXWriter
*iface
, VARIANT_BOOL
*value
)
910 mxwriter
*This
= impl_from_IMXWriter( iface
);
912 TRACE("(%p)->(%p)\n", This
, value
);
913 return writer_get_property(This
, MXWriter_Standalone
, value
);
916 static HRESULT WINAPI
mxwriter_put_omitXMLDeclaration(IMXWriter
*iface
, VARIANT_BOOL value
)
918 mxwriter
*This
= impl_from_IMXWriter( iface
);
920 TRACE("(%p)->(%d)\n", This
, value
);
921 return writer_set_property(This
, MXWriter_OmitXmlDecl
, value
);
924 static HRESULT WINAPI
mxwriter_get_omitXMLDeclaration(IMXWriter
*iface
, VARIANT_BOOL
*value
)
926 mxwriter
*This
= impl_from_IMXWriter( iface
);
928 TRACE("(%p)->(%p)\n", This
, value
);
929 return writer_get_property(This
, MXWriter_OmitXmlDecl
, value
);
932 static HRESULT WINAPI
mxwriter_put_version(IMXWriter
*iface
, BSTR version
)
934 mxwriter
*This
= impl_from_IMXWriter( iface
);
936 TRACE("(%p)->(%s)\n", This
, debugstr_w(version
));
938 if (!version
) return E_INVALIDARG
;
940 SysFreeString(This
->version
);
941 This
->version
= SysAllocString(version
);
946 static HRESULT WINAPI
mxwriter_get_version(IMXWriter
*iface
, BSTR
*version
)
948 mxwriter
*This
= impl_from_IMXWriter( iface
);
950 TRACE("(%p)->(%p)\n", This
, version
);
952 if (!version
) return E_POINTER
;
954 return return_bstr(This
->version
, version
);
957 static HRESULT WINAPI
mxwriter_put_disableOutputEscaping(IMXWriter
*iface
, VARIANT_BOOL value
)
959 mxwriter
*This
= impl_from_IMXWriter( iface
);
961 TRACE("(%p)->(%d)\n", This
, value
);
962 return writer_set_property(This
, MXWriter_DisableEscaping
, value
);
965 static HRESULT WINAPI
mxwriter_get_disableOutputEscaping(IMXWriter
*iface
, VARIANT_BOOL
*value
)
967 mxwriter
*This
= impl_from_IMXWriter( iface
);
969 TRACE("(%p)->(%p)\n", This
, value
);
970 return writer_get_property(This
, MXWriter_DisableEscaping
, value
);
973 static HRESULT WINAPI
mxwriter_flush(IMXWriter
*iface
)
975 mxwriter
*This
= impl_from_IMXWriter( iface
);
976 TRACE("(%p)\n", This
);
977 return flush_output_buffer(This
);
980 static const struct IMXWriterVtbl MXWriterVtbl
=
982 mxwriter_QueryInterface
,
985 mxwriter_GetTypeInfoCount
,
986 mxwriter_GetTypeInfo
,
987 mxwriter_GetIDsOfNames
,
991 mxwriter_put_encoding
,
992 mxwriter_get_encoding
,
993 mxwriter_put_byteOrderMark
,
994 mxwriter_get_byteOrderMark
,
997 mxwriter_put_standalone
,
998 mxwriter_get_standalone
,
999 mxwriter_put_omitXMLDeclaration
,
1000 mxwriter_get_omitXMLDeclaration
,
1001 mxwriter_put_version
,
1002 mxwriter_get_version
,
1003 mxwriter_put_disableOutputEscaping
,
1004 mxwriter_get_disableOutputEscaping
,
1008 /*** ISAXContentHandler ***/
1009 static HRESULT WINAPI
SAXContentHandler_QueryInterface(
1010 ISAXContentHandler
*iface
,
1014 mxwriter
*This
= impl_from_ISAXContentHandler( iface
);
1015 return IMXWriter_QueryInterface(&This
->IMXWriter_iface
, riid
, obj
);
1018 static ULONG WINAPI
SAXContentHandler_AddRef(ISAXContentHandler
*iface
)
1020 mxwriter
*This
= impl_from_ISAXContentHandler( iface
);
1021 return IMXWriter_AddRef(&This
->IMXWriter_iface
);
1024 static ULONG WINAPI
SAXContentHandler_Release(ISAXContentHandler
*iface
)
1026 mxwriter
*This
= impl_from_ISAXContentHandler( iface
);
1027 return IMXWriter_Release(&This
->IMXWriter_iface
);
1030 static HRESULT WINAPI
SAXContentHandler_putDocumentLocator(
1031 ISAXContentHandler
*iface
,
1032 ISAXLocator
*locator
)
1034 mxwriter
*This
= impl_from_ISAXContentHandler( iface
);
1035 FIXME("(%p)->(%p)\n", This
, locator
);
1039 static HRESULT WINAPI
SAXContentHandler_startDocument(ISAXContentHandler
*iface
)
1041 mxwriter
*This
= impl_from_ISAXContentHandler( iface
);
1043 TRACE("(%p)\n", This
);
1045 /* If properties have been changed since the last "endDocument" call
1046 * we need to reset the output buffer. If we don't the output buffer
1047 * could end up with multiple XML documents in it, plus this seems to
1048 * be how Windows works.
1050 if (This
->prop_changed
) {
1051 reset_output_buffer(This
);
1052 This
->prop_changed
= FALSE
;
1055 if (This
->props
[MXWriter_OmitXmlDecl
] == VARIANT_TRUE
) return S_OK
;
1057 write_prolog_buffer(This
);
1059 if (This
->dest
&& This
->xml_enc
== XmlEncoding_UTF16
) {
1060 static const char utf16BOM
[] = {0xff,0xfe};
1062 if (This
->props
[MXWriter_BOM
] == VARIANT_TRUE
)
1063 /* Windows passes a NULL pointer as the pcbWritten parameter and
1064 * ignores any error codes returned from this Write call.
1066 IStream_Write(This
->dest
, utf16BOM
, sizeof(utf16BOM
), NULL
);
1072 static HRESULT WINAPI
SAXContentHandler_endDocument(ISAXContentHandler
*iface
)
1074 mxwriter
*This
= impl_from_ISAXContentHandler( iface
);
1075 TRACE("(%p)\n", This
);
1076 This
->prop_changed
= FALSE
;
1077 return flush_output_buffer(This
);
1080 static HRESULT WINAPI
SAXContentHandler_startPrefixMapping(
1081 ISAXContentHandler
*iface
,
1082 const WCHAR
*prefix
,
1087 mxwriter
*This
= impl_from_ISAXContentHandler( iface
);
1088 FIXME("(%p)->(%s %s)\n", This
, debugstr_wn(prefix
, nprefix
), debugstr_wn(uri
, nuri
));
1092 static HRESULT WINAPI
SAXContentHandler_endPrefixMapping(
1093 ISAXContentHandler
*iface
,
1094 const WCHAR
*prefix
,
1097 mxwriter
*This
= impl_from_ISAXContentHandler( iface
);
1098 FIXME("(%p)->(%s)\n", This
, debugstr_wn(prefix
, nprefix
));
1102 static HRESULT WINAPI
SAXContentHandler_startElement(
1103 ISAXContentHandler
*iface
,
1104 const WCHAR
*namespaceUri
,
1106 const WCHAR
*local_name
,
1110 ISAXAttributes
*attr
)
1112 mxwriter
*This
= impl_from_ISAXContentHandler( iface
);
1113 static const WCHAR ltW
[] = {'<'};
1115 TRACE("(%p)->(%s %s %s %p)\n", This
, debugstr_wn(namespaceUri
, nnamespaceUri
),
1116 debugstr_wn(local_name
, nlocal_name
), debugstr_wn(QName
, nQName
), attr
);
1118 if (((!namespaceUri
|| !local_name
|| !QName
) && This
->class_version
!= MSXML6
) ||
1119 (nQName
== -1 && This
->class_version
== MSXML6
))
1120 return E_INVALIDARG
;
1122 close_element_starttag(This
);
1123 set_element_name(This
, QName
? QName
: emptyW
,
1124 QName
? nQName
: 0);
1126 write_node_indent(This
);
1128 write_output_buffer(This
->buffer
, ltW
, 1);
1129 write_output_buffer(This
->buffer
, QName
, nQName
);
1130 writer_inc_indent(This
);
1134 int length
, i
, escape
;
1137 hr
= ISAXAttributes_getLength(attr
, &length
);
1138 if (FAILED(hr
)) return hr
;
1140 escape
= This
->props
[MXWriter_DisableEscaping
] == VARIANT_FALSE
||
1141 (This
->class_version
== MSXML4
|| This
->class_version
== MSXML6
);
1143 for (i
= 0; i
< length
; i
++)
1145 static const WCHAR eqW
[] = {'='};
1149 hr
= ISAXAttributes_getQName(attr
, i
, &str
, &len
);
1150 if (FAILED(hr
)) return hr
;
1152 /* space separator in front of every attribute */
1153 write_output_buffer(This
->buffer
, spaceW
, 1);
1154 write_output_buffer(This
->buffer
, str
, len
);
1156 write_output_buffer(This
->buffer
, eqW
, 1);
1159 hr
= ISAXAttributes_getValue(attr
, i
, &str
, &len
);
1160 if (FAILED(hr
)) return hr
;
1164 WCHAR
*escaped
= get_escaped_string(str
, EscapeValue
, &len
);
1165 write_output_buffer_quoted(This
->buffer
, escaped
, len
);
1169 write_output_buffer_quoted(This
->buffer
, str
, len
);
1176 static HRESULT WINAPI
SAXContentHandler_endElement(
1177 ISAXContentHandler
*iface
,
1178 const WCHAR
*namespaceUri
,
1180 const WCHAR
* local_name
,
1185 mxwriter
*This
= impl_from_ISAXContentHandler( iface
);
1187 TRACE("(%p)->(%s:%d %s:%d %s:%d)\n", This
, debugstr_wn(namespaceUri
, nnamespaceUri
), nnamespaceUri
,
1188 debugstr_wn(local_name
, nlocal_name
), nlocal_name
, debugstr_wn(QName
, nQName
), nQName
);
1190 if (((!namespaceUri
|| !local_name
|| !QName
) && This
->class_version
!= MSXML6
) ||
1191 (nQName
== -1 && This
->class_version
== MSXML6
))
1192 return E_INVALIDARG
;
1194 writer_dec_indent(This
);
1198 static const WCHAR closeW
[] = {'/','>'};
1199 write_output_buffer(This
->buffer
, closeW
, 2);
1203 static const WCHAR closetagW
[] = {'<','/'};
1204 static const WCHAR gtW
[] = {'>'};
1206 write_node_indent(This
);
1207 write_output_buffer(This
->buffer
, closetagW
, 2);
1208 write_output_buffer(This
->buffer
, QName
, nQName
);
1209 write_output_buffer(This
->buffer
, gtW
, 1);
1212 set_element_name(This
, NULL
, 0);
1217 static HRESULT WINAPI
SAXContentHandler_characters(
1218 ISAXContentHandler
*iface
,
1222 mxwriter
*This
= impl_from_ISAXContentHandler( iface
);
1224 TRACE("(%p)->(%s:%d)\n", This
, debugstr_wn(chars
, nchars
), nchars
);
1226 if (!chars
) return E_INVALIDARG
;
1228 close_element_starttag(This
);
1229 set_element_name(This
, NULL
, 0);
1236 if (This
->cdata
|| This
->props
[MXWriter_DisableEscaping
] == VARIANT_TRUE
)
1237 write_output_buffer(This
->buffer
, chars
, nchars
);
1243 escaped
= get_escaped_string(chars
, EscapeText
, &len
);
1244 write_output_buffer(This
->buffer
, escaped
, len
);
1252 static HRESULT WINAPI
SAXContentHandler_ignorableWhitespace(
1253 ISAXContentHandler
*iface
,
1257 mxwriter
*This
= impl_from_ISAXContentHandler( iface
);
1259 TRACE("(%p)->(%s)\n", This
, debugstr_wn(chars
, nchars
));
1261 if (!chars
) return E_INVALIDARG
;
1263 write_output_buffer(This
->buffer
, chars
, nchars
);
1268 static HRESULT WINAPI
SAXContentHandler_processingInstruction(
1269 ISAXContentHandler
*iface
,
1270 const WCHAR
*target
,
1275 mxwriter
*This
= impl_from_ISAXContentHandler( iface
);
1276 static const WCHAR openpiW
[] = {'<','?'};
1277 static const WCHAR closepiW
[] = {'?','>','\r','\n'};
1279 TRACE("(%p)->(%s %s)\n", This
, debugstr_wn(target
, ntarget
), debugstr_wn(data
, ndata
));
1281 if (!target
) return E_INVALIDARG
;
1283 write_node_indent(This
);
1284 write_output_buffer(This
->buffer
, openpiW
, sizeof(openpiW
)/sizeof(WCHAR
));
1287 write_output_buffer(This
->buffer
, target
, ntarget
);
1289 if (data
&& *data
&& ndata
)
1291 write_output_buffer(This
->buffer
, spaceW
, 1);
1292 write_output_buffer(This
->buffer
, data
, ndata
);
1295 write_output_buffer(This
->buffer
, closepiW
, sizeof(closepiW
)/sizeof(WCHAR
));
1296 This
->newline
= TRUE
;
1301 static HRESULT WINAPI
SAXContentHandler_skippedEntity(
1302 ISAXContentHandler
*iface
,
1306 mxwriter
*This
= impl_from_ISAXContentHandler( iface
);
1307 FIXME("(%p)->(%s)\n", This
, debugstr_wn(name
, nname
));
1311 static const struct ISAXContentHandlerVtbl SAXContentHandlerVtbl
=
1313 SAXContentHandler_QueryInterface
,
1314 SAXContentHandler_AddRef
,
1315 SAXContentHandler_Release
,
1316 SAXContentHandler_putDocumentLocator
,
1317 SAXContentHandler_startDocument
,
1318 SAXContentHandler_endDocument
,
1319 SAXContentHandler_startPrefixMapping
,
1320 SAXContentHandler_endPrefixMapping
,
1321 SAXContentHandler_startElement
,
1322 SAXContentHandler_endElement
,
1323 SAXContentHandler_characters
,
1324 SAXContentHandler_ignorableWhitespace
,
1325 SAXContentHandler_processingInstruction
,
1326 SAXContentHandler_skippedEntity
1329 /*** ISAXLexicalHandler ***/
1330 static HRESULT WINAPI
SAXLexicalHandler_QueryInterface(ISAXLexicalHandler
*iface
,
1331 REFIID riid
, void **obj
)
1333 mxwriter
*This
= impl_from_ISAXLexicalHandler( iface
);
1334 return IMXWriter_QueryInterface(&This
->IMXWriter_iface
, riid
, obj
);
1337 static ULONG WINAPI
SAXLexicalHandler_AddRef(ISAXLexicalHandler
*iface
)
1339 mxwriter
*This
= impl_from_ISAXLexicalHandler( iface
);
1340 return IMXWriter_AddRef(&This
->IMXWriter_iface
);
1343 static ULONG WINAPI
SAXLexicalHandler_Release(ISAXLexicalHandler
*iface
)
1345 mxwriter
*This
= impl_from_ISAXLexicalHandler( iface
);
1346 return IMXWriter_Release(&This
->IMXWriter_iface
);
1349 static HRESULT WINAPI
SAXLexicalHandler_startDTD(ISAXLexicalHandler
*iface
,
1350 const WCHAR
*name
, int name_len
, const WCHAR
*publicId
, int publicId_len
,
1351 const WCHAR
*systemId
, int systemId_len
)
1353 static const WCHAR doctypeW
[] = {'<','!','D','O','C','T','Y','P','E',' '};
1354 static const WCHAR openintW
[] = {'[','\r','\n'};
1356 mxwriter
*This
= impl_from_ISAXLexicalHandler( iface
);
1358 TRACE("(%p)->(%s %s %s)\n", This
, debugstr_wn(name
, name_len
), debugstr_wn(publicId
, publicId_len
),
1359 debugstr_wn(systemId
, systemId_len
));
1361 if (!name
) return E_INVALIDARG
;
1363 write_output_buffer(This
->buffer
, doctypeW
, sizeof(doctypeW
)/sizeof(WCHAR
));
1367 write_output_buffer(This
->buffer
, name
, name_len
);
1368 write_output_buffer(This
->buffer
, spaceW
, 1);
1373 static const WCHAR publicW
[] = {'P','U','B','L','I','C',' '};
1375 write_output_buffer(This
->buffer
, publicW
, sizeof(publicW
)/sizeof(WCHAR
));
1376 write_output_buffer_quoted(This
->buffer
, publicId
, publicId_len
);
1378 if (!systemId
) return E_INVALIDARG
;
1381 write_output_buffer(This
->buffer
, spaceW
, 1);
1383 write_output_buffer_quoted(This
->buffer
, systemId
, systemId_len
);
1386 write_output_buffer(This
->buffer
, spaceW
, 1);
1390 static const WCHAR systemW
[] = {'S','Y','S','T','E','M',' '};
1392 write_output_buffer(This
->buffer
, systemW
, sizeof(systemW
)/sizeof(WCHAR
));
1393 write_output_buffer_quoted(This
->buffer
, systemId
, systemId_len
);
1395 write_output_buffer(This
->buffer
, spaceW
, 1);
1398 write_output_buffer(This
->buffer
, openintW
, sizeof(openintW
)/sizeof(WCHAR
));
1403 static HRESULT WINAPI
SAXLexicalHandler_endDTD(ISAXLexicalHandler
*iface
)
1405 mxwriter
*This
= impl_from_ISAXLexicalHandler( iface
);
1406 static const WCHAR closedtdW
[] = {']','>','\r','\n'};
1408 TRACE("(%p)\n", This
);
1410 write_output_buffer(This
->buffer
, closedtdW
, sizeof(closedtdW
)/sizeof(WCHAR
));
1415 static HRESULT WINAPI
SAXLexicalHandler_startEntity(ISAXLexicalHandler
*iface
, const WCHAR
*name
, int len
)
1417 mxwriter
*This
= impl_from_ISAXLexicalHandler( iface
);
1418 FIXME("(%p)->(%s): stub\n", This
, debugstr_wn(name
, len
));
1422 static HRESULT WINAPI
SAXLexicalHandler_endEntity(ISAXLexicalHandler
*iface
, const WCHAR
*name
, int len
)
1424 mxwriter
*This
= impl_from_ISAXLexicalHandler( iface
);
1425 FIXME("(%p)->(%s): stub\n", This
, debugstr_wn(name
, len
));
1429 static HRESULT WINAPI
SAXLexicalHandler_startCDATA(ISAXLexicalHandler
*iface
)
1431 static const WCHAR scdataW
[] = {'<','!','[','C','D','A','T','A','['};
1432 mxwriter
*This
= impl_from_ISAXLexicalHandler( iface
);
1434 TRACE("(%p)\n", This
);
1436 write_node_indent(This
);
1437 write_output_buffer(This
->buffer
, scdataW
, sizeof(scdataW
)/sizeof(WCHAR
));
1443 static HRESULT WINAPI
SAXLexicalHandler_endCDATA(ISAXLexicalHandler
*iface
)
1445 mxwriter
*This
= impl_from_ISAXLexicalHandler( iface
);
1446 static const WCHAR ecdataW
[] = {']',']','>'};
1448 TRACE("(%p)\n", This
);
1450 write_output_buffer(This
->buffer
, ecdataW
, sizeof(ecdataW
)/sizeof(WCHAR
));
1451 This
->cdata
= FALSE
;
1456 static HRESULT WINAPI
SAXLexicalHandler_comment(ISAXLexicalHandler
*iface
, const WCHAR
*chars
, int nchars
)
1458 mxwriter
*This
= impl_from_ISAXLexicalHandler( iface
);
1459 static const WCHAR copenW
[] = {'<','!','-','-'};
1460 static const WCHAR ccloseW
[] = {'-','-','>','\r','\n'};
1462 TRACE("(%p)->(%s:%d)\n", This
, debugstr_wn(chars
, nchars
), nchars
);
1464 if (!chars
) return E_INVALIDARG
;
1466 close_element_starttag(This
);
1467 write_node_indent(This
);
1469 write_output_buffer(This
->buffer
, copenW
, sizeof(copenW
)/sizeof(WCHAR
));
1471 write_output_buffer(This
->buffer
, chars
, nchars
);
1472 write_output_buffer(This
->buffer
, ccloseW
, sizeof(ccloseW
)/sizeof(WCHAR
));
1477 static const struct ISAXLexicalHandlerVtbl SAXLexicalHandlerVtbl
=
1479 SAXLexicalHandler_QueryInterface
,
1480 SAXLexicalHandler_AddRef
,
1481 SAXLexicalHandler_Release
,
1482 SAXLexicalHandler_startDTD
,
1483 SAXLexicalHandler_endDTD
,
1484 SAXLexicalHandler_startEntity
,
1485 SAXLexicalHandler_endEntity
,
1486 SAXLexicalHandler_startCDATA
,
1487 SAXLexicalHandler_endCDATA
,
1488 SAXLexicalHandler_comment
1491 /*** ISAXDeclHandler ***/
1492 static HRESULT WINAPI
SAXDeclHandler_QueryInterface(ISAXDeclHandler
*iface
,
1493 REFIID riid
, void **obj
)
1495 mxwriter
*This
= impl_from_ISAXDeclHandler( iface
);
1496 return IMXWriter_QueryInterface(&This
->IMXWriter_iface
, riid
, obj
);
1499 static ULONG WINAPI
SAXDeclHandler_AddRef(ISAXDeclHandler
*iface
)
1501 mxwriter
*This
= impl_from_ISAXDeclHandler( iface
);
1502 return IMXWriter_AddRef(&This
->IMXWriter_iface
);
1505 static ULONG WINAPI
SAXDeclHandler_Release(ISAXDeclHandler
*iface
)
1507 mxwriter
*This
= impl_from_ISAXDeclHandler( iface
);
1508 return IMXWriter_Release(&This
->IMXWriter_iface
);
1511 static HRESULT WINAPI
SAXDeclHandler_elementDecl(ISAXDeclHandler
*iface
,
1512 const WCHAR
*name
, int n_name
, const WCHAR
*model
, int n_model
)
1514 static const WCHAR elementW
[] = {'<','!','E','L','E','M','E','N','T',' '};
1515 mxwriter
*This
= impl_from_ISAXDeclHandler( iface
);
1517 TRACE("(%p)->(%s:%d %s:%d)\n", This
, debugstr_wn(name
, n_name
), n_name
,
1518 debugstr_wn(model
, n_model
), n_model
);
1520 if (!name
|| !model
) return E_INVALIDARG
;
1522 write_output_buffer(This
->buffer
, elementW
, sizeof(elementW
)/sizeof(WCHAR
));
1524 write_output_buffer(This
->buffer
, name
, n_name
);
1525 write_output_buffer(This
->buffer
, spaceW
, sizeof(spaceW
)/sizeof(WCHAR
));
1528 write_output_buffer(This
->buffer
, model
, n_model
);
1529 write_output_buffer(This
->buffer
, closetagW
, sizeof(closetagW
)/sizeof(WCHAR
));
1534 static HRESULT WINAPI
SAXDeclHandler_attributeDecl(ISAXDeclHandler
*iface
,
1535 const WCHAR
*element
, int n_element
, const WCHAR
*attr
, int n_attr
,
1536 const WCHAR
*type
, int n_type
, const WCHAR
*Default
, int n_default
,
1537 const WCHAR
*value
, int n_value
)
1539 mxwriter
*This
= impl_from_ISAXDeclHandler( iface
);
1540 static const WCHAR attlistW
[] = {'<','!','A','T','T','L','I','S','T',' '};
1541 static const WCHAR closetagW
[] = {'>','\r','\n'};
1543 TRACE("(%p)->(%s:%d %s:%d %s:%d %s:%d %s:%d)\n", This
, debugstr_wn(element
, n_element
), n_element
,
1544 debugstr_wn(attr
, n_attr
), n_attr
, debugstr_wn(type
, n_type
), n_type
, debugstr_wn(Default
, n_default
), n_default
,
1545 debugstr_wn(value
, n_value
), n_value
);
1547 write_output_buffer(This
->buffer
, attlistW
, sizeof(attlistW
)/sizeof(WCHAR
));
1549 write_output_buffer(This
->buffer
, element
, n_element
);
1550 write_output_buffer(This
->buffer
, spaceW
, sizeof(spaceW
)/sizeof(WCHAR
));
1554 write_output_buffer(This
->buffer
, attr
, n_attr
);
1555 write_output_buffer(This
->buffer
, spaceW
, sizeof(spaceW
)/sizeof(WCHAR
));
1559 write_output_buffer(This
->buffer
, type
, n_type
);
1560 write_output_buffer(This
->buffer
, spaceW
, sizeof(spaceW
)/sizeof(WCHAR
));
1564 write_output_buffer(This
->buffer
, Default
, n_default
);
1565 write_output_buffer(This
->buffer
, spaceW
, sizeof(spaceW
)/sizeof(WCHAR
));
1569 write_output_buffer_quoted(This
->buffer
, value
, n_value
);
1571 write_output_buffer(This
->buffer
, closetagW
, sizeof(closetagW
)/sizeof(WCHAR
));
1576 static HRESULT WINAPI
SAXDeclHandler_internalEntityDecl(ISAXDeclHandler
*iface
,
1577 const WCHAR
*name
, int n_name
, const WCHAR
*value
, int n_value
)
1579 mxwriter
*This
= impl_from_ISAXDeclHandler( iface
);
1581 TRACE("(%p)->(%s:%d %s:%d)\n", This
, debugstr_wn(name
, n_name
), n_name
,
1582 debugstr_wn(value
, n_value
), n_value
);
1584 if (!name
|| !value
) return E_INVALIDARG
;
1586 write_output_buffer(This
->buffer
, entityW
, sizeof(entityW
)/sizeof(WCHAR
));
1588 write_output_buffer(This
->buffer
, name
, n_name
);
1589 write_output_buffer(This
->buffer
, spaceW
, sizeof(spaceW
)/sizeof(WCHAR
));
1593 write_output_buffer_quoted(This
->buffer
, value
, n_value
);
1595 write_output_buffer(This
->buffer
, closetagW
, sizeof(closetagW
)/sizeof(WCHAR
));
1600 static HRESULT WINAPI
SAXDeclHandler_externalEntityDecl(ISAXDeclHandler
*iface
,
1601 const WCHAR
*name
, int n_name
, const WCHAR
*publicId
, int n_publicId
,
1602 const WCHAR
*systemId
, int n_systemId
)
1604 static const WCHAR publicW
[] = {'P','U','B','L','I','C',' '};
1605 static const WCHAR systemW
[] = {'S','Y','S','T','E','M',' '};
1606 mxwriter
*This
= impl_from_ISAXDeclHandler( iface
);
1608 TRACE("(%p)->(%s:%d %s:%d %s:%d)\n", This
, debugstr_wn(name
, n_name
), n_name
,
1609 debugstr_wn(publicId
, n_publicId
), n_publicId
, debugstr_wn(systemId
, n_systemId
), n_systemId
);
1611 if (!name
) return E_INVALIDARG
;
1612 if (publicId
&& !systemId
) return E_INVALIDARG
;
1613 if (!publicId
&& !systemId
) return E_INVALIDARG
;
1615 write_output_buffer(This
->buffer
, entityW
, sizeof(entityW
)/sizeof(WCHAR
));
1617 write_output_buffer(This
->buffer
, name
, n_name
);
1618 write_output_buffer(This
->buffer
, spaceW
, sizeof(spaceW
)/sizeof(WCHAR
));
1623 write_output_buffer(This
->buffer
, publicW
, sizeof(publicW
)/sizeof(WCHAR
));
1624 write_output_buffer_quoted(This
->buffer
, publicId
, n_publicId
);
1625 write_output_buffer(This
->buffer
, spaceW
, sizeof(spaceW
)/sizeof(WCHAR
));
1626 write_output_buffer_quoted(This
->buffer
, systemId
, n_systemId
);
1630 write_output_buffer(This
->buffer
, systemW
, sizeof(systemW
)/sizeof(WCHAR
));
1631 write_output_buffer_quoted(This
->buffer
, systemId
, n_systemId
);
1634 write_output_buffer(This
->buffer
, closetagW
, sizeof(closetagW
)/sizeof(WCHAR
));
1639 static const ISAXDeclHandlerVtbl SAXDeclHandlerVtbl
= {
1640 SAXDeclHandler_QueryInterface
,
1641 SAXDeclHandler_AddRef
,
1642 SAXDeclHandler_Release
,
1643 SAXDeclHandler_elementDecl
,
1644 SAXDeclHandler_attributeDecl
,
1645 SAXDeclHandler_internalEntityDecl
,
1646 SAXDeclHandler_externalEntityDecl
1649 static const tid_t mxwriter_iface_tids
[] = {
1654 static dispex_static_data_t mxwriter_dispex
= {
1661 HRESULT
MXWriter_create(MSXML_VERSION version
, void **ppObj
)
1663 static const WCHAR version10W
[] = {'1','.','0',0};
1667 TRACE("(%p)\n", ppObj
);
1669 This
= heap_alloc( sizeof (*This
) );
1671 return E_OUTOFMEMORY
;
1673 This
->IMXWriter_iface
.lpVtbl
= &MXWriterVtbl
;
1674 This
->ISAXContentHandler_iface
.lpVtbl
= &SAXContentHandlerVtbl
;
1675 This
->ISAXLexicalHandler_iface
.lpVtbl
= &SAXLexicalHandlerVtbl
;
1676 This
->ISAXDeclHandler_iface
.lpVtbl
= &SAXDeclHandlerVtbl
;
1678 This
->class_version
= version
;
1680 This
->props
[MXWriter_BOM
] = VARIANT_TRUE
;
1681 This
->props
[MXWriter_DisableEscaping
] = VARIANT_FALSE
;
1682 This
->props
[MXWriter_Indent
] = VARIANT_FALSE
;
1683 This
->props
[MXWriter_OmitXmlDecl
] = VARIANT_FALSE
;
1684 This
->props
[MXWriter_Standalone
] = VARIANT_FALSE
;
1685 This
->prop_changed
= FALSE
;
1686 This
->encoding
= SysAllocString(utf16W
);
1687 This
->version
= SysAllocString(version10W
);
1688 This
->xml_enc
= XmlEncoding_UTF16
;
1690 This
->element
= NULL
;
1691 This
->cdata
= FALSE
;
1694 This
->newline
= FALSE
;
1697 This
->dest_written
= 0;
1699 hr
= alloc_output_buffer(This
->xml_enc
, &This
->buffer
);
1701 SysFreeString(This
->encoding
);
1702 SysFreeString(This
->version
);
1707 init_dispex(&This
->dispex
, (IUnknown
*)&This
->IMXWriter_iface
, &mxwriter_dispex
);
1709 *ppObj
= &This
->IMXWriter_iface
;
1711 TRACE("returning iface %p\n", *ppObj
);
1716 static HRESULT WINAPI
MXAttributes_QueryInterface(IMXAttributes
*iface
, REFIID riid
, void **ppObj
)
1718 mxattributes
*This
= impl_from_IMXAttributes( iface
);
1720 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid( riid
), ppObj
);
1724 if ( IsEqualGUID( riid
, &IID_IUnknown
) ||
1725 IsEqualGUID( riid
, &IID_IDispatch
) ||
1726 IsEqualGUID( riid
, &IID_IMXAttributes
))
1730 else if ( IsEqualGUID( riid
, &IID_ISAXAttributes
))
1732 *ppObj
= &This
->ISAXAttributes_iface
;
1734 else if ( IsEqualGUID( riid
, &IID_IVBSAXAttributes
))
1736 *ppObj
= &This
->IVBSAXAttributes_iface
;
1738 else if (dispex_query_interface(&This
->dispex
, riid
, ppObj
))
1740 return *ppObj
? S_OK
: E_NOINTERFACE
;
1744 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
1745 return E_NOINTERFACE
;
1748 IMXAttributes_AddRef( iface
);
1753 static ULONG WINAPI
MXAttributes_AddRef(IMXAttributes
*iface
)
1755 mxattributes
*This
= impl_from_IMXAttributes( iface
);
1756 ULONG ref
= InterlockedIncrement( &This
->ref
);
1757 TRACE("(%p)->(%d)\n", This
, ref
);
1761 static ULONG WINAPI
MXAttributes_Release(IMXAttributes
*iface
)
1763 mxattributes
*This
= impl_from_IMXAttributes( iface
);
1764 LONG ref
= InterlockedDecrement( &This
->ref
);
1766 TRACE("(%p)->(%d)\n", This
, ref
);
1772 for (i
= 0; i
< This
->length
; i
++)
1774 SysFreeString(This
->attr
[i
].qname
);
1775 SysFreeString(This
->attr
[i
].local
);
1776 SysFreeString(This
->attr
[i
].uri
);
1777 SysFreeString(This
->attr
[i
].type
);
1778 SysFreeString(This
->attr
[i
].value
);
1781 release_dispex(&This
->dispex
);
1782 heap_free(This
->attr
);
1789 static HRESULT WINAPI
MXAttributes_GetTypeInfoCount(IMXAttributes
*iface
, UINT
* pctinfo
)
1791 mxattributes
*This
= impl_from_IMXAttributes( iface
);
1792 return IDispatchEx_GetTypeInfoCount(&This
->dispex
.IDispatchEx_iface
, pctinfo
);
1795 static HRESULT WINAPI
MXAttributes_GetTypeInfo(IMXAttributes
*iface
, UINT iTInfo
, LCID lcid
, ITypeInfo
** ppTInfo
)
1797 mxattributes
*This
= impl_from_IMXAttributes( iface
);
1798 return IDispatchEx_GetTypeInfo(&This
->dispex
.IDispatchEx_iface
, iTInfo
, lcid
, ppTInfo
);
1801 static HRESULT WINAPI
MXAttributes_GetIDsOfNames(
1802 IMXAttributes
*iface
,
1804 LPOLESTR
* rgszNames
,
1809 mxattributes
*This
= impl_from_IMXAttributes( iface
);
1810 return IDispatchEx_GetIDsOfNames(&This
->dispex
.IDispatchEx_iface
,
1811 riid
, rgszNames
, cNames
, lcid
, rgDispId
);
1814 static HRESULT WINAPI
MXAttributes_Invoke(
1815 IMXAttributes
*iface
,
1816 DISPID dispIdMember
,
1820 DISPPARAMS
* pDispParams
,
1821 VARIANT
* pVarResult
,
1822 EXCEPINFO
* pExcepInfo
,
1825 mxattributes
*This
= impl_from_IMXAttributes( iface
);
1826 return IDispatchEx_Invoke(&This
->dispex
.IDispatchEx_iface
,
1827 dispIdMember
, riid
, lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1830 static HRESULT WINAPI
MXAttributes_addAttribute(IMXAttributes
*iface
,
1831 BSTR uri
, BSTR localName
, BSTR QName
, BSTR type
, BSTR value
)
1833 mxattributes
*This
= impl_from_IMXAttributes( iface
);
1837 TRACE("(%p)->(%s %s %s %s %s)\n", This
, debugstr_w(uri
), debugstr_w(localName
),
1838 debugstr_w(QName
), debugstr_w(type
), debugstr_w(value
));
1840 if ((!uri
|| !localName
|| !QName
|| !type
|| !value
) && This
->class_version
!= MSXML6
)
1841 return E_INVALIDARG
;
1843 /* ensure array is large enough */
1844 hr
= mxattributes_grow(This
);
1845 if (hr
!= S_OK
) return hr
;
1847 attr
= &This
->attr
[This
->length
];
1849 attr
->qname
= SysAllocString(QName
);
1850 attr
->local
= SysAllocString(localName
);
1851 attr
->uri
= SysAllocString(uri
);
1852 attr
->type
= SysAllocString(type
? type
: emptyW
);
1853 attr
->value
= SysAllocString(value
);
1859 static HRESULT WINAPI
MXAttributes_addAttributeFromIndex(IMXAttributes
*iface
,
1860 VARIANT atts
, int index
)
1862 mxattributes
*This
= impl_from_IMXAttributes( iface
);
1863 FIXME("(%p)->(%s %d): stub\n", This
, debugstr_variant(&atts
), index
);
1867 static HRESULT WINAPI
MXAttributes_clear(IMXAttributes
*iface
)
1869 mxattributes
*This
= impl_from_IMXAttributes( iface
);
1872 TRACE("(%p)\n", This
);
1874 for (i
= 0; i
< This
->length
; i
++)
1876 SysFreeString(This
->attr
[i
].qname
);
1877 SysFreeString(This
->attr
[i
].local
);
1878 SysFreeString(This
->attr
[i
].uri
);
1879 SysFreeString(This
->attr
[i
].type
);
1880 SysFreeString(This
->attr
[i
].value
);
1881 memset(&This
->attr
[i
], 0, sizeof(mxattribute
));
1889 static mxattribute
*get_attribute_byindex(mxattributes
*attrs
, int index
)
1891 if (index
< 0 || index
>= attrs
->length
) return NULL
;
1892 return &attrs
->attr
[index
];
1895 static HRESULT WINAPI
MXAttributes_removeAttribute(IMXAttributes
*iface
, int index
)
1897 mxattributes
*This
= impl_from_IMXAttributes( iface
);
1900 TRACE("(%p)->(%d)\n", This
, index
);
1902 if (!(dst
= get_attribute_byindex(This
, index
))) return E_INVALIDARG
;
1904 /* no need to remove last attribute, just make it inaccessible */
1905 if (index
+ 1 == This
->length
)
1911 memmove(dst
, dst
+ 1, (This
->length
-index
-1)*sizeof(*dst
));
1917 static HRESULT WINAPI
MXAttributes_setAttribute(IMXAttributes
*iface
, int index
,
1918 BSTR uri
, BSTR localName
, BSTR QName
, BSTR type
, BSTR value
)
1920 mxattributes
*This
= impl_from_IMXAttributes( iface
);
1921 FIXME("(%p)->(%d %s %s %s %s %s): stub\n", This
, index
, debugstr_w(uri
),
1922 debugstr_w(localName
), debugstr_w(QName
), debugstr_w(type
), debugstr_w(value
));
1926 static HRESULT WINAPI
MXAttributes_setAttributes(IMXAttributes
*iface
, VARIANT atts
)
1928 mxattributes
*This
= impl_from_IMXAttributes( iface
);
1929 FIXME("(%p)->(%s): stub\n", This
, debugstr_variant(&atts
));
1933 static HRESULT WINAPI
MXAttributes_setLocalName(IMXAttributes
*iface
, int index
,
1936 mxattributes
*This
= impl_from_IMXAttributes( iface
);
1939 TRACE("(%p)->(%d %s)\n", This
, index
, debugstr_w(localName
));
1941 if (!(attr
= get_attribute_byindex(This
, index
))) return E_INVALIDARG
;
1943 SysFreeString(attr
->local
);
1944 attr
->local
= SysAllocString(localName
);
1949 static HRESULT WINAPI
MXAttributes_setQName(IMXAttributes
*iface
, int index
, BSTR QName
)
1951 mxattributes
*This
= impl_from_IMXAttributes( iface
);
1954 TRACE("(%p)->(%d %s)\n", This
, index
, debugstr_w(QName
));
1956 if (!(attr
= get_attribute_byindex(This
, index
))) return E_INVALIDARG
;
1958 SysFreeString(attr
->qname
);
1959 attr
->qname
= SysAllocString(QName
);
1964 static HRESULT WINAPI
MXAttributes_setURI(IMXAttributes
*iface
, int index
, BSTR uri
)
1966 mxattributes
*This
= impl_from_IMXAttributes( iface
);
1969 TRACE("(%p)->(%d %s)\n", This
, index
, debugstr_w(uri
));
1971 if (!(attr
= get_attribute_byindex(This
, index
))) return E_INVALIDARG
;
1973 SysFreeString(attr
->uri
);
1974 attr
->uri
= SysAllocString(uri
);
1979 static HRESULT WINAPI
MXAttributes_setValue(IMXAttributes
*iface
, int index
, BSTR value
)
1981 mxattributes
*This
= impl_from_IMXAttributes( iface
);
1984 TRACE("(%p)->(%d %s)\n", This
, index
, debugstr_w(value
));
1986 if (!(attr
= get_attribute_byindex(This
, index
))) return E_INVALIDARG
;
1988 SysFreeString(attr
->value
);
1989 attr
->value
= SysAllocString(value
);
1994 static const IMXAttributesVtbl MXAttributesVtbl
= {
1995 MXAttributes_QueryInterface
,
1996 MXAttributes_AddRef
,
1997 MXAttributes_Release
,
1998 MXAttributes_GetTypeInfoCount
,
1999 MXAttributes_GetTypeInfo
,
2000 MXAttributes_GetIDsOfNames
,
2001 MXAttributes_Invoke
,
2002 MXAttributes_addAttribute
,
2003 MXAttributes_addAttributeFromIndex
,
2005 MXAttributes_removeAttribute
,
2006 MXAttributes_setAttribute
,
2007 MXAttributes_setAttributes
,
2008 MXAttributes_setLocalName
,
2009 MXAttributes_setQName
,
2010 MXAttributes_setURI
,
2011 MXAttributes_setValue
2014 static HRESULT WINAPI
SAXAttributes_QueryInterface(ISAXAttributes
*iface
, REFIID riid
, void **ppObj
)
2016 mxattributes
*This
= impl_from_ISAXAttributes( iface
);
2017 return IMXAttributes_QueryInterface(&This
->IMXAttributes_iface
, riid
, ppObj
);
2020 static ULONG WINAPI
SAXAttributes_AddRef(ISAXAttributes
*iface
)
2022 mxattributes
*This
= impl_from_ISAXAttributes( iface
);
2023 return IMXAttributes_AddRef(&This
->IMXAttributes_iface
);
2026 static ULONG WINAPI
SAXAttributes_Release(ISAXAttributes
*iface
)
2028 mxattributes
*This
= impl_from_ISAXAttributes( iface
);
2029 return IMXAttributes_Release(&This
->IMXAttributes_iface
);
2032 static HRESULT WINAPI
SAXAttributes_getLength(ISAXAttributes
*iface
, int *length
)
2034 mxattributes
*This
= impl_from_ISAXAttributes( iface
);
2035 TRACE("(%p)->(%p)\n", This
, length
);
2037 if (!length
&& (This
->class_version
== MSXML_DEFAULT
|| This
->class_version
== MSXML3
))
2040 *length
= This
->length
;
2045 static HRESULT WINAPI
SAXAttributes_getURI(ISAXAttributes
*iface
, int index
, const WCHAR
**uri
,
2048 mxattributes
*This
= impl_from_ISAXAttributes( iface
);
2050 TRACE("(%p)->(%d %p %p)\n", This
, index
, uri
, len
);
2052 if (index
>= This
->length
|| index
< 0) return E_INVALIDARG
;
2053 if (!uri
|| !len
) return E_POINTER
;
2055 *len
= SysStringLen(This
->attr
[index
].uri
);
2056 *uri
= This
->attr
[index
].uri
;
2061 static HRESULT WINAPI
SAXAttributes_getLocalName(ISAXAttributes
*iface
, int index
, const WCHAR
**name
,
2064 mxattributes
*This
= impl_from_ISAXAttributes( iface
);
2066 TRACE("(%p)->(%d %p %p)\n", This
, index
, name
, len
);
2068 if (index
>= This
->length
|| index
< 0) return E_INVALIDARG
;
2069 if (!name
|| !len
) return E_POINTER
;
2071 *len
= SysStringLen(This
->attr
[index
].local
);
2072 *name
= This
->attr
[index
].local
;
2077 static HRESULT WINAPI
SAXAttributes_getQName(ISAXAttributes
*iface
, int index
, const WCHAR
**qname
, int *length
)
2079 mxattributes
*This
= impl_from_ISAXAttributes( iface
);
2081 TRACE("(%p)->(%d %p %p)\n", This
, index
, qname
, length
);
2083 if (index
>= This
->length
) return E_INVALIDARG
;
2084 if (!qname
|| !length
) return E_POINTER
;
2086 *qname
= This
->attr
[index
].qname
;
2087 *length
= SysStringLen(This
->attr
[index
].qname
);
2092 static HRESULT WINAPI
SAXAttributes_getName(ISAXAttributes
*iface
, int index
, const WCHAR
**uri
, int *uri_len
,
2093 const WCHAR
**local
, int *local_len
, const WCHAR
**qname
, int *qname_len
)
2095 mxattributes
*This
= impl_from_ISAXAttributes( iface
);
2097 TRACE("(%p)->(%d %p %p %p %p %p %p)\n", This
, index
, uri
, uri_len
, local
, local_len
, qname
, qname_len
);
2099 if (index
>= This
->length
|| index
< 0)
2100 return E_INVALIDARG
;
2102 if (!uri
|| !uri_len
|| !local
|| !local_len
|| !qname
|| !qname_len
)
2105 *uri_len
= SysStringLen(This
->attr
[index
].uri
);
2106 *uri
= This
->attr
[index
].uri
;
2108 *local_len
= SysStringLen(This
->attr
[index
].local
);
2109 *local
= This
->attr
[index
].local
;
2111 *qname_len
= SysStringLen(This
->attr
[index
].qname
);
2112 *qname
= This
->attr
[index
].qname
;
2114 TRACE("(%s, %s, %s)\n", debugstr_w(*uri
), debugstr_w(*local
), debugstr_w(*qname
));
2119 static HRESULT WINAPI
SAXAttributes_getIndexFromName(ISAXAttributes
*iface
, const WCHAR
*uri
, int uri_len
,
2120 const WCHAR
*name
, int len
, int *index
)
2122 mxattributes
*This
= impl_from_ISAXAttributes( iface
);
2125 TRACE("(%p)->(%s:%d %s:%d %p)\n", This
, debugstr_wn(uri
, uri_len
), uri_len
,
2126 debugstr_wn(name
, len
), len
, index
);
2128 if (!index
&& (This
->class_version
== MSXML_DEFAULT
|| This
->class_version
== MSXML3
))
2131 if (!uri
|| !name
|| !index
) return E_INVALIDARG
;
2133 for (i
= 0; i
< This
->length
; i
++)
2135 if (uri_len
!= SysStringLen(This
->attr
[i
].uri
)) continue;
2136 if (strncmpW(uri
, This
->attr
[i
].uri
, uri_len
)) continue;
2138 if (len
!= SysStringLen(This
->attr
[i
].local
)) continue;
2139 if (strncmpW(name
, This
->attr
[i
].local
, len
)) continue;
2145 return E_INVALIDARG
;
2148 static HRESULT WINAPI
SAXAttributes_getIndexFromQName(ISAXAttributes
*iface
, const WCHAR
*qname
,
2149 int len
, int *index
)
2151 mxattributes
*This
= impl_from_ISAXAttributes( iface
);
2154 TRACE("(%p)->(%s:%d %p)\n", This
, debugstr_wn(qname
, len
), len
, index
);
2156 if (!index
&& (This
->class_version
== MSXML_DEFAULT
|| This
->class_version
== MSXML3
))
2159 if (!qname
|| !index
|| !len
) return E_INVALIDARG
;
2161 for (i
= 0; i
< This
->length
; i
++)
2163 if (len
!= SysStringLen(This
->attr
[i
].qname
)) continue;
2164 if (strncmpW(qname
, This
->attr
[i
].qname
, len
)) continue;
2170 return E_INVALIDARG
;
2173 static HRESULT WINAPI
SAXAttributes_getType(ISAXAttributes
*iface
, int index
, const WCHAR
**type
,
2176 mxattributes
*This
= impl_from_ISAXAttributes( iface
);
2178 TRACE("(%p)->(%d %p %p)\n", This
, index
, type
, len
);
2180 if (index
>= This
->length
) return E_INVALIDARG
;
2182 if ((!type
|| !len
) && (This
->class_version
== MSXML_DEFAULT
|| This
->class_version
== MSXML3
))
2185 *type
= This
->attr
[index
].type
;
2186 *len
= SysStringLen(This
->attr
[index
].type
);
2191 static HRESULT WINAPI
SAXAttributes_getTypeFromName(ISAXAttributes
*iface
, const WCHAR
* pUri
, int nUri
,
2192 const WCHAR
* pLocalName
, int nLocalName
, const WCHAR
** pType
, int * nType
)
2194 mxattributes
*This
= impl_from_ISAXAttributes( iface
);
2195 FIXME("(%p)->(%s:%d %s:%d %p %p): stub\n", This
, debugstr_wn(pUri
, nUri
), nUri
,
2196 debugstr_wn(pLocalName
, nLocalName
), nLocalName
, pType
, nType
);
2200 static HRESULT WINAPI
SAXAttributes_getTypeFromQName(ISAXAttributes
*iface
, const WCHAR
* pQName
,
2201 int nQName
, const WCHAR
** pType
, int * nType
)
2203 mxattributes
*This
= impl_from_ISAXAttributes( iface
);
2204 FIXME("(%p)->(%s:%d %p %p): stub\n", This
, debugstr_wn(pQName
, nQName
), nQName
, pType
, nType
);
2208 static HRESULT WINAPI
SAXAttributes_getValue(ISAXAttributes
*iface
, int index
, const WCHAR
**value
,
2211 mxattributes
*This
= impl_from_ISAXAttributes( iface
);
2213 TRACE("(%p)->(%d %p %p)\n", This
, index
, value
, len
);
2215 if (index
>= This
->length
) return E_INVALIDARG
;
2217 if ((!value
|| !len
) && (This
->class_version
== MSXML_DEFAULT
|| This
->class_version
== MSXML3
))
2220 *value
= This
->attr
[index
].value
;
2221 *len
= SysStringLen(This
->attr
[index
].value
);
2226 static HRESULT WINAPI
SAXAttributes_getValueFromName(ISAXAttributes
*iface
, const WCHAR
*uri
,
2227 int uri_len
, const WCHAR
*name
, int name_len
, const WCHAR
**value
, int *value_len
)
2229 mxattributes
*This
= impl_from_ISAXAttributes( iface
);
2233 TRACE("(%p)->(%s:%d %s:%d %p %p)\n", This
, debugstr_wn(uri
, uri_len
), uri_len
,
2234 debugstr_wn(name
, name_len
), name_len
, value
, value_len
);
2236 if (!uri
|| !name
|| !value
|| !value_len
)
2237 return (This
->class_version
== MSXML_DEFAULT
|| This
->class_version
== MSXML3
) ? E_POINTER
: E_INVALIDARG
;
2239 hr
= ISAXAttributes_getIndexFromName(iface
, uri
, uri_len
, name
, name_len
, &index
);
2241 hr
= ISAXAttributes_getValue(iface
, index
, value
, value_len
);
2246 static HRESULT WINAPI
SAXAttributes_getValueFromQName(ISAXAttributes
*iface
, const WCHAR
*qname
,
2247 int qname_len
, const WCHAR
**value
, int *value_len
)
2249 mxattributes
*This
= impl_from_ISAXAttributes( iface
);
2253 TRACE("(%p)->(%s:%d %p %p)\n", This
, debugstr_wn(qname
, qname_len
), qname_len
, value
, value_len
);
2255 if (!qname
|| !value
|| !value_len
)
2256 return (This
->class_version
== MSXML_DEFAULT
|| This
->class_version
== MSXML3
) ? E_POINTER
: E_INVALIDARG
;
2258 hr
= ISAXAttributes_getIndexFromQName(iface
, qname
, qname_len
, &index
);
2260 hr
= ISAXAttributes_getValue(iface
, index
, value
, value_len
);
2265 static const ISAXAttributesVtbl SAXAttributesVtbl
= {
2266 SAXAttributes_QueryInterface
,
2267 SAXAttributes_AddRef
,
2268 SAXAttributes_Release
,
2269 SAXAttributes_getLength
,
2270 SAXAttributes_getURI
,
2271 SAXAttributes_getLocalName
,
2272 SAXAttributes_getQName
,
2273 SAXAttributes_getName
,
2274 SAXAttributes_getIndexFromName
,
2275 SAXAttributes_getIndexFromQName
,
2276 SAXAttributes_getType
,
2277 SAXAttributes_getTypeFromName
,
2278 SAXAttributes_getTypeFromQName
,
2279 SAXAttributes_getValue
,
2280 SAXAttributes_getValueFromName
,
2281 SAXAttributes_getValueFromQName
2284 static HRESULT WINAPI
VBSAXAttributes_QueryInterface(
2285 IVBSAXAttributes
* iface
,
2289 mxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
2290 TRACE("%p %s %p\n", This
, debugstr_guid(riid
), ppvObject
);
2291 return ISAXAttributes_QueryInterface(&This
->ISAXAttributes_iface
, riid
, ppvObject
);
2294 static ULONG WINAPI
VBSAXAttributes_AddRef(IVBSAXAttributes
* iface
)
2296 mxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
2297 return ISAXAttributes_AddRef(&This
->ISAXAttributes_iface
);
2300 static ULONG WINAPI
VBSAXAttributes_Release(IVBSAXAttributes
* iface
)
2302 mxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
2303 return ISAXAttributes_Release(&This
->ISAXAttributes_iface
);
2306 static HRESULT WINAPI
VBSAXAttributes_GetTypeInfoCount( IVBSAXAttributes
*iface
, UINT
* pctinfo
)
2308 mxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
2310 TRACE("(%p)->(%p)\n", This
, pctinfo
);
2317 static HRESULT WINAPI
VBSAXAttributes_GetTypeInfo(
2318 IVBSAXAttributes
*iface
,
2319 UINT iTInfo
, LCID lcid
, ITypeInfo
** ppTInfo
)
2321 mxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
2322 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
2323 return get_typeinfo(IVBSAXAttributes_tid
, ppTInfo
);
2326 static HRESULT WINAPI
VBSAXAttributes_GetIDsOfNames(
2327 IVBSAXAttributes
*iface
,
2329 LPOLESTR
* rgszNames
,
2334 mxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
2335 ITypeInfo
*typeinfo
;
2338 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
2341 if(!rgszNames
|| cNames
== 0 || !rgDispId
)
2342 return E_INVALIDARG
;
2344 hr
= get_typeinfo(IVBSAXAttributes_tid
, &typeinfo
);
2347 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
2348 ITypeInfo_Release(typeinfo
);
2354 static HRESULT WINAPI
VBSAXAttributes_Invoke(
2355 IVBSAXAttributes
*iface
,
2356 DISPID dispIdMember
,
2360 DISPPARAMS
* pDispParams
,
2361 VARIANT
* pVarResult
,
2362 EXCEPINFO
* pExcepInfo
,
2365 mxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
2366 ITypeInfo
*typeinfo
;
2369 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
2370 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
2372 hr
= get_typeinfo(IVBSAXAttributes_tid
, &typeinfo
);
2375 hr
= ITypeInfo_Invoke(typeinfo
, &This
->IVBSAXAttributes_iface
, dispIdMember
, wFlags
,
2376 pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
2377 ITypeInfo_Release(typeinfo
);
2383 static HRESULT WINAPI
VBSAXAttributes_get_length(IVBSAXAttributes
* iface
, int *len
)
2385 mxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
2386 return ISAXAttributes_getLength(&This
->ISAXAttributes_iface
, len
);
2389 static HRESULT WINAPI
VBSAXAttributes_getURI(IVBSAXAttributes
* iface
, int index
, BSTR
*uri
)
2391 mxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
2394 return ISAXAttributes_getURI(&This
->ISAXAttributes_iface
, index
, (const WCHAR
**)uri
, &len
);
2397 static HRESULT WINAPI
VBSAXAttributes_getLocalName(IVBSAXAttributes
* iface
, int index
, BSTR
*name
)
2399 mxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
2402 return ISAXAttributes_getLocalName(&This
->ISAXAttributes_iface
, index
, (const WCHAR
**)name
, &len
);
2405 static HRESULT WINAPI
VBSAXAttributes_getQName(IVBSAXAttributes
* iface
, int index
, BSTR
*qname
)
2407 mxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
2410 return ISAXAttributes_getQName(&This
->ISAXAttributes_iface
, index
, (const WCHAR
**)qname
, &len
);
2413 static HRESULT WINAPI
VBSAXAttributes_getIndexFromName(IVBSAXAttributes
* iface
, BSTR uri
, BSTR name
, int *index
)
2415 mxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
2416 return ISAXAttributes_getIndexFromName(&This
->ISAXAttributes_iface
, uri
, SysStringLen(uri
),
2417 name
, SysStringLen(name
), index
);
2420 static HRESULT WINAPI
VBSAXAttributes_getIndexFromQName(IVBSAXAttributes
* iface
, BSTR qname
, int *index
)
2422 mxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
2423 return ISAXAttributes_getIndexFromQName(&This
->ISAXAttributes_iface
, qname
,
2424 SysStringLen(qname
), index
);
2427 static HRESULT WINAPI
VBSAXAttributes_getType(IVBSAXAttributes
* iface
, int index
,BSTR
*type
)
2429 mxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
2432 return ISAXAttributes_getType(&This
->ISAXAttributes_iface
, index
, (const WCHAR
**)type
, &len
);
2435 static HRESULT WINAPI
VBSAXAttributes_getTypeFromName(IVBSAXAttributes
* iface
, BSTR uri
,
2436 BSTR name
, BSTR
*type
)
2438 mxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
2441 return ISAXAttributes_getTypeFromName(&This
->ISAXAttributes_iface
, uri
, SysStringLen(uri
),
2442 name
, SysStringLen(name
), (const WCHAR
**)type
, &len
);
2445 static HRESULT WINAPI
VBSAXAttributes_getTypeFromQName(IVBSAXAttributes
* iface
, BSTR qname
, BSTR
*type
)
2447 mxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
2450 return ISAXAttributes_getTypeFromQName(&This
->ISAXAttributes_iface
, qname
, SysStringLen(qname
),
2451 (const WCHAR
**)type
, &len
);
2454 static HRESULT WINAPI
VBSAXAttributes_getValue(IVBSAXAttributes
* iface
, int index
, BSTR
*value
)
2456 mxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
2459 return ISAXAttributes_getValue(&This
->ISAXAttributes_iface
, index
, (const WCHAR
**)value
, &len
);
2462 static HRESULT WINAPI
VBSAXAttributes_getValueFromName(IVBSAXAttributes
* iface
, BSTR uri
, BSTR name
,
2465 mxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
2468 return ISAXAttributes_getValueFromName(&This
->ISAXAttributes_iface
, uri
, SysStringLen(uri
),
2469 name
, SysStringLen(name
), (const WCHAR
**)value
, &len
);
2472 static HRESULT WINAPI
VBSAXAttributes_getValueFromQName(IVBSAXAttributes
* iface
, BSTR qname
, BSTR
*value
)
2474 mxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
2477 return ISAXAttributes_getValueFromQName(&This
->ISAXAttributes_iface
, qname
, SysStringLen(qname
),
2478 (const WCHAR
**)value
, &len
);
2481 static const struct IVBSAXAttributesVtbl VBSAXAttributesVtbl
=
2483 VBSAXAttributes_QueryInterface
,
2484 VBSAXAttributes_AddRef
,
2485 VBSAXAttributes_Release
,
2486 VBSAXAttributes_GetTypeInfoCount
,
2487 VBSAXAttributes_GetTypeInfo
,
2488 VBSAXAttributes_GetIDsOfNames
,
2489 VBSAXAttributes_Invoke
,
2490 VBSAXAttributes_get_length
,
2491 VBSAXAttributes_getURI
,
2492 VBSAXAttributes_getLocalName
,
2493 VBSAXAttributes_getQName
,
2494 VBSAXAttributes_getIndexFromName
,
2495 VBSAXAttributes_getIndexFromQName
,
2496 VBSAXAttributes_getType
,
2497 VBSAXAttributes_getTypeFromName
,
2498 VBSAXAttributes_getTypeFromQName
,
2499 VBSAXAttributes_getValue
,
2500 VBSAXAttributes_getValueFromName
,
2501 VBSAXAttributes_getValueFromQName
2504 static const tid_t mxattrs_iface_tids
[] = {
2509 static dispex_static_data_t mxattrs_dispex
= {
2516 HRESULT
SAXAttributes_create(MSXML_VERSION version
, void **ppObj
)
2518 static const int default_count
= 10;
2521 TRACE("(%p)\n", ppObj
);
2523 This
= heap_alloc( sizeof (*This
) );
2525 return E_OUTOFMEMORY
;
2527 This
->IMXAttributes_iface
.lpVtbl
= &MXAttributesVtbl
;
2528 This
->ISAXAttributes_iface
.lpVtbl
= &SAXAttributesVtbl
;
2529 This
->IVBSAXAttributes_iface
.lpVtbl
= &VBSAXAttributesVtbl
;
2532 This
->class_version
= version
;
2534 This
->attr
= heap_alloc(default_count
*sizeof(mxattribute
));
2536 This
->allocated
= default_count
;
2538 *ppObj
= &This
->IMXAttributes_iface
;
2540 init_dispex(&This
->dispex
, (IUnknown
*)&This
->IMXAttributes_iface
, &mxattrs_dispex
);
2542 TRACE("returning iface %p\n", *ppObj
);