WriteAttributeString (IXmlWriterLite)

 

Writes an attribute.

Syntax

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

Arguments

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

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

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

cwszValue
The length of the value in wide-character units.

Return Value

Returns S_OK if no error is generated.

Remarks

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.

Example

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.

Requirements

Header: XmlLite.h

Library: XmlLite.lib

See Also

IXmlWriterLite Methods