WriteAttributeString (IXmlWriterLite)


Writes an attribute.


HRESULT WriteAttributeString (const WCHAR * pwszQName,  
    UINT cwszQName,  
    const WCHAR * pwszValue  
    UINT cwszValue);  


The qualified name for the attribute. NULL causes an error.

The length of the attribute name in wide-character units.

The value of the attribute. NULL is equivalent to an empty string.

The length of the value in wide-character units.

Return Value

Returns S_OK if no error is generated.


Creates an attribute in the current element by using pwszQName as the qualified name for the attribute and pwszValue as the attribute value. WriteAttributeString performs no validation that the attribute name or value is allowed in the current element. When the attribute name is xmlns or xmlns:prefix, this method creates the attribute as a namespace declaration. This associates the default namespace or, if present, the declared prefix with the namespace URI specified in pwszValue. Because IXmlWriterLite performs no namespace validation, you must be careful not to create duplicate or conflicting namespace declarations.


The following example writes out a start element and an attribute string:

WCHAR tag = L"sub";  
UINT tag_len = 3;  
WCHAR attr = L"myAttr";  
UINT attr_len = 6;  
WCHAR value = L"1234";  
UINT value_len = 4;  
if (FAILED(hr = pWriter->WriteStartElement(tag, tag_len)))  
    wprintf(L"Error, Method: WriteStartElement, error is %08.8lx", hr);  
    return -1;  
if (FAILED(hr = pWriter->WriteAttributeString(attr, attr_len,  
                                              value, value_len)))  
    wprintf(L"Error, Method: WriteAttributeString, error is %08.8lx", hr);  
    return -1;  

For a complete code example that uses WriteAttributeString, see Universal Windows Platform (UWP) XmlLite sample.


Header: XmlLite.h

Library: XmlLite.lib

See Also

IXmlWriterLite Methods