本文整理汇总了C++中msxml2::IXMLDOMNode::get_nodeTypeString方法的典型用法代码示例。如果您正苦于以下问题:C++ IXMLDOMNode::get_nodeTypeString方法的具体用法?C++ IXMLDOMNode::get_nodeTypeString怎么用?C++ IXMLDOMNode::get_nodeTypeString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类msxml2::IXMLDOMNode
的用法示例。
在下文中一共展示了IXMLDOMNode::get_nodeTypeString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Parse
void XmlParser::Parse(NodeCallback callback, void *data)
{
MSXML2::IXMLDOMNodeListPtr NodeListPtr;
BSTR strFindText = L" ";
MSXML2::IXMLDOMNode *pIDOMNode = NULL;
BSTR bstrNodeType;
assert(m_domDocument != NULL);
NodeListPtr = m_domDocument->getElementsByTagName(strFindText);
for(int i = 0; i < NodeListPtr->length; i++)
{
if (pIDOMNode)
pIDOMNode->Release();
NodeListPtr->get_item(i, &pIDOMNode);
pIDOMNode->get_nodeTypeString(&bstrNodeType);
if (lstrcmp((LPCTSTR)bstrNodeType, (LPCTSTR)L"element") != 0)
continue;
XmlNode node;
_parseNode(pIDOMNode, node);
if (callback(node, data) == false)
break;
}
if (pIDOMNode)
pIDOMNode->Release();
}
示例2: _parseNodeGetText
void XmlParser::_parseNodeGetText(MSXML2::IXMLDOMNode *pIDOMNode, XmlNode& node)
{
MSXML2::IXMLDOMNode* ppFirstChild;
BSTR bstrNodeType;
pIDOMNode->get_firstChild(&ppFirstChild);
if (ppFirstChild == NULL)
return;
ppFirstChild->get_nodeTypeString(&bstrNodeType);
if (lstrcmp((LPCTSTR)bstrNodeType, (LPCTSTR)L"text") == 0 ||
(lstrcmp((LPCTSTR)bstrNodeType, (LPCTSTR)L"cdatasection") == 0))
{
BSTR bstrItemText;
ppFirstChild->get_text(&bstrItemText);
node.SetText(wstring(bstrItemText));
}
}
示例3: XMLDOMParsingNodes
void XMLDOMParsingNodes(char *szFileName)
{
try
{
//Qualify namespase explicitly to avoid Compiler Error C2872 "ambiguous symbol" during linking.
//Now Msxml2.dll use the "MSXML2" namespace
//(see http://support.microsoft.com/default.aspx?scid=kb;en-us;316317):
MSXML2::IXMLDOMDocumentPtr docPtr;//pointer to DOMDocument object
MSXML2::IXMLDOMNodeListPtr NodeListPtr;//indexed access. and iteration through the collection of nodes
MSXML2::IXMLDOMNodePtr DOMNodePtr;//pointer to the node
MSXML2::IXMLDOMNode *pIDOMNode = NULL;//pointer to element's node
MSXML2::IXMLDOMNode *pIParentNode = NULL;//pointer to parent node
MSXML2::IXMLDOMNode *pIAttrNode = NULL;//pointer to attribute node
MSXML2::IXMLDOMNamedNodeMapPtr DOMNamedNodeMapPtr;//iteration through the collection of attribute nodes
MSXML2::IXMLDOMNodeList *childList=NULL;//node list containing the child nodes
//Variable with the name of node to find:
BSTR strFindText = L" ";//" " means to output every node
//Variables to store item's name, parent, text and node type:
BSTR bstrItemText,bstrItemNode, bstrItemParent,bstrNodeType;
//Variables to store attribute's name,type and text:
BSTR bstrAttrName, bstrAttrType, bstrAttrText;
HRESULT hResult;
int i = 0;//loop-index variable
int n = 0;//lines counter
//Initialize COM Library:
CoInitialize(NULL);
//Create an instance of the DOMDocument object:
docPtr.CreateInstance(__uuidof(DOMDocument30));
// Load a document:
_variant_t varXml(szFileName);//XML file to load
_variant_t varResult((bool)TRUE);//result
varResult = docPtr->load(varXml);
if ((bool)varResult == FALSE)
{
//printf("*** Error:failed to load XML file. ***\n");
MessageBox(0,"Error: failed to load XML file. Check the file name.", \
"Load XML file",MB_OK |MB_ICONWARNING);
return;
}
//Collect all or selected nodes by tag name:
NodeListPtr = docPtr->getElementsByTagName(strFindText);
//Output the number of nodes:
//printf("Number of nodes: %d\n", (NodeListPtr->length));
//Output root node:
docPtr->documentElement->get_nodeName(&bstrItemText);
//%ls formatting is for wchar_t* parameter's type (%s for char* type):
printf("\nRoot: %ls\n", bstrItemText);
for(i = 0; i < (NodeListPtr->length); i++)
{
if (pIDOMNode) pIDOMNode->Release();
NodeListPtr->get_item(i, &pIDOMNode);
if(pIDOMNode )
{
pIDOMNode->get_nodeTypeString(&bstrNodeType);
//We process only elements (nodes of "element" type):
BSTR temp = L"element";
if (lstrcmp((LPCTSTR)bstrNodeType, (LPCTSTR)temp)==0)
{
n++;//element node's number
printf("\n\n%d\n", n);//element node's number
printf("Type: %ls\n", bstrNodeType);
pIDOMNode->get_nodeName(&bstrItemNode);
printf("Node: %ls\n", bstrItemNode);
pIDOMNode->get_text(&bstrItemText);
printf("Text: %ls\n", bstrItemText);
pIDOMNode->get_parentNode(&pIParentNode);
pIParentNode->get_nodeName(&bstrItemParent);
printf("Parent: %ls\n",bstrItemParent);
pIDOMNode->get_childNodes(&childList);
printf("Child nodes: %d\n", (childList->length));
//.........这里部分代码省略.........