Share via


CreateXmlWriter

 

Creates a new IXmlWriter or IXmlWriterLite.

Syntax

  
HRESULT CreateXmlWriter ([in] REFIID riid, [out] void ** ppvObject, [in] IMalloc * pMalloc);  

Arguments

riid
The reference ID.

ppvObject
An out argument that returns the writer.

pMalloc
An IMalloc implementation specified by the user. This parameter can be NULL.

Return Value

Returns S_OK if no error is generated.

Remarks

This constructor is used to create the writer. If no IMalloc is specified, the default implementation of IMalloc is used.

The following example shows the declaration of an IXmlWriter object; the declaration and creation of an IStream object; and the call to CreateXmlWriter. You can declare pWriter as CComPtr<IXmlWriterLite> instead, and invoke CreateXmlWriter by using IXmlWriterLite to take advantage of its faster output:

// This code is excerpted from XmlLiteNamespaceWriter1.cpp.  
int _tmain(int argc, _TCHAR* argv[])  
{  
    HRESULT hr;  
    CComPtr<IStream> pOutFileStream;  
    CComPtr<IXmlWriter> pWriter;  
  
    if (argc != 2)  
    {  
        printf("Usage: XmlLiteNamespaceWriter1.exe name-of-output-file\n");  
        return 0;  
    }  
  
    //Open writeable output stream  
    if (FAILED(hr = FileStream::OpenFile(argv[1], &pOutFileStream, TRUE)))  
    {  
        wprintf(L"Error creating file writer, error is %08.8lx", hr);  
        return -1;  
    }  
  
    if (FAILED(hr = CreateXmlWriter(__uuidof(IXmlWriter),(void**) &pWriter, NULL)))  
    {  
        wprintf(L"Error creating xml writer, error is %08.8lx", hr);  
        return -1;  
    }  
  
    if (FAILED(hr = pWriter->SetOutput(pOutFileStream)))  
    {  
        wprintf(L"Error setting output for writer, error is %08.8lx", hr);  
        return -1;  
    }  

Requirements

Header: XmlLite.h

Library: XmlLite.lib

See Also

IXmlReader Functions
IXmlWriter
IXmlWriterLite