本文整理汇总了C++中TiXmlNode::ToDeclaration方法的典型用法代码示例。如果您正苦于以下问题:C++ TiXmlNode::ToDeclaration方法的具体用法?C++ TiXmlNode::ToDeclaration怎么用?C++ TiXmlNode::ToDeclaration使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TiXmlNode
的用法示例。
在下文中一共展示了TiXmlNode::ToDeclaration方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: read_from_configuration
void Profile::read_from_configuration (Configuration* configuration)
{
TiXmlNode* node = 0;
// insert initial mandatory declaration if not present
TiXmlNode* decl = 0;
for (TiXmlNode* child = xmlProfileDoc->FirstChild();
child && !decl; child = child->NextSibling() ) {
decl = child->ToDeclaration ();
}
if (! decl) {
node = xmlProfileDoc->InsertEndChild( TiXmlDeclaration( "1.0", "UTF-8", "no" ) );
assert (node);
}
// for each configuration variable in configuration
for (std::map<std::string, Variable*>::const_iterator conf_it = configuration->begin();
conf_it != configuration->end();
conf_it ++) {
// start from root of DOM
node = xmlProfileDoc;
// get the variable name and break it up in its component vector
std::string variable_name = conf_it->second->get_name ();
std::vector<std::string> variable_name_vector = Variable::string_to_vector (variable_name);
// for each component in variable name vector
for (size_t i = 0; i < variable_name_vector.size(); i++) {
// check if component element exists
TiXmlElement* existing = node->FirstChildElement (variable_name_vector[i].c_str());
if (existing) {
// carry on with existing component
node = existing;
} else {
// create missing component element and carry on with new component
node = node->InsertEndChild (TiXmlElement (variable_name_vector[i].c_str()));
assert (node);
}
}
// check if a text node for element exists
TiXmlText* text = 0;
for(TiXmlNode* child = node->FirstChild(); child && !text; child = child->NextSibling() ) {
text = child->ToText ();
}
if (text) {
// text child already exists, so remove it to set new value
node->RemoveChild (text);
}
node = node->InsertEndChild (TiXmlText (conf_it->second->get_value ().c_str ()));
assert (node);
}
}
示例2: LoadXMLFile
void XMLUtils::LoadXMLFile( TiXmlDocument& doc, bool condenseWhiteSpace, const wxString& path )
{
if ( path.empty() )
{
THROW_WXFBEX( _("LoadXMLFile needs a path") )
}
if ( !::wxFileExists( path ) )
{
THROW_WXFBEX( _("The file does not exist.\nFile: ") << path )
}
TiXmlBase::SetCondenseWhiteSpace( condenseWhiteSpace );
doc.SetValue( std::string( path.mb_str( wxConvFile ) ) );
if ( !doc.LoadFile() )
{
// Ask user to all wxFB to convert the file to UTF-8 and add the XML declaration
wxString msg = _("This xml file could not be loaded. This could be the result of an unsupported encoding.\n");
msg += _("Would you like wxFormBuilder to backup the file and convert it to UTF-8\?\n");
msg += _("You will be prompted for the original encoding.\n\n");
msg += _("Path: ");
msg += path;
if ( wxNO == wxMessageBox( msg, _("Unable to load file"), wxICON_QUESTION | wxYES_NO | wxYES_DEFAULT, wxTheApp->GetTopWindow() ) )
{
// User declined, give up
THROW_WXFBEX( _("Unable to load file: ") << path );
}
// User accepted, convert the file
wxFontEncoding chosenEncoding = StringUtils::GetEncodingFromUser( _("Please choose the original encoding.") );
if ( wxFONTENCODING_MAX == chosenEncoding )
{
THROW_WXFBEX( _("Unable to load file: ") << path );
}
ConvertAndAddDeclaration( path, chosenEncoding );
LoadXMLFile( doc, condenseWhiteSpace, path );
}
TiXmlDeclaration* declaration = NULL;
TiXmlNode* firstChild = doc.FirstChild();
if ( firstChild )
{
declaration = firstChild->ToDeclaration();
}
LoadXMLFileImp( doc, condenseWhiteSpace, path, declaration );
}
示例3: GetDeclaration
void JXmlDocument::GetDeclaration(JString& version, JString& encoding, JString& standlone)
{
TiXmlNode* child = NULL;
while( child = m_xmlDoc.IterateChildren(child) ){
if( IsDeclarationNode(child) ){
#ifdef UNICODE
version = Utf8ToWideString(child->ToDeclaration()->Version());
encoding = Utf8ToWideString(child->ToDeclaration()->Encoding());
standlone = Utf8ToWideString(child->ToDeclaration()->Standalone());
#else
version = child->ToDeclaration()->Version();
encoding = child->ToDeclaration()->Encoding();
standlone = child->ToDeclaration()->Standalone();
#endif
break;
}
}
}
示例4: Parse
const char* TiXmlDocument::Parse( const char* p, TiXmlParsingData* prevData, TiXmlEncoding encoding )
{
ClearError();
// Parse away, at the document level. Since a document
// contains nothing but other tags, most of what happens
// here is skipping white space.
if ( !p || !*p )
{
SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN );
return 0;
}
// Note that, for a document, this needs to come
// before the while space skip, so that parsing
// starts from the pointer we are given.
location.Clear();
if ( prevData )
{
location.row = prevData->cursor.row;
location.col = prevData->cursor.col;
}
else
{
location.row = 0;
location.col = 0;
}
TiXmlParsingData data( p, TabSize(), location.row, location.col );
location = data.Cursor();
if ( encoding == TIXML_ENCODING_UNKNOWN )
{
// Check for the Microsoft UTF-8 lead bytes.
const unsigned char* pU = (const unsigned char*)p;
if ( *(pU+0) && *(pU+0) == TIXML_UTF_LEAD_0
&& *(pU+1) && *(pU+1) == TIXML_UTF_LEAD_1
&& *(pU+2) && *(pU+2) == TIXML_UTF_LEAD_2 )
{
encoding = TIXML_ENCODING_UTF8;
useMicrosoftBOM = true;
}
}
p = SkipWhiteSpace( p, encoding );
if ( !p )
{
SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN );
return 0;
}
while ( p && *p )
{
TiXmlNode* node = Identify( p, encoding );
if ( node )
{
p = node->Parse( p, &data, encoding );
LinkEndChild( node );
}
else
{
break;
}
// Did we get encoding info?
if ( encoding == TIXML_ENCODING_UNKNOWN
&& node->ToDeclaration() )
{
TiXmlDeclaration* dec = node->ToDeclaration();
const char* enc = dec->Encoding();
assert( enc );
if ( *enc == 0 )
encoding = TIXML_ENCODING_UTF8;
else if ( StringEqual( enc, "UTF-8", true, TIXML_ENCODING_UNKNOWN ) )
encoding = TIXML_ENCODING_UTF8;
else if ( StringEqual( enc, "UTF8", true, TIXML_ENCODING_UNKNOWN ) )
encoding = TIXML_ENCODING_UTF8; // incorrect, but be nice
else
encoding = TIXML_ENCODING_LEGACY;
}
p = SkipWhiteSpace( p, encoding );
}
// Was this empty?
if ( !firstChild ) {
SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, encoding );
return 0;
}
// All is well.
return p;
}
示例5: updTiXmlDeclaration
TiXmlDeclaration& updTiXmlDeclaration() {
TiXmlNode* decl = m_tixml.FirstChild();
assert(decl && decl->Type()==TiXmlNode::DECLARATION);
return *decl->ToDeclaration();
}
示例6: data
const char* TiXmlDocument::Parse
( const char* p, TiXmlParsingData* prevData, TiXmlEncoding encoding )
{
ClearError();
// Parse away, at the document level. Since a document
// contains nothing but other tags, most of what happens
// here is skipping white space.
// sherm 100319: I changed this so that untagged top-level text is
// parsed as a Text node rather than a parsing error. CDATA text was
// already allowed at the top level so this seems more consistent.
if ( !p || !*p )
{
SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN );
return 0;
}
// Note that, for a document, this needs to come
// before the while space skip, so that parsing
// starts from the pointer we are given.
location.Clear();
if ( prevData )
{
location.row = prevData->cursor.row;
location.col = prevData->cursor.col;
}
else
{
location.row = 0;
location.col = 0;
}
TiXmlParsingData data( p, TabSize(), location.row, location.col );
location = data.Cursor();
if ( encoding == TIXML_ENCODING_UNKNOWN )
{
// Check for the Microsoft UTF-8 lead bytes.
const unsigned char* pU = (const unsigned char*)p;
if ( *(pU+0) && *(pU+0) == TIXML_UTF_LEAD_0
&& *(pU+1) && *(pU+1) == TIXML_UTF_LEAD_1
&& *(pU+2) && *(pU+2) == TIXML_UTF_LEAD_2 )
{
encoding = TIXML_ENCODING_UTF8;
useMicrosoftBOM = true;
}
}
// Remember the start of white space in case we end up reading a text
// element in a "keep white space" mode.
const char* pWithWhiteSpace = p;
p = SkipWhiteSpace( p, encoding );
if ( !p )
{
SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN );
return 0;
}
// sherm 100319: ignore all but the first Declaration
bool haveSeenDeclaration = false;
while ( p && *p )
{
TiXmlNode* node = 0;
if ( *p != '<' )
{ // sherm 100319: I added this case by stealing the code from
// Element parsing; see above comment.
// Take what we have, make a text element.
TiXmlText* textNode = new TiXmlText( "" );
if ( !textNode )
{
SetError( TIXML_ERROR_OUT_OF_MEMORY, 0, 0, encoding );
return 0;
}
if ( TiXmlBase::IsWhiteSpaceCondensed() )
{
p = textNode->Parse( p, &data, encoding );
}
else
{
// Special case: we want to keep the white space
// so that leading spaces aren't removed.
p = textNode->Parse( pWithWhiteSpace, &data, encoding );
}
if ( !textNode->Blank() ) {
LinkEndChild( textNode );
node = textNode;
}
else
delete textNode;
}
else // We saw a '<', now identify what kind of tag it is.
{
TiXmlNode* node = Identify( p, encoding );
if ( node )
{
p = node->Parse( p, &data, encoding );
if (node->ToDeclaration()) {
if (haveSeenDeclaration) {
//.........这里部分代码省略.........