本文整理汇总了C++中XMLNode::IsDeclaration方法的典型用法代码示例。如果您正苦于以下问题:C++ XMLNode::IsDeclaration方法的具体用法?C++ XMLNode::IsDeclaration怎么用?C++ XMLNode::IsDeclaration使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XMLNode
的用法示例。
在下文中一共展示了XMLNode::IsDeclaration方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: XMLNode
/**
* Parses the given XML String and returns the main XMLNode
* @param xml_string XML String
* @param tag (?)
* @param pResults XMLResult object to write in on error or success
* @return The main XMLNode or empty XMLNode on error
*/
XMLNode *
XML::ParseString(const TCHAR *xml_string, Results *pResults)
{
// If String is empty
if (xml_string == nullptr) {
// If XML::Results object exists
if (pResults) {
// -> Save the error type
pResults->error = eXMLErrorNoElements;
pResults->line = 0;
pResults->column = 0;
}
// -> Return empty XMLNode
return nullptr;
}
Error error;
XMLNode xnode = XMLNode::Null();
Parser xml = { nullptr, 0, eXMLErrorNone, nullptr, 0, true, };
xml.lpXML = xml_string;
// Fill the XMLNode xnode with the parsed data of xml
// note: xnode is now the document node, not the main XMLNode
ParseXMLElement(xnode, &xml);
error = xml.error;
// If the document node does not have childnodes
XMLNode *child = xnode.GetFirstChild();
if (child == nullptr) {
// If XML::Results object exists
if (pResults) {
// -> Save the error type
pResults->error = eXMLErrorNoElements;
pResults->line = 0;
pResults->column = 0;
}
// -> Return empty XMLNode
return nullptr;
} else {
// Set the document's first childnode as new main node
xnode = std::move(*child);
}
// If the new main node is the xml declaration
// -> try to take the first childnode again
if (xnode.IsDeclaration()) {
// If the declaration does not have childnodes
child = xnode.GetFirstChild();
if (child == nullptr) {
// If XML::Results object exists
if (pResults) {
// -> Save the error type
pResults->error = eXMLErrorNoElements;
pResults->line = 0;
pResults->column = 0;
}
// -> Return empty XMLNode
return nullptr;
} else {
// Set the declaration's first childnode as new main node
xnode = std::move(*child);
}
}
// If an XML::Results object exists
// -> save the result (error/success)
if (pResults) {
pResults->error = error;
// If we have an error
if (error != eXMLErrorNone) {
// Find which line and column it starts on and
// save it in the XML::Results object
CountLinesAndColumns(xml.lpXML, xml.nIndex, pResults);
}
}
// If error occurred -> set node to empty
if (error != eXMLErrorNone)
return nullptr;
// Return the node (empty, main or child of main that equals tag)
return new XMLNode(std::move(xnode));
}
示例2: assert
//.........这里部分代码省略.........
case eTokenTagStart: /* '<' */
case eTokenTagEnd: /* '</' */
case eTokenEquals: /* '=' */
case eTokenDeclaration: /* '<?' */
pXML->error = eXMLErrorUnexpectedToken;
return false;
default:
break;
}
break;
// If we are looking for an equals
case eAttribEquals:
// Check what the current token type is
switch (token.type) {
// If the current type is text...
// Eg. 'Attribute AnotherAttribute'
case eTokenText:
// Add the unvalued attribute to the list
node.AddAttribute(std::move(attribute_name), _T(""), 0);
// Cache the token then indicate. We are next to
// look for the equals attribute
attribute_name.assign(token.pStr, token.length);
break;
// If we found a closing tag 'Attribute >' or a short hand
// closing tag 'Attribute />'
case eTokenShortHandClose:
case eTokenCloseTag:
assert(!attribute_name.empty());
// If we are a declaration element '<?' then we need
// to remove extra closing '?' if it exists
if (node.IsDeclaration() && attribute_name.back() == _T('?')) {
attribute_name.pop_back();
}
if (!attribute_name.empty())
// Add the unvalued attribute to the list
node.AddAttribute(std::move(attribute_name), _T(""), 0);
// If this is the end of the tag then return to the caller
if (token.type == eTokenShortHandClose)
return true;
// We are now outside the tag
status = eOutsideTag;
break;
// If we found the equals token...
// Eg. 'Attribute ='
case eTokenEquals:
// Indicate that we next need to search for the value
// for the attribute
attrib = eAttribValue;
break;
// Errors...
case eTokenQuotedText: /* 'Attribute "InvalidAttr"'*/
case eTokenTagStart: /* 'Attribute <' */
case eTokenTagEnd: /* 'Attribute </' */
case eTokenDeclaration: /* 'Attribute <?' */
pXML->error = eXMLErrorUnexpectedToken;
return false;
default:
break;