|
#include "stdafx.h"
#include "xml.h"
#include "globals.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
bool ParseVDStr( LPCTSTR&p, CString& t )
{
t.Empty( );
for( ; ; )
{
while( *p != '\"' && *p != '\\' && p != '\0' )
t+= *p++;
if( *p == '\"' )
{
++p;
return true;
}
if( *p == '\\' )
{
t+= *++p;
++p;
}
if( *p == '\0' )
return false;
}
}
HRESULT GetVDtoXML( CFile* file, CXML& xml )
{
//visual deployment rules:
//"name" of node.
// followed by '=' makes it a simple node like <test>data</test>
// followed by '{' makes it a parent node with element children.
// "DeployProject" will become the root node.
int depth= 0;
LPVOID buf;
const TCHAR* p;
CString name, data;
HRESULT result;
if( ( result= GetFileBuf( file, &buf ) ) != ERROR_SUCCESS )
return result;
p= (LPCTSTR)buf;
xml.CreateEmptyDoc( _T("VisualDevelopmentXML" ) );
for( ; ; )
{
//
while( _istspace( *p ) )
++p;
if( *p == '}' )
{
--depth;
xml.UpNode( );
++p;
if( depth == 0 )
break; //for(..)
else
continue;
}
ASSERT( *p == '\"' );
if( !ParseVDStr( ++p, name ) )
return ERROR_BAD_FORMAT;
while( _istspace( *p ) )
++p;
switch( *p )
{
//
case '{': //will have children.
{
++depth;
xml.AddNewNode( name );
++p;
break; //case
}
case '=': //lone child node
{
++p;
while( _istspace( *p ) )
++p;
ASSERT( *p == '\"' );
++p;
ParseVDStr( p, data );
xml.AddNewElement( name, data );
break; //case
}
//
}//case(..)
//
}//for(..)
free( buf );
return ERROR_SUCCESS;
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here