本文整理汇总了C++中DOMDocument::hasChildNodes方法的典型用法代码示例。如果您正苦于以下问题:C++ DOMDocument::hasChildNodes方法的具体用法?C++ DOMDocument::hasChildNodes怎么用?C++ DOMDocument::hasChildNodes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DOMDocument
的用法示例。
在下文中一共展示了DOMDocument::hasChildNodes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
XERCES_CPP_NAMESPACE_USE
int main( int argc, char *argv[] )
{
std::cout << "****************************" << std::endl;
std::cout << "XML DOM PARSER PLAY" << std::endl;
std::cout << "****************************" << std::endl;
try
{
XMLPlatformUtils::Initialize();
}
catch( const XMLException& ex )
{
std::cerr << "error with xml initialisation:" << ex.getMessage() << std::endl;
return 1;
}
std::cout << "Building parser ..." << std::endl;
XercesDOMParser* parser = new XercesDOMParser();
if( !parser )
{
std::cerr << "no parser" << std::endl;
return 1;
}
parser->setValidationScheme(XercesDOMParser::Val_Always);
parser->setDoNamespaces(false);
parser->setDoSchema(false);
parser->setCreateEntityReferenceNodes(false);
std::cout << "Building error handler" << std::endl;
ErrorHandler* errHandler = dynamic_cast<ErrorHandler*>(new HandlerBase());
if( errHandler == 0 )
{
std::cerr << "ibad cast" << std::endl;
return 1;
}
if( errHandler == 0 )
{
std::cerr << "error with errorhandler caszting:" << std::endl;
return 1;
}
parser->setErrorHandler(errHandler);
char* xmlFile = "/home/suggitpe/test/RPMS/config/rpms_config.xml";
try
{
parser->parse(xmlFile);
if( parser->getErrorCount() == 0 )
{
std::cerr << "errors in parsing" << std::endl;
return 1;
}
DOMDocument * doc = parser->getDocument();
if( doc->hasChildNodes() )
{
std::cout << "Num nodes: " << doc->getChildNodes()->getLength() << std::endl;
for( int i = 0; i < doc->getChildNodes()->getLength();++i )
{
cout << "\t" << i << " type: " << doc->getChildNodes()->item(i)->getNodeType() << endl;
if( doc->getChildNodes()->item(i)->getNodeType() == 1 )
{
DOMElement *e = dynamic_cast<DOMElement*>(doc->getChildNodes()->item(i));
if( !e ) { cerr << "bad cast" << endl; }
if( e->hasChildNodes() )
{
cout << "\t\telement found with " << e->getChildNodes()->getLength() << " nodes"<< endl;
}
else
{
cout << "No child nodes" << endl;
}
}
}
cout << "now for the other way" << endl;
XMLCh * name = XMLString::transcode("system_components");
DOMNodeList *list = doc->getDocumentElement()->getElementsByTagName( name );
XMLString::release(&name);
std::cout << "Got list [" << list->getLength() << "]" << std::endl;
for( XMLSize_t i =0; i < list->getLength(); ++i )
{
std::cout << "." << std::endl;
}
}
else
{
std::cout << "no child nodes" << std::endl;
}
}
catch( const XMLException& ex )
{
std::cerr << "error with xml parser:" << ex.getMessage() << std::endl;
return 1;
}
catch( const DOMException& dex )
{
std::cerr << "error with xml parser:" << dex.msg << std::endl;
//.........这里部分代码省略.........