本文整理汇总了C++中TiXmlHandle::Node方法的典型用法代码示例。如果您正苦于以下问题:C++ TiXmlHandle::Node方法的具体用法?C++ TiXmlHandle::Node怎么用?C++ TiXmlHandle::Node使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TiXmlHandle
的用法示例。
在下文中一共展示了TiXmlHandle::Node方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: readName
TiXmlElement* CSmartPlaylist::readName()
{
if (m_xmlDoc.Error())
{
CLog::Log(LOGERROR, "Error loading Smart playlist (failed to parse xml: %s)", m_xmlDoc.ErrorDesc());
return NULL;
}
TiXmlElement *root = m_xmlDoc.RootElement();
if (!root || strcmpi(root->Value(),"smartplaylist") != 0)
{
CLog::Log(LOGERROR, "Error loading Smart playlist");
return NULL;
}
// load the playlist type
const char* type = root->Attribute("type");
if (type)
m_playlistType = type;
// backward compatibility:
if (m_playlistType == "music")
m_playlistType = "songs";
if (m_playlistType == "video")
m_playlistType = "musicvideos";
// load the playlist name
TiXmlHandle name = ((TiXmlHandle)root->FirstChild("name")).FirstChild();
if (name.Node())
m_playlistName = name.Node()->Value();
return root;
}
示例2: Load
bool CSmartPlaylist::Load(const CStdString &path)
{
TiXmlElement *root = OpenAndReadName(path);
if (!root)
return false;
// encoding:
CStdString encoding;
XMLUtils::GetEncoding(&m_xmlDoc, encoding);
TiXmlHandle match = ((TiXmlHandle)root->FirstChild("match")).FirstChild();
if (match.Node())
m_matchAllRules = strcmpi(match.Node()->Value(), "all") == 0;
// now the rules
TiXmlElement *rule = root->FirstChildElement("rule");
while (rule)
{
// format is:
// <rule field="Genre" operator="contains">parameter</rule>
const char *field = rule->Attribute("field");
const char *oper = rule->Attribute("operator");
TiXmlNode *parameter = rule->FirstChild();
if (field && oper)
{ // valid rule
CStdString utf8Parameter;
if (parameter)
{
if (encoding.IsEmpty()) // utf8
utf8Parameter = parameter->Value();
else
g_charsetConverter.stringCharsetToUtf8(encoding, parameter->Value(), utf8Parameter);
}
CSmartPlaylistRule rule;
rule.TranslateStrings(field, oper, utf8Parameter.c_str());
m_playlistRules.push_back(rule);
}
rule = rule->NextSiblingElement("rule");
}
// now any limits
// format is <limit>25</limit>
TiXmlHandle limit = ((TiXmlHandle)root->FirstChild("limit")).FirstChild();
if (limit.Node())
m_limit = atoi(limit.Node()->Value());
// and order
// format is <order direction="ascending">field</order>
TiXmlElement *order = root->FirstChildElement("order");
if (order && order->FirstChild())
{
const char *direction = order->Attribute("direction");
if (direction)
m_orderAscending = strcmpi(direction, "ascending") == 0;
m_orderField = CSmartPlaylistRule::TranslateField(order->FirstChild()->Value());
}
return true;
}
示例3: removeTag
//---------------------------------------------------------
void ofXMLSettings::removeTag(string tag, int which){
vector<string> tokens = tokenize(tag,":");
//no tags so we return
if( tokens.size() == 0 ) return;
//grab the handle from the level we are at
//normally this is the doc but could be a pushed node
TiXmlHandle tagHandle = *storedHandle;
if(which < 0) which = 0;
for(int x=0;x<tokens.size();x++){
//we only support multi tags
//with same name at root level
if(x > 0) which = 0;
TiXmlHandle isRealHandle = tagHandle.ChildElement( tokens.at(x), which);
if ( !isRealHandle.Node() ) break;
else{
if (x == tokens.size()-1){
//if we are at the last tag and it exists
//we use its parent to remove it - haha
tagHandle.ToNode()->RemoveChild( isRealHandle.ToNode() );
}
tagHandle = isRealHandle;
}
}
tokens.clear();
}
示例4: playlist
TiXmlElement *CSmartPlaylist::OpenAndReadName(const CStdString &path)
{
CFileStream file;
if (!file.Open(path))
{
CLog::Log(LOGERROR, "Error loading Smart playlist %s (failed to read file)", path.c_str());
return NULL;
}
m_xmlDoc.Clear();
file >> m_xmlDoc;
if (m_xmlDoc.Error())
{
CLog::Log(LOGERROR, "Error loading Smart playlist (failed to parse xml: %s)", m_xmlDoc.ErrorDesc());
return NULL;
}
TiXmlElement *root = m_xmlDoc.RootElement();
if (!root || strcmpi(root->Value(),"smartplaylist") != 0)
{
CLog::Log(LOGERROR, "Error loading Smart playlist %s", path.c_str());
return NULL;
}
// load the playlist type
const char* type = root->Attribute("type");
if (type)
m_playlistType = type;
// backward compatibility:
if (m_playlistType == "music")
m_playlistType = "songs";
if (m_playlistType == "video")
m_playlistType = "musicvideos";
// load the playlist name
TiXmlHandle name = ((TiXmlHandle)root->FirstChild("name")).FirstChild();
if (name.Node())
m_playlistName = name.Node()->Value();
else
{
m_playlistName = CUtil::GetTitleFromPath(path);
if (URIUtils::GetExtension(m_playlistName) == ".xsp")
URIUtils::RemoveExtension(m_playlistName);
}
return root;
}
示例5: LoadFromXML
bool CSmartPlaylist::LoadFromXML(TiXmlElement *root, const CStdString &encoding)
{
if (!root)
return false;
TiXmlHandle match = ((TiXmlHandle)root->FirstChild("match")).FirstChild();
if (match.Node())
m_matchAllRules = strcmpi(match.Node()->Value(), "all") == 0;
// now the rules
TiXmlElement *ruleElement = root->FirstChildElement("rule");
while (ruleElement)
{
CSmartPlaylistRule rule;
rule.Load(ruleElement, encoding);
m_playlistRules.push_back(rule);
ruleElement = ruleElement->NextSiblingElement("rule");
}
// now any limits
// format is <limit>25</limit>
TiXmlHandle limit = ((TiXmlHandle)root->FirstChild("limit")).FirstChild();
if (limit.Node())
m_limit = atoi(limit.Node()->Value());
// and order
// format is <order direction="ascending">field</order>
TiXmlElement *order = root->FirstChildElement("order");
if (order && order->FirstChild())
{
const char *direction = order->Attribute("direction");
if (direction)
m_orderAscending = strcmpi(direction, "ascending") == 0;
m_orderField = CSmartPlaylistRule::TranslateOrder(order->FirstChild()->Value());
}
return true;
}
示例6: deserialize
bool TinyDemarshaller::deserialize( PropertyBag &v )
{
Logger::In in("TinyDemarshaller");
if ( !d->loadOkay )
return false;
TiXmlHandle docHandle( &d->doc );
TiXmlHandle propHandle = docHandle.FirstChildElement( "properties" );
if ( ! propHandle.Node() ) {
log(Error) << "No <properties> element found in document!"<< endlog();
return false;
}
detail::Tiny2CPFHandler proc( v );
if ( proc.populateBag( propHandle.Node() ) == false) {
deleteProperties( v );
return false;
}
return true;
}
示例7: pushTag
//---------------------------------------------------------
bool ofXMLSettings::pushTag(string tag, int which){
vector<string> tokens = tokenize(tag,":");
//we only allow to push one tag at a time.
TiXmlHandle isRealHandle = storedHandle->ChildElement(tokens.at(0), which);
//now, clear that vector!
tokens.clear();
if( isRealHandle.Node() ){
*storedHandle = isRealHandle;
level++;
return true;
}else{
printf("pushTag - tag not found\n");
}
return false;
}
示例8: pushTag
//---------------------------------------------------------
bool ofxXmlSettings::pushTag(string tag, int which){
int pos = tag.find(":");
if(pos > 0){
tag = tag.substr(0,pos);
}
//we only allow to push one tag at a time.
TiXmlHandle isRealHandle = storedHandle->ChildElement(tag, which);
if( isRealHandle.Node() ){
*storedHandle = isRealHandle;
level++;
return true;
}else{
printf("pushTag - tag not found\n");
}
return false;
}
示例9: tagExists
//---------------------------------------------------------
bool ofXMLSettings::tagExists(string tag, int which){
vector<string> tokens = tokenize(tag,":");
bool found = false;
//grab the handle from the level we are at
//normally this is the doc but could be a pushed node
TiXmlHandle tagHandle = *storedHandle;
if(which < 0) which = 0;
for(int x=0;x<tokens.size();x++){
//we only support multi tags
//with same name at root level
if(x > 0) which = 0;
TiXmlHandle isRealHandle = tagHandle.ChildElement( tokens.at(x), which);
//as soon as we find a tag that doesn't exist
//we return false;
if ( !isRealHandle.Node() ){
found = false;
break;
}
else{
found = true;
tagHandle = isRealHandle;
}
}
tokens.clear();
return found;
}
示例10: main
int main()
{
//
// We start with the 'demoStart' todo list. Process it. And
// should hopefully end up with the todo list as illustrated.
//
const char* demoStart =
"<?xml version=\"1.0\" standalone='no' >\n"
"<!-- Our to do list data -->"
"<ToDo>\n"
"<!-- Do I need a secure PDA? -->\n"
"<Item priority=\"1\" distance='close'> Go to the <bold>Toy store!</bold></Item>"
"<Item priority=\"2\" distance='none'> Do bills </Item>"
"<Item priority=\"2\" distance='far & back'> Look for Evil Dinosaurs! </Item>"
"</ToDo>";
{
#ifdef TIXML_USE_STL
// What the todo list should look like after processing.
// In stream (no formatting) representation.
const char* demoEnd =
"<?xml version=\"1.0\" standalone=\"no\" ?>"
"<!-- Our to do list data -->"
"<ToDo>"
"<!-- Do I need a secure PDA? -->"
"<Item priority=\"2\" distance=\"close\">Go to the"
"<bold>Toy store!"
"</bold>"
"</Item>"
"<Item priority=\"1\" distance=\"far\">Talk to:"
"<Meeting where=\"School\">"
"<Attendee name=\"Marple\" position=\"teacher\" />"
"<Attendee name=\"Voel\" position=\"counselor\" />"
"</Meeting>"
"<Meeting where=\"Lunch\" />"
"</Item>"
"<Item priority=\"2\" distance=\"here\">Do bills"
"</Item>"
"</ToDo>";
#endif
// The example parses from the character string (above):
#if defined( WIN32 ) && defined( TUNE )
_CrtMemCheckpoint( &startMemState );
#endif
{
// Write to a file and read it back, to check file I/O.
TiXmlDocument doc( "demotest.xml" );
doc.Parse( demoStart );
if ( doc.Error() )
{
printf( "Error in %s: %s\n", doc.Value(), doc.ErrorDesc() );
exit( 1 );
}
doc.SaveFile();
}
TiXmlDocument doc( "demotest.xml" );
bool loadOkay = doc.LoadFile();
if ( !loadOkay )
{
printf( "Could not load test file 'demotest.xml'. Error='%s'. Exiting.\n", doc.ErrorDesc() );
exit( 1 );
}
printf( "** Demo doc read from disk: ** \n\n" );
printf( "** Printing via doc.Print **\n" );
doc.Print( stdout );
{
printf( "** Printing via TiXmlPrinter **\n" );
TiXmlPrinter printer;
doc.Accept( &printer );
fprintf( stdout, "%s", printer.CStr() );
}
#ifdef TIXML_USE_STL
{
printf( "** Printing via operator<< **\n" );
std::cout << doc;
}
#endif
TiXmlNode* node = 0;
TiXmlElement* todoElement = 0;
TiXmlElement* itemElement = 0;
// --------------------------------------------------------
// An example of changing existing attributes, and removing
// an element from the document.
// --------------------------------------------------------
// Get the "ToDo" element.
// It is a child of the document, and can be selected by name.
node = doc.FirstChild( "ToDo" );
//.........这里部分代码省略.........
示例11: writeTag
//---------------------------------------------------------
int ofXMLSettings::writeTag(string tag, char * valueStr, int which){
vector<string> tokens = tokenize(tag,":");
// allocate then clean up :
TiXmlElement ** elements = new TiXmlElement*[tokens.size()];
for(int x=0;x<tokens.size();x++){
elements[x] = new TiXmlElement(tokens.at(x));
}
TiXmlText Value(valueStr);
// search our way up - do these tags exist?
// find the first that DOESNT exist, then move backwards...
TiXmlHandle tagHandle = *storedHandle;
bool addNewTag = false;
if(which == -1)addNewTag = true;
for(int x=0;x<tokens.size();x++){
if( x > 0 ){
//multi tags of same name
//only for the root level
which = 0;
addNewTag = false;
}
TiXmlHandle isRealHandle = tagHandle.ChildElement( tokens.at(x), which);
if ( !isRealHandle.Node() || addNewTag){
for(int i=tokens.size()-1;i>=x;i--){
if (i == tokens.size()-1){
elements[i]->InsertEndChild(Value);
} else {
elements[i]->InsertEndChild(*(elements[i+1]));
}
}
tagHandle.ToNode()->InsertEndChild(*(elements[x]));
break;
} else {
tagHandle = isRealHandle;
if (x == tokens.size()-1){
// what we want to change : TiXmlHandle valHandle = tagHandle.Child( 0 );
tagHandle.ToNode()->Clear();
tagHandle.ToNode()->InsertEndChild(Value);
}
}
}
//lets find how many of the same tags exist
//then we can return the numTags;
int numSameTags = 0;
while( (storedHandle->ChildElement( tokens.at(0), numSameTags )).Node() ){
numSameTags++;
}
//now, clear that vector!
tokens.clear();
return numSameTags;
}
示例12: writeTag
//---------------------------------------------------------
int ofxXmlSettings::writeTag(string tag, char * valueStr, int which){
vector<string> tokens = tokenize(tag,":");
// allocate then clean up :
TiXmlElement ** elements = new TiXmlElement*[tokens.size()];
for(int x=0;x<tokens.size();x++){
elements[x] = new TiXmlElement(tokens.at(x));
}
TiXmlText Value(valueStr);
// search our way up - do these tags exist?
// find the first that DOESNT exist, then move backwards...
TiXmlHandle tagHandle = *storedHandle;
bool addNewTag = false;
if(which == -1)addNewTag = true;
for(int x=0;x<tokens.size();x++){
if( x > 0 ){
//multi tags of same name
//only for the root level
which = 0;
addNewTag = false;
}
TiXmlHandle isRealHandle = tagHandle.ChildElement( tokens.at(x), which);
if ( !isRealHandle.Node() || addNewTag){
for(int i=tokens.size()-1;i>=x;i--){
if (i == tokens.size()-1){
elements[i]->InsertEndChild(Value);
} else {
elements[i]->InsertEndChild(*(elements[i+1]));
}
}
tagHandle.ToNode()->InsertEndChild(*(elements[x]));
break;
} else {
tagHandle = isRealHandle;
if (x == tokens.size()-1){
// what we want to change : TiXmlHandle valHandle = tagHandle.Child( 0 );
tagHandle.ToNode()->Clear();
tagHandle.ToNode()->InsertEndChild(Value);
}
}
}
//lets count how many tags with our name exist so we can return an index
//ripped from tinyXML as doing this ourselves once is a LOT! faster
//than having this called n number of times in a while loop - we go from n*n iterations to n iterations
int numSameTags;
TiXmlElement* child = ( storedHandle->FirstChildElement( tokens.at(0) ) ).Element();
for (numSameTags = 0; child; child = child->NextSiblingElement( tokens.at(0) ), ++numSameTags){
//nothing
}
//now, clear that vector!
tokens.clear();
return numSameTags;
}
示例13: main
int main()
{
//
// We start with the 'demoStart' todo list. Process it. And
// should hopefully end up with the todo list as illustrated.
//
const char* demoStart =
"<?xml version=\"1.0\" standalone='no' >\n"
"<!-- Our to do list data -->"
"<ToDo>\n"
"<!-- Do I need a secure PDA? -->\n"
"<Item priority=\"1\" distance='close'> Go to the <bold>Toy store!</bold></Item>"
"<Item priority=\"2\" distance='none'> Do bills </Item>"
"<Item priority=\"2\" distance='far & back'> Look for Evil Dinosaurs! </Item>"
"</ToDo>";
#ifdef TIXML_USE_STL
/* What the todo list should look like after processing.
In stream (no formatting) representation. */
const char* demoEnd =
"<?xml version=\"1.0\" standalone=\"no\" ?>"
"<!-- Our to do list data -->"
"<ToDo>"
"<!-- Do I need a secure PDA? -->"
"<Item priority=\"2\" distance=\"close\">Go to the"
"<bold>Toy store!"
"</bold>"
"</Item>"
"<Item priority=\"1\" distance=\"far\">Talk to:"
"<Meeting where=\"School\">"
"<Attendee name=\"Marple\" position=\"teacher\" />"
"<Attendee name=\"Voel\" position=\"counselor\" />"
"</Meeting>"
"<Meeting where=\"Lunch\" />"
"</Item>"
"<Item priority=\"2\" distance=\"here\">Do bills"
"</Item>"
"</ToDo>";
#endif
// The example parses from the character string (above):
#if defined( WIN32 ) && defined( TUNE )
QueryPerformanceCounter( (LARGE_INTEGER*) (&start) );
#endif
{
// Write to a file and read it back, to check file I/O.
TiXmlDocument doc( "demotest.xml" );
doc.Parse( demoStart );
if ( doc.Error() )
{
printf( "Error in %s: %s\n", doc.Value(), doc.ErrorDesc() );
exit( 1 );
}
doc.SaveFile();
}
TiXmlDocument doc( "demotest.xml" );
bool loadOkay = doc.LoadFile();
if ( !loadOkay )
{
printf( "Could not load test file 'demotest.xml'. Error='%s'. Exiting.\n", doc.ErrorDesc() );
exit( 1 );
}
printf( "** Demo doc read from disk: ** \n\n" );
doc.Print( stdout );
TiXmlNode* node = 0;
TiXmlElement* todoElement = 0;
TiXmlElement* itemElement = 0;
// --------------------------------------------------------
// An example of changing existing attributes, and removing
// an element from the document.
// --------------------------------------------------------
// Get the "ToDo" element.
// It is a child of the document, and can be selected by name.
node = doc.FirstChild( "ToDo" );
assert( node );
todoElement = node->ToElement();
assert( todoElement );
// Going to the toy store is now our second priority...
// So set the "priority" attribute of the first item in the list.
node = todoElement->FirstChildElement(); // This skips the "PDA" comment.
assert( node );
itemElement = node->ToElement();
assert( itemElement );
itemElement->SetAttribute( "priority", 2 );
// Change the distance to "doing bills" from
// "none" to "here". It's the next sibling element.
itemElement = itemElement->NextSiblingElement();
assert( itemElement );
//.........这里部分代码省略.........
示例14: main
int main()
{
//
// We start with the 'demoStart' todo list. Process it. And
// should hopefully end up with the todo list as illustrated.
//
const char* demoStart =
"<?xml version=\"1.0\" standalone='no' >\n"
"<!-- Our to do list data -->"
"<ToDo>\n"
"<!-- Do I need a secure PDA? -->\n"
"<Item priority=\"1\" distance='close'> Go to the <bold>Toy store!</bold></Item>"
"<Item priority=\"2\" distance='none'> Do bills </Item>"
"<Item priority=\"2\" distance='far & back'> Look for Evil Dinosaurs! </Item>"
"</ToDo>";
#ifdef TIXML_USE_STL
/* What the todo list should look like after processing.
In stream (no formatting) representation. */
const char* demoEnd =
"<?xml version=\"1.0\" standalone=\"no\" ?>"
"<!-- Our to do list data -->"
"<ToDo>"
"<!-- Do I need a secure PDA? -->"
"<Item priority=\"2\" distance=\"close\">Go to the"
"<bold>Toy store!"
"</bold>"
"</Item>"
"<Item priority=\"1\" distance=\"far\">Talk to:"
"<Meeting where=\"School\">"
"<Attendee name=\"Marple\" position=\"teacher\" />"
"<Attendee name=\"Vo‚\" position=\"counselor\" />"
"</Meeting>"
"<Meeting where=\"Lunch\" />"
"</Item>"
"<Item priority=\"2\" distance=\"here\">Do bills"
"</Item>"
"</ToDo>";
#endif
// The example parses from the character string (above):
#if defined( WIN32 ) && defined( TUNE )
QueryPerformanceCounter( (LARGE_INTEGER*) (&start) );
#endif
{
// Write to a file and read it back, to check file I/O.
TiXmlDocument doc( "demotest.xml" );
doc.Parse( demoStart );
if ( doc.Error() )
{
printf( "Error in %s: %s\n", doc.Value(), doc.ErrorDesc() );
exit( 1 );
}
doc.SaveFile();
}
ostringstream outputStream( ostringstream::out );
{
TiXmlDocument doc( "demotest.xml" );
bool loadOkay = doc.LoadFile();
if ( !loadOkay )
{
printf( "Could not load test file 'demotest.xml'. Error='%s'. Exiting.\n", doc.ErrorDesc() );
exit( 1 );
}
printf( "** Demo doc read from disk: ** \n\n" );
doc.Print( stdout );
TiXmlNode* node = 0;
TiXmlElement* todoElement = 0;
TiXmlElement* itemElement = 0;
// --------------------------------------------------------
// An example of changing existing attributes, and removing
// an element from the document.
// --------------------------------------------------------
// Get the "ToDo" element.
// It is a child of the document, and can be selected by name.
node = doc.FirstChild( "ToDo" );
assert( node );
todoElement = node->ToElement();
assert( todoElement );
// Going to the toy store is now our second priority...
// So set the "priority" attribute of the first item in the list.
node = todoElement->FirstChildElement(); // This skips the "PDA" comment.
assert( node );
itemElement = node->ToElement();
assert( itemElement );
itemElement->SetAttribute( "priority", 2 );
// Change the distance to "doing bills" from
// "none" to "here". It's the next sibling element.
itemElement = itemElement->NextSiblingElement();
//.........这里部分代码省略.........