다음을 통해 공유


WriteStartElement

 

Writes out the specified start tag and associates it with the specified namespace.

Syntax

  
HRESULT WriteStartElement (  
    const WCHAR * pwszPrefix,  
    const WCHAR * pwszLocalname,  
    const WCHAR * pwszNamespaceUri);  

Arguments

pwszPrefix
The namespace prefix of the element. A NULL value is equivalent to an empty string.

pwszLocalname
The local name of the element. A NULL value is not valid.

pwszNamespaceUri
The namespace URI of the element. NULL is equivalent to an empty string.

Return Value

Returns S_OK if no error is generated.

Remarks

After calling this method, an application can either write attributes or write content. To write content, use WriteComment, WriteString, or WriteStartElement.

A program must call WriteEndElement to close the element. The WriteEndElement method might write a full end tag, or it might close the element using the short form. The WriteFullEndElement method always writes a full end tag.

For example, the following code creates an element:

if (FAILED(hr = pWriter->WriteStartElement(NULL, L"containsEntity", NULL)))  
{  
    wprintf(L"Error, Method: WriteStartElement, error is %08.8lx", hr);  
    return -1;  
}  
if (FAILED(hr = pWriter->WriteEntityRef(L"myEntity")))  
{  
    wprintf(L"Error, Method: WriteEntityRef, error is %08.8lx", hr);  
    return -1;  
}  
if (FAILED(hr = pWriter->WriteEndElement()))  
{  
    wprintf(L"Error, Method: WriteEndElement, error is %08.8lx", hr);  
    return -1;  
}  

For a more detailed example of the WriteStartElement method, see Writing an XML Document Using XmlLite.

Requirements

Header: XmlLite.h

Library: XmlLite.lib

See Also

IXmlWriter Methods