static HRESULT WINAPI xmlwriter_WriteCharEntity(IXmlWriter *iface, WCHAR ch) { static const WCHAR fmtW[] = {'&','#','x','%','x',';',0}; xmlwriter *This = impl_from_IXmlWriter(iface); WCHAR bufW[16]; TRACE("%p %#x\n", This, ch); switch (This->state) { case XmlWriterState_Initial: return E_UNEXPECTED; case XmlWriterState_ElemStarted: writer_close_starttag(This); break; case XmlWriterState_DocClosed: return WR_E_INVALIDACTION; default: ; } sprintfW(bufW, fmtW, ch); write_output_buffer(This->output, bufW, -1); return S_OK; }
static HRESULT WINAPI xmlwriter_WriteElementString(IXmlWriter *iface, LPCWSTR prefix, LPCWSTR local_name, LPCWSTR uri, LPCWSTR value) { xmlwriter *This = impl_from_IXmlWriter(iface); TRACE("(%p)->(%s %s %s %s)\n", This, wine_dbgstr_w(prefix), wine_dbgstr_w(local_name), wine_dbgstr_w(uri), wine_dbgstr_w(value)); switch (This->state) { case XmlWriterState_Initial: return E_UNEXPECTED; case XmlWriterState_ElemStarted: writer_close_starttag(This); break; default: ; } write_encoding_bom(This); write_output_buffer(This->output, ltW, ARRAY_SIZE(ltW)); write_output_qname(This->output, prefix, local_name); write_output_buffer(This->output, gtW, ARRAY_SIZE(gtW)); if (value) write_output_buffer(This->output, value, -1); write_output_buffer(This->output, closeelementW, ARRAY_SIZE(closeelementW)); write_output_qname(This->output, prefix, local_name); write_output_buffer(This->output, gtW, ARRAY_SIZE(gtW)); This->state = XmlWriterState_Content; return S_OK; }
static HRESULT WINAPI xmlwriter_WriteCData(IXmlWriter *iface, LPCWSTR data) { xmlwriter *This = impl_from_IXmlWriter(iface); int len; TRACE("%p %s\n", This, debugstr_w(data)); switch (This->state) { case XmlWriterState_Initial: return E_UNEXPECTED; case XmlWriterState_ElemStarted: writer_close_starttag(This); break; case XmlWriterState_Ready: case XmlWriterState_DocClosed: This->state = XmlWriterState_DocClosed; return WR_E_INVALIDACTION; default: ; } len = data ? strlenW(data) : 0; write_node_indent(This); if (!len) write_cdata_section(This->output, NULL, 0); else { static const WCHAR cdatacloseW[] = {']',']','>',0}; while (len) { const WCHAR *str = strstrW(data, cdatacloseW); if (str) { str += 2; write_cdata_section(This->output, data, str - data); len -= str - data; data = str; } else { write_cdata_section(This->output, data, len); break; } } } return S_OK; }
static HRESULT WINAPI xmlwriter_WriteComment(IXmlWriter *iface, LPCWSTR comment) { static const WCHAR copenW[] = {'<','!','-','-'}; static const WCHAR ccloseW[] = {'-','-','>'}; xmlwriter *This = impl_from_IXmlWriter(iface); TRACE("%p %s\n", This, debugstr_w(comment)); switch (This->state) { case XmlWriterState_Initial: return E_UNEXPECTED; case XmlWriterState_ElemStarted: writer_close_starttag(This); break; case XmlWriterState_DocClosed: return WR_E_INVALIDACTION; default: ; } write_node_indent(This); write_output_buffer(This->output, copenW, ARRAY_SIZE(copenW)); if (comment) { int len = strlenW(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 (comment[i] == '-' && (i + 1 < len) && comment[i+1] == '-') write_output_buffer(This->output, spaceW, ARRAY_SIZE(spaceW)); } } else write_output_buffer(This->output, comment, len); if (len && comment[len-1] == '-') write_output_buffer(This->output, spaceW, ARRAY_SIZE(spaceW)); } write_output_buffer(This->output, ccloseW, ARRAY_SIZE(ccloseW)); return S_OK; }
static HRESULT WINAPI xmlwriter_WriteFullEndElement(IXmlWriter *iface) { xmlwriter *This = impl_from_IXmlWriter(iface); struct element *element; TRACE("%p\n", This); switch (This->state) { case XmlWriterState_Initial: return E_UNEXPECTED; case XmlWriterState_Ready: case XmlWriterState_DocClosed: This->state = XmlWriterState_DocClosed; return WR_E_INVALIDACTION; default: ; } element = pop_element(This); if (!element) return WR_E_INVALIDACTION; writer_close_starttag(This); writer_dec_indent(This); /* don't force full end tag to the next line */ if (This->state == XmlWriterState_ElemStarted) This->state = XmlWriterState_Content; else write_node_indent(This); /* write full end tag */ write_output_buffer(This->output, closeelementW, ARRAY_SIZE(closeelementW)); write_output_buffer(This->output, element->qname, element->len); write_output_buffer(This->output, gtW, ARRAY_SIZE(gtW)); return S_OK; }