[PATCH 1/4] wsdapi: Add support for writing XML attributes.
Huw Davies
huw at codeweavers.com
Mon Mar 26 04:02:08 CDT 2018
On Fri, Mar 23, 2018 at 10:04:47PM +0000, Owen Rudge wrote:
> Signed-off-by: Owen Rudge <orudge at codeweavers.com>
> ---
> dlls/wsdapi/soap.c | 66
> +++++++++++++++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 65 insertions(+), 1 deletion(-)
>
>
> diff --git a/dlls/wsdapi/soap.c b/dlls/wsdapi/soap.c
> index 40edd15463..ba0484c274 100644
> --- a/dlls/wsdapi/soap.c
> +++ b/dlls/wsdapi/soap.c
> @@ -130,9 +130,66 @@ static inline void free_xml_string(WS_XML_STRING *value)
> heap_free(value);
> }
>
> +static BOOL write_xml_attribute(WSDXML_ATTRIBUTE *attribute, WS_XML_WRITER *writer)
> +{
> + WS_XML_STRING *local_name = NULL, *element_ns = NULL, *ns_prefix = NULL;
> + WS_XML_UTF16_TEXT utf16_text;
> + BOOL retVal = FALSE;
> + int text_len;
> + HRESULT ret;
Usually if you've got two different 'return' variables then it's a
good sign something can be improved. This is another case where
the function could return HRESULT.
> +
> + if (attribute == NULL)
> + return TRUE;
> +
> + /* Start the attribute */
> + local_name = populate_xml_string(attribute->Name->LocalName);
> + if (local_name == NULL) goto cleanup;
> +
> + if (attribute->Name->Space == NULL)
> + {
> + element_ns = populate_xml_string(emptyString);
> + if (element_ns == NULL) goto cleanup;
> +
> + ns_prefix = NULL;
> + }
> + else
> + {
> + element_ns = populate_xml_string(attribute->Name->Space->Uri);
> + if (element_ns == NULL) goto cleanup;
> +
> + ns_prefix = populate_xml_string(attribute->Name->Space->PreferredPrefix);
> + if (ns_prefix == NULL) goto cleanup;
> + }
> +
> + ret = WsWriteStartAttribute(writer, ns_prefix, local_name, element_ns, FALSE, NULL);
> + if (FAILED(ret)) goto cleanup;
> +
> + text_len = lstrlenW(attribute->Value);
> +
> + utf16_text.text.textType = WS_XML_TEXT_TYPE_UTF16;
> + utf16_text.bytes = (BYTE *)attribute->Value;
> + utf16_text.byteCount = min(WSD_MAX_TEXT_LENGTH, text_len) * sizeof(WCHAR);
> +
> + ret = WsWriteText(writer, (WS_XML_TEXT *)&utf16_text, NULL);
> + if (FAILED(ret)) goto cleanup;
> +
> + ret = WsWriteEndAttribute(writer, NULL);
> + if (FAILED(ret)) goto cleanup;
> +
> + retVal = TRUE;
> +
> +cleanup:
> + free_xml_string(local_name);
> + free_xml_string(element_ns);
> + free_xml_string(ns_prefix);
> +
> + return retVal;
> +}
> +
> static BOOL write_xml_element(WSDXML_ELEMENT *element, WS_XML_WRITER *writer)
> {
> WS_XML_STRING *local_name = NULL, *element_ns = NULL, *ns_prefix = NULL;
> + WSDXML_ATTRIBUTE *current_attribute;
> WS_XML_UTF16_TEXT utf16_text;
> WSDXML_NODE *current_child;
> WSDXML_TEXT *node_as_text;
> @@ -156,7 +213,14 @@ static BOOL write_xml_element(WSDXML_ELEMENT *element, WS_XML_WRITER *writer)
> ret = WsWriteStartElement(writer, ns_prefix, local_name, element_ns, NULL);
> if (FAILED(ret)) goto cleanup;
>
> - /* TODO: Write attributes */
> + /* Write attributes */
> + current_attribute = element->FirstAttribute;
> +
> + while (current_attribute != NULL)
> + {
> + if (!write_xml_attribute(current_attribute, writer)) goto cleanup;
'ret' would be set to the return value and tested here.
> + current_attribute = current_attribute->Next;
> + }
>
> /* Write child elements */
> current_child = element->FirstChild;
>
More information about the wine-devel
mailing list