From: Nikolay Sivov nsivov@codeweavers.com
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/xmllite/writer.c | 84 +++++++++++++++++++++++++------------------ 1 file changed, 50 insertions(+), 34 deletions(-)
diff --git a/dlls/xmllite/writer.c b/dlls/xmllite/writer.c index 8fed5f60405..d77908f3c7c 100644 --- a/dlls/xmllite/writer.c +++ b/dlls/xmllite/writer.c @@ -718,24 +718,26 @@ static void writer_dec_indent(xmlwriter *writer) writer->indent_level--; }
-static void write_node_indent(xmlwriter *writer) +static HRESULT write_node_indent(xmlwriter *writer, HRESULT *hr) { unsigned int indent_level = writer->indent_level;
- if (!writer->indent || writer->textnode) + if (FAILED(*hr)) + return *hr; + + if (writer->indent && !writer->textnode) { - writer->textnode = 0; - return; + /* Do state check to prevent newline inserted after BOM. It is assumed that + state does not change between writing BOM and inserting indentation. */ + if (writer->output->written && writer->state != XmlWriterState_Ready) + write_output(writer, L"\r\n", 2, hr); + while (indent_level--) + write_output(writer, L" ", 2, hr); }
- /* Do state check to prevent newline inserted after BOM. It is assumed that - state does not change between writing BOM and inserting indentation. */ - if (writer->output->written && writer->state != XmlWriterState_Ready) - write_output_buffer(writer->output, L"\r\n", 2); - while (indent_level--) - write_output_buffer(writer->output, L" ", 2); - writer->textnode = 0; + + return *hr; }
static HRESULT WINAPI xmlwriter_QueryInterface(IXmlWriter *iface, REFIID riid, void **ppvObject) @@ -1070,31 +1072,35 @@ static HRESULT WINAPI xmlwriter_WriteAttributeString(IXmlWriter *iface, LPCWSTR return S_OK; }
-static void write_cdata_section(xmlwriteroutput *output, const WCHAR *data, int len) +static HRESULT write_cdata_section(xmlwriter *writer, const WCHAR *data, int len) { - write_output_buffer(output, L"<![CDATA[", 9); + HRESULT hr = S_OK; + + write_output(writer, L"<![CDATA[", 9, &hr); if (data) - write_output_buffer(output, data, len); - write_output_buffer(output, L"]]>", 3); + write_output(writer, data, len, &hr); + + return write_output(writer, L"]]>", 3, &hr); }
static HRESULT WINAPI xmlwriter_WriteCData(IXmlWriter *iface, LPCWSTR data) { - xmlwriter *This = impl_from_IXmlWriter(iface); + xmlwriter *writer = impl_from_IXmlWriter(iface); + HRESULT hr = S_OK; int len;
- TRACE("%p %s\n", This, debugstr_w(data)); + TRACE("%p, %s.\n", iface, debugstr_w(data));
- switch (This->state) + switch (writer->state) { case XmlWriterState_Initial: return E_UNEXPECTED; case XmlWriterState_ElemStarted: - writer_close_starttag(This); + hr = writer_close_starttag(writer); break; case XmlWriterState_Ready: case XmlWriterState_DocClosed: - This->state = XmlWriterState_DocClosed; + writer->state = XmlWriterState_DocClosed; return WR_E_INVALIDACTION; case XmlWriterState_InvalidEncoding: return MX_E_ENCODING; @@ -1104,28 +1110,34 @@ static HRESULT WINAPI xmlwriter_WriteCData(IXmlWriter *iface, LPCWSTR data)
len = data ? lstrlenW(data) : 0;
- write_node_indent(This); + if (FAILED(write_node_indent(writer, &hr))) + return hr; + if (!len) - write_cdata_section(This->output, NULL, 0); + { + hr = write_cdata_section(writer, NULL, 0); + } else { - while (len) + while (hr == S_OK && len) { const WCHAR *str = wcsstr(data, L"]]>"); - if (str) { + if (str) + { str += 2; - write_cdata_section(This->output, data, str - data); + hr = write_cdata_section(writer, data, str - data); len -= str - data; data = str; } - else { - write_cdata_section(This->output, data, len); + else + { + hr = write_cdata_section(writer, data, len); break; } } }
- return S_OK; + return hr; }
static HRESULT WINAPI xmlwriter_WriteCharEntity(IXmlWriter *iface, WCHAR ch) @@ -1262,6 +1274,7 @@ static HRESULT WINAPI xmlwriter_WriteChars(IXmlWriter *iface, const WCHAR *chara static HRESULT WINAPI xmlwriter_WriteComment(IXmlWriter *iface, LPCWSTR comment) { xmlwriter *This = impl_from_IXmlWriter(iface); + HRESULT hr = S_OK;
TRACE("%p %s\n", This, debugstr_w(comment));
@@ -1280,7 +1293,7 @@ static HRESULT WINAPI xmlwriter_WriteComment(IXmlWriter *iface, LPCWSTR comment) ; }
- write_node_indent(This); + write_node_indent(This, &hr); write_output_buffer(This->output, L"<!--", 4); if (comment) { int len = lstrlenW(comment), i; @@ -1417,7 +1430,7 @@ static HRESULT WINAPI xmlwriter_WriteElementString(IXmlWriter *iface, LPCWSTR pr }
write_encoding_bom(This); - write_node_indent(This); + write_node_indent(This, &hr);
write_output_buffer_char(This->output, '<'); if (ns) @@ -1480,6 +1493,7 @@ static HRESULT WINAPI xmlwriter_WriteEndElement(IXmlWriter *iface) { xmlwriter *This = impl_from_IXmlWriter(iface); struct element *element; + HRESULT hr = S_OK;
TRACE("%p\n", This);
@@ -1512,7 +1526,7 @@ static HRESULT WINAPI xmlwriter_WriteEndElement(IXmlWriter *iface) else { /* Write full end tag. */ - write_node_indent(This); + write_node_indent(This, &hr); write_output_buffer(This->output, L"</", 2); write_output_buffer(This->output, element->qname, element->len); write_output_buffer_char(This->output, '>'); @@ -1547,6 +1561,7 @@ static HRESULT WINAPI xmlwriter_WriteFullEndElement(IXmlWriter *iface) { xmlwriter *This = impl_from_IXmlWriter(iface); struct element *element; + HRESULT hr = S_OK;
TRACE("%p\n", This);
@@ -1580,7 +1595,7 @@ static HRESULT WINAPI xmlwriter_WriteFullEndElement(IXmlWriter *iface) This->textnode = 0; } else - write_node_indent(This); + write_node_indent(This, &hr);
/* write full end tag */ write_output_buffer(This->output, L"</", 2); @@ -1770,6 +1785,7 @@ static HRESULT WINAPI xmlwriter_WriteProcessingInstruction(IXmlWriter *iface, LP LPCWSTR text) { xmlwriter *This = impl_from_IXmlWriter(iface); + HRESULT hr = S_OK;
TRACE("(%p)->(%s %s)\n", This, wine_dbgstr_w(name), wine_dbgstr_w(text));
@@ -1793,7 +1809,7 @@ static HRESULT WINAPI xmlwriter_WriteProcessingInstruction(IXmlWriter *iface, LP }
write_encoding_bom(This); - write_node_indent(This); + write_node_indent(This, &hr); write_output_buffer(This->output, L"<?", 2); write_output_buffer(This->output, name, -1); write_output_buffer_char(This->output, ' '); @@ -1990,7 +2006,7 @@ static HRESULT WINAPI xmlwriter_WriteStartElement(IXmlWriter *iface, LPCWSTR pre return E_OUTOFMEMORY;
write_encoding_bom(This); - write_node_indent(This); + write_node_indent(This, &hr);
This->state = XmlWriterState_ElemStarted; This->starttagopen = 1;
From: Nikolay Sivov nsivov@codeweavers.com
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/xmllite/writer.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-)
diff --git a/dlls/xmllite/writer.c b/dlls/xmllite/writer.c index d77908f3c7c..fa744f9ecb7 100644 --- a/dlls/xmllite/writer.c +++ b/dlls/xmllite/writer.c @@ -1273,19 +1273,19 @@ static HRESULT WINAPI xmlwriter_WriteChars(IXmlWriter *iface, const WCHAR *chara
static HRESULT WINAPI xmlwriter_WriteComment(IXmlWriter *iface, LPCWSTR comment) { - xmlwriter *This = impl_from_IXmlWriter(iface); + xmlwriter *writer = impl_from_IXmlWriter(iface); HRESULT hr = S_OK;
- TRACE("%p %s\n", This, debugstr_w(comment)); + TRACE("%p, %s.\n", iface, debugstr_w(comment));
- switch (This->state) + switch (writer->state) { case XmlWriterState_Initial: return E_UNEXPECTED; case XmlWriterState_InvalidEncoding: return MX_E_ENCODING; case XmlWriterState_ElemStarted: - writer_close_starttag(This); + hr = writer_close_starttag(writer); break; case XmlWriterState_DocClosed: return WR_E_INVALIDACTION; @@ -1293,29 +1293,33 @@ static HRESULT WINAPI xmlwriter_WriteComment(IXmlWriter *iface, LPCWSTR comment) ; }
- write_node_indent(This, &hr); - write_output_buffer(This->output, L"<!--", 4); - if (comment) { + write_node_indent(writer, &hr); + write_output(writer, L"<!--", 4, &hr); + if (comment) + { int len = lstrlenW(comment), i;
/* Make sure there's no two hyphen sequences in a string, space is used as a separator to produce compliant comment string */ - if (len > 1) { - for (i = 0; i < len; i++) { - write_output_buffer(This->output, comment + i, 1); + if (len > 1) + { + for (i = 0; i < len && hr == S_OK; i++) + { + write_output(writer, comment + i, 1, &hr); if (comment[i] == '-' && (i + 1 < len) && comment[i+1] == '-') - write_output_buffer_char(This->output, ' '); + write_output(writer, L" ", 1, &hr); } } else - write_output_buffer(This->output, comment, len); + { + write_output(writer, comment, len, &hr); + }
if (len && comment[len-1] == '-') - write_output_buffer_char(This->output, ' '); + write_output(writer, L" ", 1, &hr); } - write_output_buffer(This->output, L"-->", 3);
- return S_OK; + return write_output(writer, L"-->", 3, &hr); }
static HRESULT WINAPI xmlwriter_WriteDocType(IXmlWriter *iface, LPCWSTR name, LPCWSTR pubid,
From: Nikolay Sivov nsivov@codeweavers.com
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/xmllite/writer.c | 51 +++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 24 deletions(-)
diff --git a/dlls/xmllite/writer.c b/dlls/xmllite/writer.c index fa744f9ecb7..7079cb93b14 100644 --- a/dlls/xmllite/writer.c +++ b/dlls/xmllite/writer.c @@ -620,24 +620,24 @@ static HRESULT writeroutput_flush_stream(xmlwriteroutput *output) return S_OK; }
-static HRESULT write_encoding_bom(xmlwriter *writer) +static void write_encoding_bom(xmlwriter *writer, HRESULT *hr) { - if (!writer->bom || writer->bomwritten) return S_OK; + if (FAILED(*hr)) return; + if (!writer->bom || writer->bomwritten) return;
if (writer->output->encoding == XmlEncoding_UTF16) { static const char utf16bom[] = {0xff, 0xfe}; struct output_buffer *buffer = &writer->output->buffer; int len = sizeof(utf16bom); - HRESULT hr;
- hr = grow_output_buffer(writer->output, len); - if (FAILED(hr)) return hr; + if (FAILED(*hr = grow_output_buffer(writer->output, len))) + return; + memcpy(buffer->data + buffer->written, utf16bom, len); buffer->written += len; }
writer->bomwritten = TRUE; - return S_OK; }
static const WCHAR *get_output_encoding_name(xmlwriteroutput *output) @@ -653,7 +653,7 @@ static HRESULT write_xmldecl(xmlwriter *writer, XmlStandalone standalone, HRESUL if (FAILED(*hr)) return *hr;
- write_encoding_bom(writer); + write_encoding_bom(writer, hr); writer->state = XmlWriterState_DocStarted;
if (writer->omitxmldecl) return S_OK; @@ -1433,7 +1433,7 @@ static HRESULT WINAPI xmlwriter_WriteElementString(IXmlWriter *iface, LPCWSTR pr return WR_E_XMLNSURIDECLARATION; }
- write_encoding_bom(This); + write_encoding_bom(This, &hr); write_node_indent(This, &hr);
write_output_buffer_char(This->output, '<'); @@ -1788,23 +1788,26 @@ static HRESULT WINAPI xmlwriter_WriteNodeShallow(IXmlWriter *iface, IXmlReader * static HRESULT WINAPI xmlwriter_WriteProcessingInstruction(IXmlWriter *iface, LPCWSTR name, LPCWSTR text) { - xmlwriter *This = impl_from_IXmlWriter(iface); + xmlwriter *writer = impl_from_IXmlWriter(iface); HRESULT hr = S_OK; + BOOL xmldecl;
- TRACE("(%p)->(%s %s)\n", This, wine_dbgstr_w(name), wine_dbgstr_w(text)); + TRACE("%p, %s, %s.\n", iface, wine_dbgstr_w(name), wine_dbgstr_w(text));
- switch (This->state) + xmldecl = !wcscmp(name, L"xml"); + + switch (writer->state) { case XmlWriterState_Initial: return E_UNEXPECTED; case XmlWriterState_InvalidEncoding: return MX_E_ENCODING; case XmlWriterState_DocStarted: - if (!wcscmp(name, L"xml")) + if (xmldecl) return WR_E_INVALIDACTION; break; case XmlWriterState_ElemStarted: - writer_close_starttag(This); + hr = writer_close_starttag(writer); break; case XmlWriterState_DocClosed: return WR_E_INVALIDACTION; @@ -1812,18 +1815,18 @@ static HRESULT WINAPI xmlwriter_WriteProcessingInstruction(IXmlWriter *iface, LP ; }
- write_encoding_bom(This); - write_node_indent(This, &hr); - write_output_buffer(This->output, L"<?", 2); - write_output_buffer(This->output, name, -1); - write_output_buffer_char(This->output, ' '); - write_output_buffer(This->output, text, -1); - write_output_buffer(This->output, L"?>", 2); + write_encoding_bom(writer, &hr); + write_node_indent(writer, &hr); + write_output(writer, L"<?", 2, &hr); + write_output(writer, name, -1, &hr); + write_output(writer, L" ", 1, &hr); + write_output(writer, text, -1, &hr); + write_output(writer, L"?>", 2, &hr);
- if (!wcscmp(name, L"xml")) - This->state = XmlWriterState_PIDocStarted; + if (xmldecl) + writer->state = XmlWriterState_PIDocStarted;
- return S_OK; + return hr; }
static HRESULT WINAPI xmlwriter_WriteQualifiedName(IXmlWriter *iface, LPCWSTR pwszLocalName, @@ -2009,7 +2012,7 @@ static HRESULT WINAPI xmlwriter_WriteStartElement(IXmlWriter *iface, LPCWSTR pre if (!element) return E_OUTOFMEMORY;
- write_encoding_bom(This); + write_encoding_bom(This, &hr); write_node_indent(This, &hr);
This->state = XmlWriterState_ElemStarted;
From: Nikolay Sivov nsivov@codeweavers.com
Should have been removed in d423c76ca8e.
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/xmllite/writer.c | 5 ----- 1 file changed, 5 deletions(-)
diff --git a/dlls/xmllite/writer.c b/dlls/xmllite/writer.c index 7079cb93b14..90ac69d565b 100644 --- a/dlls/xmllite/writer.c +++ b/dlls/xmllite/writer.c @@ -2118,11 +2118,6 @@ static HRESULT WINAPI xmlwriter_WriteWhitespace(IXmlWriter *iface, LPCWSTR text) return WR_E_INVALIDACTION; }
- while (text[length]) - { - if (!is_wchar_space(text[length])) return WR_E_NONWHITESPACE; - length++; - } if (SUCCEEDED(hr) && !is_valid_whitespace(text, &length)) hr = WR_E_NONWHITESPACE;
From: Nikolay Sivov nsivov@codeweavers.com
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/xmllite/writer.c | 47 ++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 19 deletions(-)
diff --git a/dlls/xmllite/writer.c b/dlls/xmllite/writer.c index 90ac69d565b..1bc9f64258c 100644 --- a/dlls/xmllite/writer.c +++ b/dlls/xmllite/writer.c @@ -541,6 +541,16 @@ static HRESULT write_output(xmlwriter *writer, const WCHAR *data, int len, HRESU return *hr; }
+static HRESULT write_output_quoted(xmlwriter *writer, const WCHAR *data, int len, HRESULT *hr) +{ + write_output(writer, L""", 1, hr); + if (!is_empty_string(data)) + write_output(writer, data, len, hr); + write_output(writer, L""", 1, hr); + + return *hr; +} + static HRESULT write_output_buffer_char(xmlwriteroutput *output, WCHAR ch) { return write_output_buffer(output, &ch, 1); @@ -663,7 +673,7 @@ static HRESULT write_xmldecl(xmlwriter *writer, XmlStandalone standalone, HRESUL
/* encoding */ write_output(writer, L" encoding=", 10, hr); - write_output_buffer_quoted(writer->output, get_output_encoding_name(writer->output), -1); + write_output_quoted(writer, get_output_encoding_name(writer->output), -1, hr);
/* standalone */ if (standalone == XmlStandalone_Omit) @@ -1325,14 +1335,14 @@ static HRESULT WINAPI xmlwriter_WriteComment(IXmlWriter *iface, LPCWSTR comment) static HRESULT WINAPI xmlwriter_WriteDocType(IXmlWriter *iface, LPCWSTR name, LPCWSTR pubid, LPCWSTR sysid, LPCWSTR subset) { - xmlwriter *This = impl_from_IXmlWriter(iface); + xmlwriter *writer = impl_from_IXmlWriter(iface); unsigned int name_len, pubid_len; HRESULT hr;
- TRACE("(%p)->(%s %s %s %s)\n", This, wine_dbgstr_w(name), wine_dbgstr_w(pubid), wine_dbgstr_w(sysid), + TRACE("%p, %s, %s, %s, %s.\n", iface, wine_dbgstr_w(name), wine_dbgstr_w(pubid), wine_dbgstr_w(sysid), wine_dbgstr_w(subset));
- switch (This->state) + switch (writer->state) { case XmlWriterState_Initial: return E_UNEXPECTED; @@ -1354,34 +1364,33 @@ static HRESULT WINAPI xmlwriter_WriteDocType(IXmlWriter *iface, LPCWSTR name, LP if (FAILED(hr = is_valid_pubid(pubid, &pubid_len))) return hr;
- write_output_buffer(This->output, L"<!DOCTYPE ", 10); - write_output_buffer(This->output, name, name_len); + write_output(writer, L"<!DOCTYPE ", 10, &hr); + write_output(writer, name, name_len, &hr);
if (pubid) { - write_output_buffer(This->output, L" PUBLIC ", 8); - write_output_buffer_quoted(This->output, pubid, pubid_len); - write_output_buffer_char(This->output, ' '); - write_output_buffer_quoted(This->output, sysid, -1); + write_output(writer, L" PUBLIC ", 8, &hr); + write_output_quoted(writer, pubid, pubid_len, &hr); + write_output(writer, L" ", 1, &hr); + write_output_quoted(writer, sysid, -1, &hr); } else if (sysid) { - write_output_buffer(This->output, L" SYSTEM ", 8); - write_output_buffer_quoted(This->output, sysid, -1); + write_output(writer, L" SYSTEM ", 8, &hr); + write_output_quoted(writer, sysid, -1, &hr); }
if (subset) { - write_output_buffer_char(This->output, ' '); - write_output_buffer_char(This->output, '['); - write_output_buffer(This->output, subset, -1); - write_output_buffer_char(This->output, ']'); + write_output(writer, L" [", 2, &hr); + write_output(writer, subset, -1, &hr); + write_output(writer, L"]", 1, &hr); } - write_output_buffer_char(This->output, '>'); + write_output(writer, L">", 1, &hr);
- This->state = XmlWriterState_Content; + writer->state = XmlWriterState_Content;
- return S_OK; + return hr; }
static HRESULT WINAPI xmlwriter_WriteElementString(IXmlWriter *iface, LPCWSTR prefix,
From: Nikolay Sivov nsivov@codeweavers.com
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/xmllite/writer.c | 57 +++++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 24 deletions(-)
diff --git a/dlls/xmllite/writer.c b/dlls/xmllite/writer.c index 1bc9f64258c..d715b5db914 100644 --- a/dlls/xmllite/writer.c +++ b/dlls/xmllite/writer.c @@ -690,7 +690,7 @@ static HRESULT write_xmldecl(xmlwriter *writer, XmlStandalone standalone, HRESUL return *hr; }
-static void writer_output_ns(xmlwriter *writer, struct element *element) +static void writer_output_ns(xmlwriter *writer, const struct element *element) { struct ns *ns;
@@ -1474,6 +1474,30 @@ static HRESULT WINAPI xmlwriter_WriteElementString(IXmlWriter *iface, LPCWSTR pr return S_OK; }
+static HRESULT write_end_element(xmlwriter *writer, const struct element *element) +{ + HRESULT hr = S_OK; + + writer_dec_indent(writer); + + if (writer->starttagopen) + { + writer_output_ns(writer, element); + write_output(writer, L" />", 3, &hr); + writer->starttagopen = 0; + } + else + { + /* Write full end tag. */ + write_node_indent(writer, &hr); + write_output(writer, L"</", 2, &hr); + write_output(writer, element->qname, element->len, &hr); + write_output(writer, L">", 1, &hr); + } + + return hr; +} + static HRESULT WINAPI xmlwriter_WriteEndDocument(IXmlWriter *iface) { xmlwriter *This = impl_from_IXmlWriter(iface); @@ -1504,19 +1528,19 @@ static HRESULT WINAPI xmlwriter_WriteEndDocument(IXmlWriter *iface)
static HRESULT WINAPI xmlwriter_WriteEndElement(IXmlWriter *iface) { - xmlwriter *This = impl_from_IXmlWriter(iface); + xmlwriter *writer = impl_from_IXmlWriter(iface); struct element *element; HRESULT hr = S_OK;
- TRACE("%p\n", This); + TRACE("%p.\n", iface);
- switch (This->state) + switch (writer->state) { case XmlWriterState_Initial: return E_UNEXPECTED; case XmlWriterState_Ready: case XmlWriterState_DocClosed: - This->state = XmlWriterState_DocClosed; + writer->state = XmlWriterState_DocClosed; return WR_E_INVALIDACTION; case XmlWriterState_InvalidEncoding: return MX_E_ENCODING; @@ -1524,29 +1548,14 @@ static HRESULT WINAPI xmlwriter_WriteEndElement(IXmlWriter *iface) ; }
- element = pop_element(This); + element = pop_element(writer); if (!element) return WR_E_INVALIDACTION;
- writer_dec_indent(This); - - if (This->starttagopen) - { - writer_output_ns(This, element); - write_output_buffer(This->output, L" />", 3); - This->starttagopen = 0; - } - else - { - /* Write full end tag. */ - write_node_indent(This, &hr); - write_output_buffer(This->output, L"</", 2); - write_output_buffer(This->output, element->qname, element->len); - write_output_buffer_char(This->output, '>'); - } - writer_free_element(This, element); + hr = write_end_element(writer, element); + writer_free_element(writer, element);
- return S_OK; + return hr; }
static HRESULT WINAPI xmlwriter_WriteEntityRef(IXmlWriter *iface, LPCWSTR pwszName)
From: Nikolay Sivov nsivov@codeweavers.com
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/xmllite/writer.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-)
diff --git a/dlls/xmllite/writer.c b/dlls/xmllite/writer.c index d715b5db914..fa6665d15f5 100644 --- a/dlls/xmllite/writer.c +++ b/dlls/xmllite/writer.c @@ -1500,17 +1500,19 @@ static HRESULT write_end_element(xmlwriter *writer, const struct element *elemen
static HRESULT WINAPI xmlwriter_WriteEndDocument(IXmlWriter *iface) { - xmlwriter *This = impl_from_IXmlWriter(iface); + xmlwriter *writer = impl_from_IXmlWriter(iface); + struct element *element; + HRESULT hr = S_OK;
- TRACE("%p\n", This); + TRACE("%p.\n", iface);
- switch (This->state) + switch (writer->state) { case XmlWriterState_Initial: return E_UNEXPECTED; case XmlWriterState_Ready: case XmlWriterState_DocClosed: - This->state = XmlWriterState_DocClosed; + writer->state = XmlWriterState_DocClosed; return WR_E_INVALIDACTION; case XmlWriterState_InvalidEncoding: return MX_E_ENCODING; @@ -1518,12 +1520,15 @@ static HRESULT WINAPI xmlwriter_WriteEndDocument(IXmlWriter *iface) ; }
- /* empty element stack */ - while (IXmlWriter_WriteEndElement(iface) == S_OK) - ; + /* Empty element stack */ + while (hr == S_OK && (element = pop_element(writer))) + { + hr = write_end_element(writer, element); + writer_free_element(writer, element); + }
- This->state = XmlWriterState_DocClosed; - return S_OK; + writer->state = XmlWriterState_DocClosed; + return hr; }
static HRESULT WINAPI xmlwriter_WriteEndElement(IXmlWriter *iface)