Share via


WriteAttributes (Compact 7)

3/12/2014

This method copies attributes from the specified source IXmlReader to the IXmlWriter.

Syntax

HRESULT WriteAttributes (
    IXmlReader* pReader, 
    BOOL fWriteDefaultAttributes
);

Arguments

  • pReader
    The reader from which to copy the attributes. This argument cannot be NULL.
  • fWriteDefaultAttributes
    Specifies whether to also copy the default attributes from the reader.

Return Value

This method returns S_OK if no error is generated.

Remarks

The attributes copied depend on the current position of the reader:

  • If the reader is positioned on an element node, this method copies all the attributes contained by the element.
  • If the reader is positioned on an attribute node, this method copies the current attribute and the rest of the attributes contained by the element.
  • If the reader is positioned on an XmlNodeType_XmlDeclaration, this method writes out all the attributes of the declaration.
  • If the reader is positioned on any other node type, calling this method has no effect.

The following code writes out all the attributes located at the current position in the specified reader:

if (FAILED(hr = pWriter->WriteStartElement(NULL, L"sub", NULL)))
{
    wprintf(L"Error, Method: WriteStartElement, error is %08.8lx", hr);
    return -1;
}
if (FAILED(hr = pWriter->WriteAttributeString(NULL, L"myAttr", NULL,
                                              L"1234")))
{
    wprintf(L"Error, Method: WriteAttributeString, error is %08.8lx", hr);
    return -1;
}

See Also

Reference

IXmlWriter Methods
IXmlReader
IXmlWriter
IXmlWriter Properties