本文整理汇总了C++中DOMElement::getElementsByTagName方法的典型用法代码示例。如果您正苦于以下问题:C++ DOMElement::getElementsByTagName方法的具体用法?C++ DOMElement::getElementsByTagName怎么用?C++ DOMElement::getElementsByTagName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DOMElement
的用法示例。
在下文中一共展示了DOMElement::getElementsByTagName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: readFile
void Parameters::readFile(string str){
file = str;
XMLPlatformUtils::Initialize();
XercesDOMParser parser;
parser.setValidationScheme(XercesDOMParser::Val_Always);
HandlerBase errHandler;// = (ErrorHandler*) new HandlerBase();
parser.setErrorHandler(&errHandler);
parser.parse(str.c_str());
DOMDocument * doc = parser.getDocument();
DOMElement* elementRoot = doc->getDocumentElement();
// Extract floats
DOMElement* floatRoot = (DOMElement *)
elementRoot->getElementsByTagName(XMLString::transcode("real"))->item(0);
DOMElement* child = floatRoot->getFirstElementChild();
do{
saveReal(XMLString::transcode(child->getNodeName()),
atof(XMLString::transcode(child->getTextContent())));
child = child->getNextElementSibling();
}while(child != NULL);
// Extract integers
DOMElement* intRoot = (DOMElement *)
elementRoot->getElementsByTagName(XMLString::transcode("integer"))->item(0);
child = intRoot->getFirstElementChild();
do{
saveInteger(
XMLString::transcode(child->getNodeName()),
atoi(XMLString::transcode(child->getTextContent())));
child = child->getNextElementSibling();
}while(child != NULL);
}
示例2: main
int main( int argc, char **argv ){
m_doc = openDocument( argv[1] );
DOMElement *root = m_doc->getDocumentElement();
DOMNodeList *parts = root->getElementsByTagName(XS("part"));
/*
*/
DOMElement *part1 = (DOMElement*)parts->item(0);
DOMElement *part2 = (DOMElement*)parts->item(1);
mergeParts( part1, part2 );
root->removeChild( part2 );
DOMElement *partlist = getSingleElement( root, "part-list" );
partlist->removeChild( partlist->getElementsByTagName(XS("score-part"))->item(1) );
writeFile("merged.xml");
}
示例3: index
/**
TEMP! 2DO Returns perf part by index (will not create perf part)
*/
PerfPart *PMLDocument::getPerfPart( int index ){
DOMElement *root = m_doc->getDocumentElement();
DOMElement *perf = (DOMElement*)root->getElementsByTagName(XS("performance"))->item(0);
DOMNodeList *parts = perf->getElementsByTagName(XS("perfpart"));
DOMElement *perfPartEl = (DOMElement*)parts->item(index);
PerfPart *perfPart = new PerfPart(this, perfPartEl);
return perfPart;
}
示例4: metagame
void Generation::GenerationImpl::getGeneration(DOMElement *node) {
XMLCh tempStr[20];
XMLString::transcode("id", tempStr, 19);
DOMNode *p = node->getAttributes()->getNamedItem(tempStr);
if (p) {
m_id = getStringNodeValue(p);
}
XMLString::transcode("name", tempStr, 19);
DOMNodeList *list = node->getElementsByTagName(tempStr);
if (list->getLength() != 0) {
m_name = getTextFromElement((DOMElement *)list->item(0));
}
XMLString::transcode("metagames", tempStr, 19);
list = node->getElementsByTagName(tempStr);
if (list->getLength() != 0) {
DOMElement *metagames = (DOMElement *)list->item(0);
XMLString::transcode("metagame", tempStr, 19);
list = metagames->getElementsByTagName(tempStr);
const int length = list->getLength();
for (int i = 0; i < length; ++i) {
DOMElement *item = (DOMElement *)list->item(i);
MetagamePtr metagame(new Metagame());
metagame.get()->m_impl->getMetagame(item);
metagame.get()->m_impl->m_idx = i;
metagame.get()->m_impl->m_generation = m_owner;
m_metagames.push_back(metagame);
}
}
}
示例5: parread
// to check the value of child node
string cap::parread(const char* parentTag, int parentIndex,const char* childTag, int childIndex)
{
XMLCh* temp=XMLString::transcode(parentTag);
DOMNodeList* list = doc->getElementsByTagName(temp);
XMLString::release(&temp);
DOMElement* parent =dynamic_cast<DOMElement*>(list->item(parentIndex));
DOMElement* child =dynamic_cast<DOMElement*>(parent->getElementsByTagName(XMLString::transcode(childTag))->item(childIndex));
string value;
if (child) {
char* temp2 = XMLString::transcode(child->getTextContent());
//cout<<"its :"<<child->getTextContent()<<endl;
value = temp2;
XMLString::release(&temp2);
}
else {
value = "NO VALUE";
}
return value;
}
示例6: readGenerations
void Generation::readGenerations(const string &file,
vector<GenerationPtr> &generations) {
XMLPlatformUtils::Initialize();
XercesDOMParser parser;
GenerationErrorHandler handler;
parser.setErrorHandler(&handler);
parser.setEntityResolver(&handler);
parser.parse(file.c_str());
DOMDocument *doc = parser.getDocument();
DOMElement *root = doc->getDocumentElement();
XMLCh tempStr[12];
XMLString::transcode("generation", tempStr, 11);
DOMNodeList *list = root->getElementsByTagName(tempStr);
int length = list->getLength();
for (int i = 0; i < length; ++i) {
DOMElement *item = (DOMElement *)list->item(i);
GenerationPtr generation(new Generation());
generation->m_impl->m_owner = generation.get();
generation->m_impl->getGeneration(item);
generation->m_impl->m_idx = i;
generations.push_back(generation);
}
}
示例7: GetNumVar
int Problem::GetNumVar()
{
// first check if we have already read in this value yet.
if(!hasNumVar_)
{
DOMNodeList* nodeList;
DOMNode* tmpNode;
DOMElement* variableXML;
DOMElement* tmpXML;
// if not, count the number of variables given in the
// Variable Array
if((nodeList =
applicationXML_->getElementsByTagName(XMLString::transcode("VariableClass")))->getLength() > 0)
{
tmpNode = nodeList->item(0);
tmpXML = (DOMElement *)tmpNode;
}
if((nodeList =
applicationXML_->getElementsByTagName(XMLString::transcode("Array")))->getLength() > 0)
{
tmpNode = nodeList->item(0);
variableXML = (DOMElement *)tmpNode;
}
numVar_ =
variableXML->getElementsByTagName(XMLString::transcode("Variables"))->getLength();
hasNumVar_ = true;
}
return numVar_;
}
示例8: stampDocument
// 2006/12/16
void stampDocument(DOMElement* root) {
DOMElement* meta = NULL;
DOMElement* macastamps = NULL;
DOMElement* stamp = NULL;
stamp = (root->getOwnerDocument())->createElement(XMLString::transcode("maca_stamp"));
stamp->setAttribute(XMLString::transcode("module"),
XMLString::transcode(_INSTALLED_NAME_));
stamp->setAttribute(XMLString::transcode("version"),
XMLString::transcode(_VERSION_));
stamp->setAttribute(XMLString::transcode("timestamp"),
XMLString::transcode(getTimestamp().c_str()));
DOMNodeList* metaList = root->getElementsByTagName(XMLString::transcode("meta"));
if (metaList->getLength() == 0) { // NO meta Element
meta = (root->getOwnerDocument())->createElement(XMLString::transcode("meta"));
macastamps =
(root->getOwnerDocument())->createElement(XMLString::transcode("maca_stamps"));
meta->appendChild(macastamps);
root->insertBefore(meta,root->getFirstChild());
} else { // meta Element
meta = (DOMElement*)metaList->item(0);
DOMNodeList* macastampsList =
meta->getElementsByTagName(XMLString::transcode("maca_stamps"));
if (macastampsList->getLength() == 0) { // NO macastamps Element
macastamps =
(root->getOwnerDocument())->createElement(XMLString::transcode("maca_stamps"));
meta->appendChild(macastamps);
} else { // macastamps Element
macastamps = (DOMElement*)macastampsList->item(0);
}
}
macastamps->appendChild(stamp);
}
示例9: XS
/**
* Create PerfPart element
*/
PerfPart::PerfPart( PMLDocument *doc, DOMElement *element ){
m_doc = doc;
m_element = element;
DOMDocument *domdoc = m_element->getOwnerDocument();
const XMLCh *partID = m_element->getAttribute( XS("part") );
DOMElement *root = m_element->getOwnerDocument()->getDocumentElement();
DOMNodeList *parts = root->getElementsByTagName(XS("part"));
for( unsigned int i=0; i<parts->getLength(); i++ ){
DOMElement *e = (DOMElement*)parts->item(i);
cout << " perf " << XS( m_element->getAttribute(XS("id")))
<< " score " << XS( e->getAttribute(XS("part")) )
<< endl;
if( !strcmp(XS( m_element->getAttribute(XS("id")) ), XS( e->getAttribute(XS("part")) )) ){
m_scorePart = new ScorePart( m_doc, e );
}
}
DOMNodeList *nl = m_element->getElementsByTagName(XS(PNote::Tag));
for( int i=0; i<nl->getLength(); i++ ){
m_notes.push_back( new PNote( m_doc, (DOMElement*)nl->item(i) ) );
}
}
示例10: HandlerBase
map<string, DatasetSpecification> Specifications::readDatasetIndex(string str){
map<string, DatasetSpecification> result;
XERCES_CPP_NAMESPACE_USE
XMLPlatformUtils::Initialize();
XercesDOMParser parser;
parser.setValidationScheme(XercesDOMParser::Val_Always);
HandlerBase errHandler;// = (ErrorHandler*) new HandlerBase();
parser.setErrorHandler(&errHandler);
parser.parse(str.c_str());
DOMDocument * doc = parser.getDocument();
DOMElement* elementRoot = doc->getDocumentElement();
DOMNodeList *entries =
elementRoot->getElementsByTagName(XMLString::transcode("dataset"));
cout << "Databases in index:\n";
for(size_t i = 0; i < entries->getLength(); ++i){
DOMNode *current = entries->item(i);
DatasetSpecification dss;
dss.name = XMLString::transcode(current->getAttributes()->
getNamedItem(XMLString::transcode("name"))->
getNodeValue());
dss.root = XMLString::transcode(current->getAttributes()->
getNamedItem(XMLString::transcode("root"))->
getNodeValue());
cout << " name: " << dss.name << " root: " << dss.root << endl;
DOMNodeList *categories = current->getChildNodes();
for(size_t j = 0; j < categories->getLength(); ++j)
if((string) XMLString::transcode(categories->item(j)->getNodeName()) ==
"category")
dss.categories.push_back(XMLString::transcode(categories->item(j)->getTextContent()));
result[dss.name] = dss;
}
return result;
}
示例11: i
list<string> InputHandler::getPostProcessorNameList()
{
list<string> names;
//get the postprocessor node
DOMElement *elem = dynamic_cast<DOMElement*>(getElementByTagName(TAG_postprocessor.xmlStr()));
//check whether there is one
if(!elem)
{
crusde_info("No postprocessors found.");
return names;
}
//if so, grab all plugins it owns.
DOMNodeList *plugins = elem->getElementsByTagName(TAG_plugin.xmlStr());
unsigned int i(0);
//if there are plugins ...
while(plugins && i < plugins->getLength() )
{
if( plugins->item(i)->getNodeType() == DOMNode::ELEMENT_NODE)
{
/* upcast child to element node */
DOMElement *elem = dynamic_cast<DOMElement*>( plugins->item(i) );
StrXML name(elem->getAttribute(ATTR_name.xmlStr()));
//... add names to list for later lookup.
names.push_back(name.cppStr());
}
++i;
}
//return filled list
return names;
}
示例12: getAttributeValue
/**
* extract's the value of an attribute and returns it:
*
* <parentNode>
* <elementNode attribute="returnstring" />
* </parentNode>
*
* the first parentNode found in the document is used. thus, it is expected to be unique.
*
* @param parentNode
* @param elementNode
* @param attribute
* @return
*/
string InputHandler::getAttributeValue(const XMLCh* parentNode, const XMLCh* elementNode, const XMLCh* attribute)
{
crusde_debug("%s, line: %d, InputHandler::getAttributeValue(%s) ", __FILE__, __LINE__, XMLString::transcode(elementNode));
DOMElement *root = doc->getDocumentElement();
DOMNodeList *node_list = root->getElementsByTagName(parentNode);
/*if element does not exist, return emptry string*/
if(node_list->getLength() == 0)
return string();
DOMNode *child = node_list->item(0)->getFirstChild();
DOMNamedNodeMap *attributes = NULL;
while (child)
{
if( child->getNodeType() == DOMNode::ELEMENT_NODE)
{
attributes = child->getAttributes();
if( XMLString::compareIString(child->getNodeName(), elementNode) == 0 )
{
char *val = XMLString::transcode(attributes->getNamedItem(attribute)->getNodeValue());
string value(val);
XMLString::release(&val);
return value;
}
}
child = child->getNextSibling();
}
return string();
}
示例13: ScorePart
ScorePart *PMLDocument::getScorePart( int index ){
DOMElement *root = m_doc->getDocumentElement();
DOMNodeList *parts = root->getElementsByTagName(XS("part"));
DOMElement *score = (DOMElement*)parts->item(index);
ScorePart *scorePart = new ScorePart(this, score);
return scorePart;
}
示例14: getChildCount
int XmlDomDocument::getChildCount(const char* parentTag, int parentIndex, const char* childTag)
{
XMLCh* temp = XMLString::transcode(parentTag);
DOMNodeList* list = m_doc->getElementsByTagName(temp);
XMLString::release(&temp);
DOMElement* parent = dynamic_cast<DOMElement*>(list->item(parentIndex));
DOMNodeList* childList = parent->getElementsByTagName(XMLString::transcode(childTag));
return (int)childList->getLength();
}
示例15: FindParameterXML
DOMElement* NewtonProblem::FindParameterXML()
{
DOMElement* solverXML = GetSolverXML();
DOMElement* parameterXML;
DOMNodeList* nodeList;
DOMNode* tmpNode;
string trName = "trustRegion";
string lsName = "lineSearch";
string pdsName = "trustPDS";
// now check to see which search method is used.
if((nodeList =
solverXML->getElementsByTagName(XMLString::transcode(trName.c_str())))->getLength() > 0)
{
searchType_ = trustRegion;
tmpNode = nodeList->item(0);
parameterXML = (DOMElement *) tmpNode;
}
else if((nodeList =
solverXML->getElementsByTagName(XMLString::transcode(lsName.c_str())))->getLength() > 0)
{
searchType_ = lineSearch;
tmpNode = nodeList->item(0);
parameterXML = (DOMElement *) tmpNode;
}
else if((nodeList =
solverXML->getElementsByTagName(XMLString::transcode(pdsName.c_str())))->getLength() > 0)
{
searchType_ = trustPDS;
tmpNode = nodeList->item(0);
parameterXML = (DOMElement *) tmpNode;
}
else
{
cerr << "CANNOT determine search strategy type" << endl;
exit(1);
}
return parameterXML;
}