本文整理汇总了C++中CXMLNode::CopyChildrenInto方法的典型用法代码示例。如果您正苦于以下问题:C++ CXMLNode::CopyChildrenInto方法的具体用法?C++ CXMLNode::CopyChildrenInto怎么用?C++ CXMLNode::CopyChildrenInto使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CXMLNode
的用法示例。
在下文中一共展示了CXMLNode::CopyChildrenInto方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: xmlCopyFile
int CLuaXMLDefs::xmlCopyFile ( lua_State* luaVM )
{
#ifndef MTA_CLIENT
if ( lua_type ( luaVM, 3 ) == LUA_TLIGHTUSERDATA )
m_pScriptDebugging->LogCustom ( luaVM, "xmlCopyFile may be using an outdated syntax. Please check and update." );
#endif // !MTA_CLIENT
// Grab our resource
CLuaMain* pLUA = m_pLuaManager->GetVirtualMachine ( luaVM );
if ( pLUA )
{
SString strFile;
CXMLNode* pSourceNode;
CScriptArgReader argStream ( luaVM );
argStream.ReadUserData ( pSourceNode );
argStream.ReadString ( strFile );
if ( !argStream.HasErrors () )
{
SString strPath;
CResource* pThisResource = pLUA->GetResource ();
CResource* pOtherResource = pThisResource;
// Resolve other resource from name
if ( CResourceManager::ParseResourcePathInput ( strFile, pOtherResource, &strPath, NULL ) )
{
#ifndef MTA_CLIENT
// We have access to modify other resource?
if ( pOtherResource == pThisResource ||
m_pACLManager->CanObjectUseRight ( pThisResource->GetName ().c_str (),
CAccessControlListGroupObject::OBJECT_TYPE_RESOURCE,
"ModifyOtherObjects",
CAccessControlListRight::RIGHT_TYPE_GENERAL,
false ) )
#endif // !MTA_CLIENT
{
if ( pSourceNode ) {
// Make sure the dir exists so we can successfully make the file
MakeSureDirExists ( strPath );
// Grab the roots tag name
std::string strRootTagName;
strRootTagName = pSourceNode->GetTagName ();
// Create the new XML file and its root node
CXMLFile* pNewXML = pLUA->CreateXML ( strPath.c_str () );
if ( pNewXML )
{
// Grab the root of the new XML
CXMLNode* pNewRoot = pNewXML->CreateRootNode ( strRootTagName );
if ( pNewRoot )
{
// Copy over the attributes from the root
int iAttributeCount = pSourceNode->GetAttributes ().Count ();
int i = 0;
CXMLAttribute* pAttribute;
for ( ; i < iAttributeCount; i++ )
{
pAttribute = pSourceNode->GetAttributes ().Get ( i );
if ( pAttribute )
pNewRoot->GetAttributes ().Create ( *pAttribute );
}
// Copy the stuff from the given source node to the destination root
if ( pSourceNode->CopyChildrenInto ( pNewRoot, true ) )
{
lua_pushxmlnode ( luaVM, pNewRoot );
return 1;
}
}
// Delete the XML again
pLUA->DestroyXML ( pNewXML );
}
}
else
argStream.SetCustomError ( SString ( "Unable to copy XML file %s", strFile.c_str () ), "Bad filepath" );
}
#ifndef MTA_CLIENT
else
argStream.SetCustomError ( SString ( "ModifyOtherObjects in ACL denied resource '%s' to access '%s'", pThisResource->GetName ().c_str (), pOtherResource->GetName ().c_str () ), "Access denied" );
#endif
}
}
if ( argStream.HasErrors () )
m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );
}
// Error
lua_pushboolean ( luaVM, false );
return 1;
}
示例2: XMLCopyFile
int CLuaFunctionDefs::XMLCopyFile ( lua_State* luaVM )
{
// xmlnode xmlCopyFile ( xmlnode nodeToCopy, string newFilePath )
CXMLNode* pSourceNode; SString newFilePath;
CScriptArgReader argStream ( luaVM );
argStream.ReadUserData ( pSourceNode );
argStream.ReadString ( newFilePath );
if ( !argStream.HasErrors () )
{
// Grab the virtual machine for this luastate
CLuaMain* pLUA = m_pLuaManager->GetVirtualMachine ( luaVM );
if ( pLUA )
{
CResource* pResource = pLUA->GetResource();
SString strFilename;
if ( CResourceManager::ParseResourcePathInput( newFilePath, pResource, strFilename ) )
{
if ( pSourceNode )
{
// Grab the roots tag name
std::string strRootTagName;
strRootTagName = pSourceNode->GetTagName ();
// Grab our lua VM
CLuaMain* pLUA = m_pLuaManager->GetVirtualMachine ( luaVM );
// Create the new XML file and its root node
CXMLFile* pNewXML = pLUA->CreateXML ( strFilename );
if ( pNewXML )
{
// Create root for new XML
CXMLNode* pNewRoot = pNewXML->CreateRootNode ( strRootTagName );
if ( pNewRoot )
{
// Copy over the attributes from the root
int iAttributeCount = pSourceNode->GetAttributes ().Count ();
int i = 0;
CXMLAttribute* pAttribute;
for ( ; i < iAttributeCount; i++ )
{
pAttribute = pSourceNode->GetAttributes ().Get ( i );
if ( pAttribute )
pNewRoot->GetAttributes ().Create ( *pAttribute );
}
// Copy the stuff from the given source node to the destination root
if ( pSourceNode->CopyChildrenInto ( pNewRoot, true ) )
{
lua_pushxmlnode ( luaVM, pNewRoot );
return 1;
}
}
// Delete the XML again
pLUA->DestroyXML ( pNewXML );
}
}
}
else
CLogger::ErrorPrintf ( "Unable to copy xml file; bad filepath" );
}
}
else
m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );
// Error
lua_pushboolean ( luaVM, false );
return 1;
}
示例3: CopyChildrenInto
bool CXMLNodeImpl::CopyChildrenInto ( CXMLNode* pDestination, bool bRecursive )
{
// Delete all the children of the target
pDestination->DeleteAllSubNodes ();
// Iterate through our children if we have. Otherwize just copy the content
if ( m_Children.size () > 0 )
{
std::list < CXMLNode* > ::iterator iter = m_Children.begin ();
CXMLNode* pMyChildNode;
CXMLNode* pNewChildNode;
for ( ; iter != m_Children.end (); iter++ )
{
// Grab its tag name
pMyChildNode = *iter;
const std::string& strTagName = pMyChildNode->GetTagName ();
// Create at the destination
pNewChildNode = pDestination->CreateSubNode ( strTagName.c_str () );
if ( pNewChildNode )
{
// Copy our child's attributes into it
int iAttributeCount = pMyChildNode->GetAttributes ().Count ();
int i = 0;
CXMLAttribute* pAttribute;
for ( ; i < iAttributeCount; i++ )
{
// Create a copy of every attribute into our destination
pAttribute = pMyChildNode->GetAttributes ().Get ( i );
if ( pAttribute )
{
pNewChildNode->GetAttributes ().Create ( *pAttribute );
}
}
// Run it recursively if asked to. Copy child child nodes etc..
if ( bRecursive )
{
if ( !pMyChildNode->CopyChildrenInto ( pNewChildNode, true ) )
{
pDestination->DeleteAllSubNodes ();
return false;
}
}
}
else
{
pDestination->DeleteAllSubNodes ();
return false;
}
}
}
else
{
const char* szText = m_pNode->GetText ();
if ( szText )
pDestination->SetTagContent ( szText );
}
// Success
return true;
}