Partager via


Basic MSXML Utility Functions

The following utility functions are not considered native to the core operating system or core XML functionality. The full code example for writing an extension to the Applications snap-in uses some basic MSXML utility functions developed for this code example.

The following functions, in the Utility.h and Utility.cpp files, are used to encapsulate some of the MSXML functionality:

GetAttribute

Retrieves an attribute from the IXMLDOMDocument*

HRESULT GetAttribute( 
   IXMLDOMNode* pParent,
   LPCTSTR      szName, 
   CComBSTR&    bstrValue );

Parameters

  • pParent

    A pointer to the element from which to retrieve the attribute

  • szName

    The name of the attribute

  • bstrValue

    The string in which to return the attribute value

Return Values

The return value will be either a standard HRESULT error code or one of the following:

  • S_OK

    The attribute exists and its value has been stored in the bstrValue parameter.

  • S_FALSE

    The specified attribute was not found.

SetAttribute

Sets an attribute from the IXMLDOMDocument*

HRESULT SetAttribute( 
   IXMLDOMDocument* pDom,
   IXMLDOMNode*     pParent, 
   LPCTSTR          szName, 
   LPCTSTR          szValue );

Parameters

  • pDom

    A pointer to the document object

  • pParent

    A pointer to the element on which to set the attribute

  • szName

    The name of the attribute

  • szValue

    The value of the attribute

Return Value

The return value will be either a standard HRESULT error code or the following:

  • S_OK

    The attribute was successfully set.

AddElement

Adds an element to the IXMLDOMDocument*

HRESULT AddElement( 
   IXMLDOMDocument* pDom,
   IXMLDOMNode*     pParent,
   LPCTSTR          szName, 
   IXMLDOMNode**    ppNew );

Parameters

  • pDom

    A pointer to the document object

  • pParent

    A pointer to the element under which to add the new element

  • szName

    The name of the element

  • ppNew

    A pointer to the pointer in which the new element address will be stored. The caller must release this object.

Return Value

The return value will be either a standard HRESULT error code or the following:

  • S_OK

    The element was added successfully.

AllocOleStr

Allocates memory for a buffer to receive allocated text.

Note

Although, normally, the caller must release the buffer, this function passes the buffer to the Microsoft Management Console (MMC) and it is subsequently released by the MMC.

 

Note

This utility function differs from CSnapinAbout::AllocOleStr() which is defined in the full code example provided in the About.cpp file.

 

HRESULT AllocOleStr( 
   LPOLESTR* lppDest,
   LPCWSTR   szwBuffer );

Parameters

  • lppDest

    A pointer to the buffer that will receive the allocated text. The caller must release this buffer.

  • szwBuffer

    The text to be copied into lppDest

Return Value

The return value will be either a standard HRESULT error code or one the following:

  • S_OK

    The string was allocated and copied successfully.