CXMLTool![]()
[ XMLSample | Source | Keywords | Summary | Ancestors | All Members | Descendants ]
![]()
Back to the top of CXMLTool
This class provides high-level access to the Microsoft's XMLDOM Document Object Model (parser/analyser for XML documents). It wraps the complex APIs to make them easy to use.
Most functions implemented here are very simple. They are examples of using XMLDOM API in VC++, as well as integration with MFC's data type CString (if your application doesn't use MFC, you better not use CXMLTool).
Back to the top of CXMLTool
This class has only static function members: you can call them directly.
Back to the top of CXMLTool
// =======================================================================
// Transform XML with XSL
// =======================================================================
BSTR pBXMLString = NULL;
VARIANT vObject;
IXMLDOMDocument *pOutputXMLDocument = NULL;
IDispatch *pDisp = NULL;
hResult = CoCreateInstance(CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, IID_IXMLDOMDocument, (void**)&pOutputXMLDocument);
hResult = pOutputXMLDocument->QueryInterface(IID_IDispatch, (void **)&pDisp); vObject.vt = VT_DISPATCH; vObject.pdispVal = pDisp;
// Use transformNodeToObject hResult = pXMLDocument->transformNodeToObject(pXMLStyle, vObject);
if (!FAILED(hResult)) { CXMLTool::MakeXMLBuffer(pOutputXMLDocument, szXMLString, nIndentStep); }
// =======================================================================
// Print the transformed string
// =======================================================================
cout << (LPCTSTR)szXMLString;
Back to the top of CXMLTool
Author Emmanuel KARTMANN
Date Monday 1/24/00 20:19:55 AM
Back to the top of CXMLTool
Extensible Markup Language (XML) at Microsoft's Web Site
Back to the top of CXMLTool
Purpose: Build the XML source (flat text file) of an XMLDOM
(tree data structure).
Parameters:
Description : This function call recursive function
MakeXMLBuffer() below.
CAUTION: this function doesn't generate
standard XML. It's rather a good example on
how to walk the XML tree to produce your own
text file format. For example, empty tags
are not terminated by / (e.g. "<EMPTY/>").
Instead, they are shown by a start and end tag
(i.e. "<EMPTY></EMPTY>").
ADMINISTRATIVE
SEE ALSO
Using the XMLDOMDocument Object
Using the XMLDOMNode Object
Using the XMLDOMNodeList Object
Using the XMLDOMNamedNodeMap Object
![]()
HRESULT MakeXMLBuffer(IXMLDOMDocument *pXMLDOMDocument, CString &szXMLBuffer, int nIndentStep);
Return value : HRESULT = S_OK for success,
otherwise an error occured
static HRESULT MakeXMLBuffer(IXMLDOMDocument *pXMLDOMDocument, CString &szXMLBuffer, int nIndentStep);
Back to the top of CXMLTool
Purpose: Build the XML source (flat text file) of an XMLDOM node (and its children)
Parameters:
Description : This function call itself (recursive).
static HRESULT MakeXMLBuffer(IXMLDOMNode *pParentNode, CString &szXMLBuffer, int nIndentValue, int nIndentStep);
Back to the top of CXMLTool
![]()
HRESULT CreateXMLNode(IXMLDOMDocument* pDoc, DOMNodeType type, BSTR bstrName, IXMLDOMNode **node);
Purpose: create a node in an XML Document tree
Parameters:
Description :
static HRESULT CreateXMLNode(IXMLDOMDocument* pDoc, DOMNodeType type, BSTR bstrName, IXMLDOMNode **node);
Back to the top of CXMLTool
![]()
HRESULT DeleteXMLNode(IXMLDOMNode *pNode);
Purpose: delete a node
Parameters:
Description :
static HRESULT DeleteXMLNode(IXMLDOMNode *pNode);
Back to the top of CXMLTool
Purpose: create a node beneath (child of) an existing node
Parameters:
Description : calls
static HRESULT CreateXMLNodeChild(IXMLDOMDocument* pDoc, DOMNodeType type, LPCTSTR lpszName, IXMLDOMNode *pParentNode, IXMLDOMNode **pNode);
Back to the top of CXMLTool
Purpose: create a TEXT node beneath (child of) an existing node
Parameters:
Description : calls CreateXMLNodeChild() twice: once for the node, once for the TEXT (which is a child node of type TEXT).
static HRESULT CreateXMLNodeChildText(IXMLDOMDocument* pDoc, DOMNodeType type, LPCTSTR lpszName, IXMLDOMNode *pParentNode, LPCTSTR lpszNodeText, IXMLDOMNode **pNode);
Back to the top of CXMLTool
Purpose: load an XML document from a buffer in memory
Parameters:
Description : calls IXMLDOMDocument::loadXML()
static BOOL LoadXMLDocumentFromMemory(IXMLDOMDocument *pXMLDOMDocument, BSTR pBXMLText, char *lpszErrorMessage);
Back to the top of CXMLTool
![]()
BOOL CheckTagPresence(IXMLDOMDocument *pXMLDOMDocument, LPCTSTR lpszTagName);
Purpose: check if a tag is present in an XML document
Parameters:
Description : calls IXMLDOMDocument::getElementsByTagName() and IXMLDOMNodeList::get_length().
static BOOL CheckTagPresence(IXMLDOMDocument *pXMLDOMDocument, LPCTSTR lpszTagName);
Back to the top of CXMLTool
![]()
BOOL GetTagText(IXMLDOMDocument *pXMLDOMDocument, LPCTSTR lpszTagName, CString &szTagText);
Purpose: returns the text within a tag
Parameters:
Description : calls IXMLDOMDocument::getElementsByTagName() and IXMLDOMNode::get_text().
If several nodes have the given name, the text of the first node is returned.
static BOOL GetTagText(IXMLDOMDocument *pXMLDOMDocument, LPCTSTR lpszTagName, CString &szTagText);
Back to the top of CXMLTool
Purpose: returns an XML parsing error
Parameters:
Description : calls IXMLDOMDocument::get_parseError() and then IXMLDOMParseError::get_errorCode(), IXMLDOMParseError::get_reason(), IXMLDOMParseError::get_line()
static BOOL GetXMLParseError(IXMLDOMDocument *pXMLDOMDocument, CString &szErrorReason, long &nErrorCode, long &nLineNumber);
Back to the top of CXMLTool
![]()
BOOL GetChildTagText(IXMLDOMNode *pParentNode, LPCTSTR lpszTagName, CString &szTagText);
Purpose: get text within a tag beneath (child of) a given node
Parameters:
Description : calls IXMLDOMNode::selectSingleNode() and IXMLDOMNode::get_text()
static BOOL GetChildTagText(IXMLDOMNode *pParentNode, LPCTSTR lpszTagName, CString &szTagText);
Back to the top of CXMLTool
![]()
BOOL GetTopLevelNode(IXMLDOMDocument *pXMDOMDocument, IXMLDOMNode **ppTopLevelNode);
Purpose: returns the top-level node of an XML document
Parameters:
Description : calls IXMLDOMDocument::get_documentElement() and QueryInterface(IID_IXMLDOMNode, ...).
static BOOL GetTopLevelNode(IXMLDOMDocument *pXMDOMDocument, IXMLDOMNode **ppTopLevelNode);
Back to the top of CXMLTool
Purpose: Copy (recursively) a node
Parameters:
Description : calls IXMLDOMNode::cloneNode() to copy node (recursive) and call IXMLDOMNode::appendChild to put the cloned tree underneath destination node.
static BOOL CopyNode(IXMLDOMNode *pSourceNode, IXMLDOMNode *pDestinationNode, IXMLDOMDocument *pXMLDOMDocument);
Back to the top of CXMLTool
Purpose: returns the first node with a given name
Parameters:
Description : calls IXMLDOMDocument::getElementsByTagName() and picks the first element in the returned list.
static BOOL GetFirstNodeWithName(IXMLDOMDocument *pXMLDOMDocument, LPCTSTR lpszNodeName, IXMLDOMNode **ppNode);
Back to the top of CXMLTool
![]()
CString GetTagName(IXMLDOMNode *pNode);
Purpose: return the name of the tag in a node
Parameters:
Description : calls IXMLDOMNode::get_nodeName()
static CString GetTagName(IXMLDOMNode *pNode);
Back to the top of CXMLTool
![]()
CString GetXMLPath(IXMLDOMNode *pNode);
Purpose: return the full path of an XML node
Parameters:
Description : calls IXMLDOMNode::get_nodeName() on every parent node (up to the top-level node) and build the fully qualified name.
static CString GetXMLPath(IXMLDOMNode *pNode);
Back to the top of CXMLTool
Back to the top of CXMLTool
Back to the top of CXMLTool
Back to the top of CXMLTool
![]()
Report problems to jkotula@stratasys.com