本文整理汇总了C++中TiXmlNode::PreviousSibling方法的典型用法代码示例。如果您正苦于以下问题:C++ TiXmlNode::PreviousSibling方法的具体用法?C++ TiXmlNode::PreviousSibling怎么用?C++ TiXmlNode::PreviousSibling使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TiXmlNode
的用法示例。
在下文中一共展示了TiXmlNode::PreviousSibling方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: while
Xml::node_iterator& Xml::node_iterator::
operator--() {
TiXmlNode* prev = node.updTiNode().PreviousSibling();
while (prev && !nodeTypeIsAllowed(allowed, prev->Type()))
prev = prev->PreviousSibling();
node = Node(prev);
return *this;
}
示例2: addRootElementIfNeeded
// If the supplied Xml document has zero or more than one top-level element,
// or has top-level text, we'll add <_Root> elements </_Root> to
// encapsulate all the top-level text and element nodes (this may also
// surround top-level comments and unknowns if they occur between the text
// and elements. A pointer to the root element (whether original or added)
// is returned.
TiXmlElement* addRootElementIfNeeded() {
// Find the first element or text node, and remember the node that
// preceded it since that's where we may be inserting the new root
// element.
TiXmlNode* nodeBeforeFirst = 0;
TiXmlNode* firstEltOrText = m_tixml.FirstChild();
while ( firstEltOrText &&
!(firstEltOrText->ToElement()||firstEltOrText->ToText()))
{ nodeBeforeFirst = firstEltOrText;
firstEltOrText = firstEltOrText->NextSibling(); }
if (!firstEltOrText) {
// No top level element or text node. We'll just append an empty
// _Root element to the end of whatever's there.
TiXmlElement* root = new TiXmlElement("_Root");
m_tixml.LinkEndChild(root);
return root;
}
// There is at least one element or text node at the top level; the
// first one is pointed to by firstEltOrText, and the node just before
// that (if any) is pointed to by nodeBeforeFirst. Now find the last
// top-level element or text node.
TiXmlNode* lastEltOrText = m_tixml.LastChild();
while ( lastEltOrText &&
!(lastEltOrText->ToElement()||lastEltOrText->ToText()))
lastEltOrText = lastEltOrText->PreviousSibling();
assert(lastEltOrText); // should have at least re-found the first one!
// If the extremely likely case that the first and last are the same
// node and that node is an element, then the document is already in the
// right format and we don't have to do anything to it.
if (firstEltOrText==lastEltOrText && firstEltOrText->ToElement())
return firstEltOrText->ToElement();
// Now we know there is top-level text or more than one top-level
// element so we are going to have to surround everything between
// first and last with a new root element.
TiXmlElement* root = new TiXmlElement("_Root");
TiXmlNode* nextToMove = firstEltOrText;
while(true) {
assert(nextToMove); // can't happen!
TiXmlNode* moveMe = nextToMove;
nextToMove = moveMe->NextSibling();
root->LinkEndChild(m_tixml.DisconnectChild(moveMe));
// Did we just move the last element or text node?
if (moveMe == lastEltOrText) break;
}
// Now link the new root element right where we found the first
// element or text node.
if (nodeBeforeFirst) m_tixml.LinkAfterChild(nodeBeforeFirst, root);
else m_tixml.LinkBeginChild(root);
return root;
}
示例3: save
Xml::node_iterator Xml::node_iterator::
operator--(int) {
Node save(node);
TiXmlNode* prev = node.updTiNode().PreviousSibling();
while (prev && !nodeTypeIsAllowed(allowed, prev->Type()))
prev = prev->PreviousSibling();
node = Node(prev);
return node_iterator(save);
}
示例4: main
//.........这里部分代码省略.........
node = doc.RootElement();
assert( node );
XmlTest( "Root element exists.", true, ( node != 0 && node->ToElement() ) );
XmlTest ( "Root element value is 'ToDo'.", "ToDo", node->Value());
node = node->FirstChild();
XmlTest( "First child exists & is a comment.", true, ( node != 0 && node->ToComment() ) );
node = node->NextSibling();
XmlTest( "Sibling element exists & is an element.", true, ( node != 0 && node->ToElement() ) );
XmlTest ( "Value is 'Item'.", "Item", node->Value() );
node = node->FirstChild();
XmlTest ( "First child exists.", true, ( node != 0 && node->ToText() ) );
XmlTest ( "Value is 'Go to the'.", "Go to the", node->Value() );
//////////////////////////////////////////////////////
printf ("\n** Iterators. **\n");
// Walk all the top level nodes of the document.
count = 0;
for( node = doc.FirstChild();
node;
node = node->NextSibling() )
{
count++;
}
XmlTest( "Top level nodes, using First / Next.", 3, count );
count = 0;
for( node = doc.LastChild();
node;
node = node->PreviousSibling() )
{
count++;
}
XmlTest( "Top level nodes, using Last / Previous.", 3, count );
// Walk all the top level nodes of the document,
// using a different syntax.
count = 0;
for( node = doc.IterateChildren( 0 );
node;
node = doc.IterateChildren( node ) )
{
count++;
}
XmlTest( "Top level nodes, using IterateChildren.", 3, count );
// Walk all the elements in a node.
count = 0;
for( element = todoElement->FirstChildElement();
element;
element = element->NextSiblingElement() )
{
count++;
}
XmlTest( "Children of the 'ToDo' element, using First / Next.",
3, count );
// Walk all the elements in a node by value.
count = 0;
for( node = todoElement->FirstChild( "Item" );
node;
node = node->NextSibling( "Item" ) )
示例5: main
//.........这里部分代码省略.........
#endif
node = doc.RootElement();
XmlTest( "Root element exists.", true, ( node != 0 && node->ToElement() ) );
XmlTest ( "Root element value is 'ToDo'.", "ToDo", node->Value());
node = node->FirstChild();
XmlTest( "First child exists & is a comment.", true, ( node != 0 && node->ToComment() ) );
node = node->NextSibling();
XmlTest( "Sibling element exists & is an element.", true, ( node != 0 && node->ToElement() ) );
XmlTest ( "Value is 'Item'.", "Item", node->Value() );
node = node->FirstChild();
XmlTest ( "First child exists.", true, ( node != 0 && node->ToText() ) );
XmlTest ( "Value is 'Go to the'.", "Go to the", node->Value() );
//////////////////////////////////////////////////////
printf ("\n** Iterators. **\n");
// Walk all the top level nodes of the document.
count = 0;
for( node = doc.FirstChild();
node;
node = node->NextSibling() )
{
count++;
}
XmlTest( "Top level nodes, using First / Next.", 3, count );
count = 0;
for( node = doc.LastChild();
node;
node = node->PreviousSibling() )
{
count++;
}
XmlTest( "Top level nodes, using Last / Previous.", 3, count );
// Walk all the top level nodes of the document,
// using a different sytax.
count = 0;
for( node = doc.IterateChildren( 0 );
node;
node = doc.IterateChildren( node ) )
{
count++;
}
XmlTest( "Top level nodes, using IterateChildren.", 3, count );
// Walk all the elements in a node.
count = 0;
for( element = todoElement->FirstChildElement();
element;
element = element->NextSiblingElement() )
{
count++;
}
XmlTest( "Children of the 'ToDo' element, using First / Next.",
3, count );
// Walk all the elements in a node by value.
count = 0;
for( node = todoElement->FirstChild( "Item" );
node;
node = node->NextSibling( "Item" ) )
示例6: main
//.........这里部分代码省略.........
#endif
node = doc.RootElement();
XmlTest( "Root element exists.", true, ( node != 0 && node->ToElement() ) );
XmlTest ( "Root element value is 'ToDo'.", "ToDo", node->Value());
node = node->FirstChild();
XmlTest( "First child exists & is a comment.", true, ( node != 0 && node->ToComment() ) );
node = node->NextSibling();
XmlTest( "Sibling element exists & is an element.", true, ( node != 0 && node->ToElement() ) );
XmlTest ( "Value is 'Item'.", "Item", node->Value() );
node = node->FirstChild();
XmlTest ( "First child exists.", true, ( node != 0 && node->ToText() ) );
XmlTest ( "Value is 'Go to the'.", "Go to the", node->Value() );
//////////////////////////////////////////////////////
printf ("\n** Iterators. **\n");
// Walk all the top level nodes of the document.
count = 0;
for( node = doc.FirstChild();
node;
node = node->NextSibling() )
{
count++;
}
XmlTest( "Top level nodes, using First / Next.", 3, count );
count = 0;
for( node = doc.LastChild();
node;
node = node->PreviousSibling() )
{
count++;
}
XmlTest( "Top level nodes, using Last / Previous.", 3, count );
// Walk all the top level nodes of the document,
// using a different sytax.
count = 0;
for( node = doc.IterateChildren( 0 );
node;
node = doc.IterateChildren( node ) )
{
count++;
}
XmlTest( "Top level nodes, using IterateChildren.", 3, count );
// Walk all the elements in a node.
count = 0;
for( element = todoElement->FirstChildElement();
element;
element = element->NextSiblingElement() )
{
count++;
}
XmlTest( "Children of the 'ToDo' element, using First / Next.",
3, count );
// Walk all the elements in a node by value.
count = 0;
for( node = todoElement->FirstChild( "Item" );
node;
node = node->NextSibling( "Item" ) )