static HRESULT write_xmldecl(xmlwriter *writer, XmlStandalone standalone) { static const WCHAR versionW[] = {'<','?','x','m','l',' ','v','e','r','s','i','o','n','=','"','1','.','0','"'}; static const WCHAR encodingW[] = {' ','e','n','c','o','d','i','n','g','='}; write_encoding_bom(writer); writer->state = XmlWriterState_DocStarted; if (writer->omitxmldecl) return S_OK; /* version */ write_output_buffer(writer->output, versionW, ARRAY_SIZE(versionW)); /* encoding */ write_output_buffer(writer->output, encodingW, ARRAY_SIZE(encodingW)); write_output_buffer_quoted(writer->output, get_encoding_name(writer->output->encoding), -1); /* standalone */ if (standalone == XmlStandalone_Omit) write_output_buffer(writer->output, closepiW, ARRAY_SIZE(closepiW)); else { static const WCHAR standaloneW[] = {' ','s','t','a','n','d','a','l','o','n','e','=','\"'}; static const WCHAR yesW[] = {'y','e','s','\"','?','>'}; static const WCHAR noW[] = {'n','o','\"','?','>'}; write_output_buffer(writer->output, standaloneW, ARRAY_SIZE(standaloneW)); if (standalone == XmlStandalone_Yes) write_output_buffer(writer->output, yesW, ARRAY_SIZE(yesW)); else write_output_buffer(writer->output, noW, ARRAY_SIZE(noW)); } return S_OK; }
static HRESULT WINAPI xmlwriter_WriteStartElement(IXmlWriter *iface, LPCWSTR prefix, LPCWSTR local_name, LPCWSTR uri) { xmlwriter *This = impl_from_IXmlWriter(iface); struct element *element; TRACE("(%p)->(%s %s %s)\n", This, wine_dbgstr_w(prefix), wine_dbgstr_w(local_name), wine_dbgstr_w(uri)); if (This->state == XmlWriterState_Initial) return E_UNEXPECTED; if (!local_name) return E_INVALIDARG; /* close pending element */ if (This->starttagopen) write_output_buffer(This->output, gtW, ARRAY_SIZE(gtW)); element = alloc_element(This, prefix, local_name); if (!element) return E_OUTOFMEMORY; write_encoding_bom(This); This->state = XmlWriterState_ElemStarted; This->starttagopen = TRUE; push_element(This, element); write_output_buffer(This->output, ltW, ARRAY_SIZE(ltW)); write_output_qname(This->output, prefix, local_name); 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_WriteStartDocument(IXmlWriter *iface, XmlStandalone standalone) { static const WCHAR versionW[] = {'<','?','x','m','l',' ','v','e','r','s','i','o','n','=','"','1','.','0','"'}; static const WCHAR encodingW[] = {' ','e','n','c','o','d','i','n','g','='}; xmlwriter *This = impl_from_IXmlWriter(iface); TRACE("(%p)->(%d)\n", This, standalone); switch (This->state) { case XmlWriterState_Initial: return E_UNEXPECTED; case XmlWriterState_PIDocStarted: This->state = XmlWriterState_DocStarted; return S_OK; case XmlWriterState_DocStarted: case XmlWriterState_ElemStarted: case XmlWriterState_DocClosed: return WR_E_INVALIDACTION; default: ; } write_encoding_bom(This); This->state = XmlWriterState_DocStarted; if (This->omitxmldecl) return S_OK; /* version */ write_output_buffer(This->output, versionW, ARRAY_SIZE(versionW)); /* encoding */ write_output_buffer(This->output, encodingW, ARRAY_SIZE(encodingW)); write_output_buffer_quoted(This->output, get_encoding_name(This->output->encoding), -1); /* standalone */ if (standalone == XmlStandalone_Omit) write_output_buffer(This->output, closepiW, ARRAY_SIZE(closepiW)); else { static const WCHAR standaloneW[] = {' ','s','t','a','n','d','a','l','o','n','e','=','\"'}; static const WCHAR yesW[] = {'y','e','s','\"','?','>'}; static const WCHAR noW[] = {'n','o','\"','?','>'}; write_output_buffer(This->output, standaloneW, ARRAY_SIZE(standaloneW)); if (standalone == XmlStandalone_Yes) write_output_buffer(This->output, yesW, ARRAY_SIZE(yesW)); else write_output_buffer(This->output, noW, ARRAY_SIZE(noW)); } return S_OK; }
static HRESULT WINAPI xmlwriter_WriteProcessingInstruction(IXmlWriter *iface, LPCWSTR name, LPCWSTR text) { xmlwriter *This = impl_from_IXmlWriter(iface); static const WCHAR xmlW[] = {'x','m','l',0}; static const WCHAR openpiW[] = {'<','?'}; static const WCHAR spaceW[] = {' '}; TRACE("(%p)->(%s %s)\n", This, wine_dbgstr_w(name), wine_dbgstr_w(text)); switch (This->state) { case XmlWriterState_Initial: return E_UNEXPECTED; case XmlWriterState_DocStarted: if (!strcmpW(name, xmlW)) return WR_E_INVALIDACTION; break; case XmlWriterState_ElemStarted: case XmlWriterState_DocClosed: return WR_E_INVALIDACTION; default: ; } write_encoding_bom(This); write_output_buffer(This->output, openpiW, ARRAY_SIZE(openpiW)); write_output_buffer(This->output, name, -1); write_output_buffer(This->output, spaceW, ARRAY_SIZE(spaceW)); write_output_buffer(This->output, text, -1); write_output_buffer(This->output, closepiW, ARRAY_SIZE(closepiW)); if (!strcmpW(name, xmlW)) This->state = XmlWriterState_PIDocStarted; return S_OK; }
static HRESULT WINAPI xmlwriter_WriteStartElement(IXmlWriter *iface, LPCWSTR prefix, LPCWSTR local_name, LPCWSTR uri) { xmlwriter *This = impl_from_IXmlWriter(iface); TRACE("(%p)->(%s %s %s)\n", This, wine_dbgstr_w(prefix), wine_dbgstr_w(local_name), wine_dbgstr_w(uri)); if (This->state == XmlWriterState_Initial) return E_UNEXPECTED; if (!local_name) return E_INVALIDARG; if (This->state == XmlWriterState_ElemStarted) return WR_E_INVALIDACTION; write_encoding_bom(This); This->state = XmlWriterState_ElemStarted; This->starttagopen = TRUE; write_output_buffer(This->output, ltW, 1); write_output_qname(This->output, prefix, local_name); return S_OK; }