MarkupDlg.cpp
Upload User: wbm1988
Upload Date: 2022-08-06
Package Size: 3696k
Code Size: 81k
Category:

Windows Develop

Development Platform:

Visual C++

  1. // MarkupDlg.cpp : implementation file
  2. //
  3. // Markup Release 9.0
  4. // Copyright (C) 1999-2007 First Objective Software, Inc. All rights reserved
  5. // Go to www.firstobject.com for the latest CMarkup and EDOM documentation
  6. // Use in commercial applications requires written permission
  7. // This software is provided "as is", with no warranty.
  8. #include "stdafx.h"
  9. #include "MarkupApp.h"
  10. #include "MarkupDlg.h"
  11. #include <afxpriv.h>
  12. #include <io.h>
  13. #include <locale.h>
  14. #include <math.h> 
  15. #include <stdio.h> 
  16. #include <stdlib.h> 
  17. #include <string.h> 
  18. #define OPSETSIZE 8 
  19. typedef int Status; 
  20. #ifdef MARKUP_MSXML
  21. #include "MarkupMSXML.h"
  22. #define MCD_STR CString
  23. #define MCD_2PCSZ(s) ((LPCTSTR)s)
  24. #define MCD_STRCLEAR(s) s.Empty()
  25. #define MCD_STRISEMPTY(s) s.IsEmpty()
  26. #else
  27. #include "Markup.h"
  28. #endif
  29. #ifdef _DEBUG
  30. #define new DEBUG_NEW
  31. #undef THIS_FILE
  32. static char THIS_FILE[] = __FILE__;
  33. #endif
  34. unsigned char Prior[8][8] = { // 表3.1 算符间的优先关系 
  35. // '+' '-' '*' '/' '(' ')' '#' '^' 
  36. /*'+'*/'>','>','<','<','<','>','>','<', 
  37. /*'-'*/'>','>','<','<','<','>','>','<', 
  38. /*'*'*/'>','>','>','>','<','>','>','<', 
  39. /*'/'*/'>','>','>','>','<','>','>','<', 
  40. /*'('*/'<','<','<','<','<','=',' ','<', 
  41. /*')'*/'>','>','>','>',' ','>','>','>', 
  42. /*'#'*/'<','<','<','<','<',' ','=','<', 
  43. /*'^'*/'>','>','>','>','<','>','>','>' 
  44. }; 
  45. CMarkup xml;
  46. /////////////////////////////////////////////////////////////////////////////
  47. // CMarkupDlg dialog
  48. CMarkupDlg::CMarkupDlg(CWnd* pParent /*=NULL*/)
  49. : CDialog(CMarkupDlg::IDD, pParent)
  50. {
  51. //{{AFX_DATA_INIT(CMarkupDlg)
  52. m_cmdEdit = _T("");
  53. //}}AFX_DATA_INIT
  54. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  55. }
  56. void CMarkupDlg::DoDataExchange(CDataExchange* pDX)
  57. {
  58. CDialog::DoDataExchange(pDX);
  59. //{{AFX_DATA_MAP(CMarkupDlg)
  60. DDX_Text(pDX, IDC_CMD_EDIT, m_cmdEdit);
  61. //}}AFX_DATA_MAP
  62. }
  63. BEGIN_MESSAGE_MAP(CMarkupDlg, CDialog)
  64. //{{AFX_MSG_MAP(CMarkupDlg)
  65. ON_WM_PAINT()
  66. ON_WM_QUERYDRAGICON()
  67. ON_BN_CLICKED(IDC_BUTTON_BROWSE, OnButtonBrowse)
  68. ON_BN_CLICKED(IDC_BUTTON_PARSE, OnButtonParse)
  69. ON_WM_DESTROY()
  70. ON_BN_CLICKED(IDC_TEST_XML_NEW, OnTestXmlNew)
  71. ON_BN_CLICKED(IDC_COMPILE, OnCompile)
  72. ON_BN_CLICKED(IDC_CLEAR, OnClear)
  73. ON_BN_CLICKED(IDC_OPEN_EXISTS, OnOpenExists)
  74. ON_BN_CLICKED(IDC_SAVE_AS, OnSaveAs)
  75. ON_WM_TIMER()
  76. //}}AFX_MSG_MAP
  77. END_MESSAGE_MAP()
  78. void CMarkupDlg::OnPaint() 
  79. {
  80. if (IsIconic())
  81. {
  82. CPaintDC dc(this); // device context for painting
  83. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  84. // Center icon in client rectangle
  85. int cxIcon = GetSystemMetrics(SM_CXICON);
  86. int cyIcon = GetSystemMetrics(SM_CYICON);
  87. CRect rect;
  88. GetClientRect(&rect);
  89. int x = (rect.Width() - cxIcon + 1) / 2;
  90. int y = (rect.Height() - cyIcon + 1) / 2;
  91. // Draw the icon
  92. dc.DrawIcon(x, y, m_hIcon);
  93. }
  94. else
  95. {
  96. CDialog::OnPaint();
  97. }
  98. }
  99. HCURSOR CMarkupDlg::OnQueryDragIcon()
  100. {
  101. return (HCURSOR) m_hIcon;
  102. }
  103. /////////////////////////////////////////////////////////////////////////////
  104. // CMarkupDlg message handlers
  105. BOOL CMarkupDlg::OnInitDialog()
  106. {
  107. CDialog::OnInitDialog();
  108. SetIcon(m_hIcon, TRUE); // Set big icon
  109. SetIcon(m_hIcon, FALSE); // Set small icon
  110. SystemSettings( TRUE );
  111. m_nErrorCount = 0;
  112. m_nTotalZones = 0;
  113. m_nTotalChecks = 0;
  114. SetWindowText( _T("CMarkup Evaluation Test Dialog") );
  115. // Determine version
  116. CString csVersion, csV0, csV1;
  117. CString csTitle;
  118. csVersion.LoadString( ID_APP_VERSION );
  119. AfxExtractSubString( csV0, csVersion, 0, ',' );
  120. AfxExtractSubString( csV1, csVersion, 1, ',' );
  121. CString csClass = _T("CMarkup");
  122. CString csBuild;
  123. #if defined( MARKUP_MSXML )
  124. csClass += _T("MSXML");
  125. #if defined( MARKUP_MSXML3 )
  126. csClass += _T(" MSXML3");
  127. #elif defined( MARKUP_MSXML4 )
  128. csClass += _T(" MSXML4");
  129. #endif
  130. #endif
  131. #if defined( MARKUP_STL )
  132. csBuild += _T(" STL");
  133. #endif
  134. #if defined( _DEBUG )
  135. csBuild += _T(" Debug");
  136. #endif
  137. #if defined( _UNICODE )
  138. csBuild += _T(" Unicode");
  139. #endif
  140. #if defined( _MBCS )
  141. csBuild += _T(" MBCS");
  142. #endif
  143. csTitle.Format( _T("%s %s.%s%srn"), csClass, csV0, csV1, csBuild );
  144. OutputTestResults( csTitle );
  145. OutputParseResults( _T("") );
  146. RunTest();
  147. return TRUE;  // return TRUE  unless you set the focus to a control
  148. }
  149. void CMarkupDlg::OnDestroy() 
  150. {
  151. SystemSettings( FALSE );
  152. CDialog::OnDestroy();
  153. }
  154. void CMarkupDlg::OutputTestResults( CString csMsg )
  155. {
  156. m_csTestResults += csMsg;
  157. // GetDlgItem( IDC_ST_TEST_RESULTS )->SetWindowText( m_csTestResults );
  158. }
  159. int CMarkupDlg::Alert( CString csMsg )
  160. {
  161. m_csChecks += csMsg + _T("rn");
  162. ++m_nErrorCount;
  163. return -1;
  164. }
  165. void CMarkupDlg::StartCheckZone( CString csCheckZone )
  166. {
  167. m_nCheckCount = 0;
  168. ++m_nTotalZones;
  169. m_csCheckZone = csCheckZone;
  170. }
  171. int CMarkupDlg::Check( BOOL bCorrect )
  172. {
  173. ++m_nCheckCount;
  174. ++m_nTotalChecks;
  175. if ( ! bCorrect )
  176. {
  177. if ( m_csCheckZone.IsEmpty() )
  178. m_csCheckZone = _T("Unknown Check Zone");
  179. CString csMsg;
  180. csMsg.Format( _T("Error: %s, check %d"), m_csCheckZone, m_nCheckCount );
  181. return Alert( csMsg );
  182. }
  183. return 0;
  184. }
  185. #ifdef MARKUP_MSXML
  186. void SetEntry( CMarkupMSXML& xml, MCD_STR strSection, MCD_STR strEntry, MCD_STR strValue )
  187. #else
  188. void SetEntry( CMarkup& xml, MCD_STR strSection, MCD_STR strEntry, MCD_STR strValue )
  189. #endif
  190. {
  191. // Find/Create root element of xml document
  192. xml.ResetPos();
  193. if ( ! xml.FindElem() )
  194. xml.AddElem( _T("sbml") ); // or whatever root element name is
  195. // Find/Create section
  196. BOOL bFoundSection = FALSE;
  197. while ( xml.FindChildElem(_T("Section")) )
  198. {
  199. // Is this the right section?
  200. if ( xml.GetChildAttrib(_T("name")) == strSection )
  201. {
  202. bFoundSection = TRUE;
  203. break;
  204. }
  205. }
  206. if ( ! bFoundSection )
  207. {
  208. xml.AddChildElem( _T("Section") );
  209. xml.SetChildAttrib( _T("name"), strSection );
  210. }
  211. // Find/Create entry
  212. xml.IntoElem();
  213. BOOL bFoundEntry = FALSE;
  214. while ( xml.FindChildElem(_T("Entry")) )
  215. {
  216. // Is this the right entry?
  217. if ( xml.GetChildAttrib(_T("name")) == strEntry )
  218. {
  219. bFoundEntry = TRUE;
  220. break;
  221. }
  222. }
  223. if ( ! bFoundEntry )
  224. {
  225. xml.AddChildElem( _T("Entry") );
  226. xml.SetChildAttrib( _T("name"), strEntry );
  227. }
  228. // Set value
  229. xml.SetChildData( strValue );
  230. }
  231. #ifdef MARKUP_MSXML
  232. bool FindEntry( CMarkupMSXML& xml, MCD_STR strSection, MCD_STR strEntry, MCD_STR& strValue )
  233. #else
  234. bool FindEntry( CMarkup& xml, MCD_STR strSection, MCD_STR strEntry, MCD_STR& strValue )
  235. #endif
  236. {
  237. // Loop through sections
  238. xml.ResetPos();
  239. while ( xml.FindChildElem(_T("Section")) )
  240. {
  241. // Is this the right section?
  242. if ( xml.GetChildAttrib(_T("name")) == strSection )
  243. {
  244. // Check entries in this section
  245. xml.IntoElem();
  246. while ( xml.FindChildElem(_T("Entry")) )
  247. {
  248. // Is this the right entry?
  249. if ( xml.GetChildAttrib(_T("name")) == strEntry )
  250. {
  251. strValue = xml.GetChildData();
  252. return TRUE;
  253. }
  254. }
  255. break; // don't check any other sections
  256. }
  257. }
  258. return FALSE;
  259. }
  260. CString CMarkupDlg::GetSpecialPath( int nFolderID )
  261. {
  262. CString csPath;
  263. TCHAR szSpecialPath[MAX_PATH];
  264. LPITEMIDLIST pidl;
  265. if( SUCCEEDED(SHGetSpecialFolderLocation(0,nFolderID,&pidl)) )
  266. {
  267. SHGetPathFromIDList( pidl, szSpecialPath );
  268. LPMALLOC pMalloc = NULL;
  269. SHGetMalloc(&pMalloc);
  270. pMalloc->Free( pidl );
  271. pMalloc->Release();
  272. csPath = szSpecialPath;
  273. csPath += "\";
  274. }
  275. return csPath;
  276. }
  277. #if ! defined(_UNICODE)
  278. CString CMarkupDlg::WinAToUTF8( CString csText )
  279. {
  280. int nMBLen = csText.GetLength();
  281. if ( nMBLen )
  282. {
  283. wchar_t* pwszWide = new wchar_t[nMBLen+1];
  284. int nWideLen = MultiByteToWideChar(CP_ACP,0,csText,nMBLen,pwszWide,nMBLen);
  285. pwszWide[nWideLen] = (wchar_t)0;
  286. int nUTF8Len = nWideLen * 4 + 1;
  287. char* pUTF8 = csText.GetBuffer( nUTF8Len );
  288. nUTF8Len = WideCharToMultiByte(CP_UTF8,0,pwszWide,nWideLen,pUTF8,nUTF8Len,NULL,NULL);
  289. delete[] pwszWide;
  290. csText.ReleaseBuffer( nUTF8Len );
  291. }
  292. return csText;
  293. }
  294. CString CMarkupDlg::WinUTF8ToA( CString csText )
  295. {
  296. int nUTF8Len = csText.GetLength();
  297. if ( nUTF8Len )
  298. {
  299. wchar_t* pwszWide = new wchar_t[nUTF8Len+1];
  300. int nWideLen = MultiByteToWideChar(CP_UTF8,0,csText,nUTF8Len,pwszWide,nUTF8Len);
  301. pwszWide[nWideLen] = (wchar_t)0;
  302. int nMBLen = nWideLen * 2 + 1;
  303. char* pMB = csText.GetBuffer( nMBLen );
  304. BOOL bUsedDefault = FALSE;
  305. nMBLen = WideCharToMultiByte(CP_ACP,0,pwszWide,nWideLen,pMB,nMBLen,"?",&bUsedDefault);
  306. delete[] pwszWide;
  307. csText.ReleaseBuffer( nMBLen );
  308. }
  309. return csText;
  310. }
  311. #endif
  312. void CMarkupDlg::SystemSettings( BOOL bLoad )
  313. {
  314. #ifdef MARKUP_MSXML
  315. CMarkupMSXML xmlSettings;
  316. #else
  317. CMarkup xmlSettings;
  318. #endif
  319. // Find/Create app data folder
  320. CString csUserAppDataPath = GetSpecialPath( 0x001a ); // CSIDL_APPDATA
  321. if ( csUserAppDataPath.IsEmpty() )
  322. return;
  323. CString csCompanyFolder = csUserAppDataPath + "firstobject";
  324. CString csSettingsFolder = csCompanyFolder + "\CMarkup";
  325. CString csSettingsPathName = csSettingsFolder + "\settings.xml";
  326. #if defined( _MBCS )
  327. setlocale( LC_ALL, "C" );
  328. setlocale( LC_ALL, "" );
  329. #endif
  330. if ( ! xmlSettings.Load((LPCTSTR)csSettingsPathName) )
  331. {
  332. if ( _taccess(csCompanyFolder,0) != 0 )
  333. {
  334. if ( ! CreateDirectory(csCompanyFolder,NULL) )
  335. return;
  336. }
  337. if ( _taccess(csSettingsFolder,0) != 0 )
  338. {
  339. if ( ! CreateDirectory(csSettingsFolder,NULL) )
  340. return;
  341. }
  342. }
  343. if ( bLoad )
  344. {
  345. MCD_STR strFilename;
  346. if ( FindEntry(xmlSettings,_T("Settings"),_T("Filename"),strFilename) && strFilename != _T("") )
  347. {
  348. CString csFilename = MCD_2PCSZ(strFilename);
  349. #if ! defined(_UNICODE) && ! defined(_MBCS)
  350. csFilename = WinUTF8ToA( csFilename );
  351. #endif
  352. GetDlgItem( IDC_EDIT_FILE )->SetWindowText( csFilename );
  353. }
  354. MCD_STR csPos;
  355. if ( FindEntry(xmlSettings,_T("Settings"),_T("Position"),csPos) )
  356. {
  357. CPoint ptDlg;
  358. if ( _stscanf( MCD_2PCSZ(csPos), _T("%d,%d"), &ptDlg.x, &ptDlg.y ) == 2 )
  359. {
  360. CRect rect;
  361. GetWindowRect( &rect );
  362. if ( rect.Width() > 10 )
  363. {
  364. rect.OffsetRect( ptDlg.x - rect.left, ptDlg.y - rect.top ); 
  365. MoveWindow( &rect );
  366. }
  367. }
  368. }
  369. }
  370. else // save
  371. {
  372. CString csFilename;
  373. GetDlgItem( IDC_EDIT_FILE )->GetWindowText( csFilename );
  374. #if ! defined(_UNICODE) && ! defined(_MBCS)
  375. csFilename = WinAToUTF8( csFilename );
  376. #endif
  377. MCD_STR strFilename = csFilename;
  378. SetEntry( xmlSettings, _T("Settings"), _T("Filename"), strFilename );
  379. CRect rect;
  380. GetWindowRect( &rect );
  381. CString csPos;
  382. csPos.Format( _T("%d,%d"), rect.left, rect.top );
  383. MCD_STR strPos = csPos;
  384. SetEntry( xmlSettings, _T("Settings"), _T("Position"), strPos );
  385. xmlSettings.Save( (LPCTSTR)csSettingsPathName );
  386. }
  387. }
  388. #ifdef MARKUP_MSXML
  389. void SimpleMerge( CMarkupMSXML& xmlMaster, CMarkupMSXML& xmlUpdate )
  390. #else
  391. void SimpleMerge( CMarkup& xmlMaster, CMarkup& xmlUpdate )
  392. #endif
  393. {
  394. // Generic merge xmlUpdate into xmlMaster when element names are unique among siblings
  395. // removing elements from xmlUpdate as added to or overrided in xmlMaster
  396. //
  397. MCD_STR strMergeName;
  398. xmlMaster.ResetPos();
  399. xmlUpdate.ResetPos();
  400. BOOL bMergeFinished = FALSE;
  401. if ( ! xmlMaster.FindChildElem() )
  402. {
  403. xmlMaster = xmlUpdate;
  404. bMergeFinished = TRUE;
  405. }
  406. xmlUpdate.FindChildElem();
  407. while ( ! bMergeFinished )
  408. {
  409. // Process Element
  410. xmlMaster.IntoElem();
  411. xmlUpdate.IntoElem();
  412. strMergeName = xmlMaster.GetTagName();
  413. // Did this one match?
  414. xmlUpdate.ResetMainPos();
  415. BOOL bMatched = xmlUpdate.FindElem( strMergeName );
  416. if ( bMatched )
  417. {
  418. // Merge attributes
  419. for ( int nAttrib=0; !MCD_STRISEMPTY((strMergeName=xmlUpdate.GetAttribName(nAttrib))); ++nAttrib )
  420. xmlMaster.SetAttrib( strMergeName, xmlUpdate.GetAttrib(strMergeName) );
  421. }
  422. // Next element (depth first)
  423. BOOL bChildFound = xmlMaster.FindChildElem();
  424. while ( ! bChildFound && ! bMergeFinished )
  425. {
  426. if ( bMatched )
  427. {
  428. while ( xmlUpdate.FindChildElem() )
  429. {
  430. xmlMaster.AddChildSubDoc( xmlUpdate.GetChildSubDoc() );
  431. xmlUpdate.RemoveChildElem();
  432. }
  433. xmlUpdate.RemoveElem();
  434. }
  435. if ( xmlMaster.OutOfElem() )
  436. {
  437. xmlUpdate.OutOfElem();
  438. bChildFound = xmlMaster.FindChildElem();
  439. if ( ! bChildFound )
  440. {
  441. bMatched = TRUE;
  442. xmlUpdate.ResetChildPos();
  443. }
  444. }
  445. else
  446. bMergeFinished = TRUE;
  447. }
  448. }
  449. }
  450. CString TruncToLastEOL( CString csVal )
  451. {
  452. // locate and truncate from final EOL
  453. // also cuts any trailing indentation
  454. int nLength = csVal.GetLength();
  455. const _TCHAR* pszVal = (const _TCHAR*)csVal;
  456. int nLastEOL = nLength;
  457. int nChar = 0;
  458. while ( nChar < nLength )
  459. {
  460. // Go to next EOL
  461. nLastEOL = nLength;
  462. while ( nChar < nLength && pszVal[nChar] != _T('r')
  463. && pszVal[nChar] != _T('n') )
  464. nChar += (int)_tclen(&pszVal[nChar]);
  465. nLastEOL = nChar;
  466. while ( nChar < nLength
  467. && _tcschr(_T(" tnr"),pszVal[nChar]) )
  468. ++nChar;
  469. }
  470. if ( nLastEOL < nLength )
  471. csVal = csVal.Left( nLastEOL );
  472. return csVal;
  473. }
  474. int CMarkupDlg::RunTest()
  475. {
  476. // Instantiate XML objects for use in tests
  477. // Mostly the same code can be used to test the different versions of CMarkup
  478. // However, to convert both CString and std::string to const char *, use MCD_2PCSZ()
  479. #ifdef MARKUP_MSXML
  480. CMarkupMSXML xml, xml2, xml3;
  481. #else
  482. CMarkup xml, xml2, xml3;
  483. #endif
  484. // Integer Method Test
  485. StartCheckZone( _T("Integer Method Test") );
  486. xml.SetDoc( NULL );
  487. xml.AddElem( _T("R"), 5 );
  488. Check( _ttoi(MCD_2PCSZ(xml.GetData())) == 5 );
  489. xml.SetData( _T("") );
  490. Check( xml.InsertChildElem( _T("C"), 1 ) );
  491. Check( xml.AddChildElem( _T("C"), 3 ) );
  492. Check( xml.IntoElem() );
  493. Check( xml.InsertElem( _T("C"), 2 ) );
  494. xml.ResetMainPos();
  495. Check( xml.FindElem() );
  496. Check( _ttoi(MCD_2PCSZ(xml.GetData())) == 1 );
  497. Check( xml.FindElem() );
  498. Check( _ttoi(MCD_2PCSZ(xml.GetData())) == 2 );
  499. Check( xml.FindElem() );
  500. Check( _ttoi(MCD_2PCSZ(xml.GetData())) == 3 );
  501. // Quote and special chars in attrib value test
  502. StartCheckZone( _T("Attrib Value Test") );
  503. Check( xml.SetDoc( _T("<H g1=">" g2='>' d="d'd" s='s"s'/>") ) );
  504. Check( xml.FindElem() );
  505. Check( xml.GetAttrib(_T("d")) == _T("d'd") );
  506. Check( xml.GetAttrib(_T("s")) == _T("s"s") );
  507. Check( xml.SetAttrib( _T("d"), _T("d'd") ) );
  508. Check( xml.GetAttrib(_T("d")) == _T("d'd") );
  509. Check( xml.GetAttrib(_T("s")) == _T("s"s") );
  510. Check( xml.GetAttrib(_T("g1")) == _T(">") );
  511. Check( xml.GetAttrib(_T("g2")) == _T(">") );
  512. // FindElem Tag Name Test
  513. StartCheckZone( _T("FindElem Tag Name Test") );
  514. xml.SetDoc( NULL );
  515. xml.AddElem( _T("R") );
  516. xml.AddChildElem( _T("N"), _T("A") );
  517. xml.AddChildElem( _T("Name"), _T("B") );
  518. xml.AddChildElem( _T("Na"), _T("C") );
  519. xml.AddChildElem( _T("Nam"), _T("D") );
  520. xml.ResetChildPos();
  521. Check( xml.FindChildElem(_T("Name")) );
  522. Check( xml.GetChildData() == _T("B") );
  523. Check( xml.FindChildElem(_T("Nam")) );
  524. Check( xml.GetChildData() == _T("D") );
  525. // Copy Constructor Heap Test
  526. #ifndef MARKUP_MSXML
  527. StartCheckZone( _T("Copy Constructor Heap Test") );
  528. Check( AfxCheckMemory() );
  529. CMarkup xmlTest(xml);
  530. Check( AfxCheckMemory() );
  531. xmlTest.AddElem( _T("AfterCopyEmpty") );
  532. Check( AfxCheckMemory() );
  533. xmlTest.SetDoc( NULL );
  534. xml = xmlTest;
  535. xml.AddElem( _T("AfterCopyEmpty") );
  536. Check( AfxCheckMemory() );
  537. #endif
  538. // CDATA Section Test
  539. StartCheckZone( _T("CDATA Section Test") );
  540. xml.SetDoc( NULL );
  541. Check( xml.AddElem( _T("R") ) );
  542. Check( xml.AddChildElem( _T("C") ) );
  543. Check( xml.SetChildData( _T("a]]>b]]>c]]>d"), 1 ) );
  544. Check( xml.GetChildData() == _T("a]]>b]]>c]]>d") );
  545. Check( xml.IntoElem() );
  546. Check( xml.SetData( _T("]]>"), 1 ) );
  547. Check( xml.GetData() == _T("]]>") );
  548. MCD_STR strCDATASubDoc = _T("<C><![CDATA[a]]>]]&gt;<![CDATA[a]]></C>");
  549. Check( xml.AddSubDoc( strCDATASubDoc ) );
  550. Check( xml.GetData() == _T("a]]>a") );
  551. // Underscore tag name check
  552. StartCheckZone( _T("Tag Name Test") );
  553. xml.SetDoc( NULL );
  554. Check( xml.AddElem( _T("_Underscore") ) );
  555. MCD_STR strTagNameDoc = xml.GetDoc();
  556. Check( xml.SetDoc( strTagNameDoc ) );
  557. xml.FindElem();
  558. Check( xml.GetTagName() == _T("_Underscore") );
  559. // ORDER Test, simple XML example
  560. StartCheckZone( _T("ORDER Test") );
  561. xml.SetDoc( NULL );
  562. Check( xml.AddElem( _T("ORDER") ) );
  563. Check( xml.IntoElem() );
  564. Check( xml.AddElem( _T("ITEM") ) );
  565. Check( xml.AddChildElem( _T("NAME"), _T("carrots") ) );
  566. Check( xml.AddChildElem( _T("QTY"), _T("1") ) );
  567. Check( xml.AddChildElem( _T("PRICE"), _T(".98") ) );
  568. Check( xml.AddChildAttrib( _T("unit"), _T("1 lb") ) );
  569. Check( xml.AddElem( _T("ITEM") ) );
  570. Check( xml.AddChildElem( _T("NAME"), _T("onions") ) );
  571. Check( xml.AddChildElem( _T("QTY"), _T("1") ) );
  572. Check( xml.AddChildElem( _T("PRICE"), _T("1.10") ) );
  573. Check( xml.AddChildAttrib( _T("unit"), _T("3 lb bag") ) );
  574. Check( xml.AddChildElem( _T("SUPPLIER"), _T("Hanover") ) );
  575. // Create List
  576. StartCheckZone( _T("List Test") );
  577. MCD_STR strList;
  578. xml.ResetPos();
  579. Check( xml.FindElem( _T("ORDER") ) );
  580. while ( xml.FindChildElem( _T("ITEM") ) )
  581. {
  582. xml.IntoElem();
  583. xml.FindChildElem( _T("NAME") );
  584. strList += xml.GetChildData();
  585. strList += _T("n");
  586. #ifndef MARKUP_MSXML
  587. xml.SavePos();
  588. #endif
  589. xml.OutOfElem();
  590. }
  591. #if ! defined( MARKUP_MSXML )
  592. xml.RestorePos();
  593. Check( xml.GetChildData() == _T("onions") );
  594. #endif
  595. Check( strList == _T("carrotsnonionsn") );
  596. // December Test, add and remove five elements repeatedly
  597. StartCheckZone( _T("December Test") );
  598. struct TestData { _TCHAR* szName; _TCHAR* szValue; } td[] =
  599. {
  600. _T("patridge"), _T("PEARTREE"),
  601. _T("2turtle"), _T("DOVES"),
  602. _T("3french"), _T("HENS"),
  603. _T("4calling"), _T("BIRDS"),
  604. _T("5golden"), _T("RINGS"),
  605. };
  606. int nTD;
  607. xml.SetDoc( _T("") );
  608. Check( xml.AddElem( _T("RESULT") ) );
  609. for ( nTD=0; nTD<=4; ++nTD )
  610. {
  611. xml.AddChildElem( _T("VAR"), td[nTD].szValue );
  612. xml.SetChildAttrib( _T("name"), td[nTD].szName );
  613. }
  614. for ( nTD=0; nTD<=4; ++nTD )
  615. {
  616. xml.ResetPos();
  617. while ( xml.FindChildElem( _T("VAR") ) )
  618. if ( xml.GetChildAttrib( _T("name") ) == td[nTD].szName )
  619. {
  620. xml.RemoveChildElem();
  621. break;
  622. }
  623. xml.AddChildElem( _T("VAR"), td[nTD].szValue );
  624. xml.SetChildAttrib( _T("name"), td[nTD].szName );
  625. }
  626. for ( nTD=4; nTD>=0; --nTD )
  627. {
  628. xml.ResetPos();
  629. while ( xml.FindChildElem( _T("VAR") ) )
  630. if ( xml.GetChildAttrib( _T("name") ) == td[nTD].szName )
  631. {
  632. xml.RemoveChildElem();
  633. break;
  634. }
  635. xml.ResetChildPos();
  636. xml.AddChildElem( _T("VAR"), td[nTD].szValue );
  637. xml.SetChildAttrib( _T("name"), td[nTD].szName );
  638. }
  639. // <RESULT>
  640. // <VAR name="5golden">RINGS</VAR>
  641. // <VAR name="4calling">BIRDS</VAR>
  642. // <VAR name="3french">HENS</VAR>
  643. // <VAR name="2turtle">DOVES</VAR>
  644. // <VAR name="patridge">PEARTREE</VAR>
  645. // </RESULT>
  646. xml.ResetPos();
  647. for ( nTD=4; nTD>=0; --nTD )
  648. {
  649. Check( xml.FindChildElem() );
  650. Check( xml.GetChildData() == td[nTD].szValue );
  651. Check( xml.GetChildAttrib( _T("name") ) == td[nTD].szName );
  652. }
  653. // Add Insert Test, test siblings created in correct sequence
  654. _TCHAR* aszNums[] = { _T("zero"),_T("one"),_T("two"),_T("three"),_T("four"),_T("five"),_T("six") };
  655. MCD_STR strInside = _T("_in6");
  656. StartCheckZone( _T("Insert Test") );
  657. xml.SetDoc( _T("") );
  658. xml.AddElem( _T("root") );
  659. xml.AddChildElem( aszNums[1] );
  660. xml.ResetChildPos();
  661. xml.AddChildElem( aszNums[3] );
  662. xml.ResetChildPos();
  663. xml.FindChildElem();
  664. xml.InsertChildElem( aszNums[0] );
  665. xml.RemoveChildElem();
  666. xml.InsertChildElem( aszNums[0] );
  667. xml.FindChildElem();
  668. xml.AddChildElem( aszNums[2] );
  669. xml.FindChildElem();
  670. xml.AddChildElem( aszNums[4] );
  671. xml.FindChildElem();
  672. xml.AddChildElem( aszNums[5] );
  673. xml.ResetChildPos();
  674. xml.IntoElem();
  675. xml.FindElem();
  676. xml.RemoveElem();
  677. xml.InsertElem( aszNums[0] );
  678. xml.ResetMainPos();
  679. xml.AddElem( aszNums[6] );
  680. xml.IntoElem();
  681. xml.AddElem( aszNums[1] + strInside );
  682. xml.ResetMainPos();
  683. xml.AddElem( aszNums[3] + strInside );
  684. xml.ResetMainPos();
  685. xml.FindElem();
  686. xml.InsertElem( aszNums[0] + strInside );
  687. xml.RemoveElem();
  688. xml.ResetMainPos();
  689. xml.InsertElem( aszNums[0] + strInside );
  690. xml.FindElem();
  691. xml.AddElem( aszNums[2] + strInside );
  692. xml.FindElem();
  693. xml.AddElem( aszNums[4] + strInside );
  694. xml.FindElem();
  695. xml.AddElem( aszNums[5] + strInside );
  696. // Should result in the following (indented to illustrate):
  697. // <root>
  698. //   <zero/>
  699. //   <one/>
  700. //   <two/>
  701. //   <three/>
  702. //   <four/>
  703. //   <five/>
  704. //   <six>
  705. //     <zero_in6/>
  706. //     <one_in6/>
  707. //     <two_in6/>
  708. //     <three_in6/>
  709. //     <four_in6/>
  710. //     <five_in6/>
  711. //   </six>
  712. // </root>
  713. xml.ResetPos();
  714. for ( int nIT=0; nIT<7; ++nIT )
  715. {
  716. Check( xml.FindChildElem() );
  717. Check( xml.IntoElem() );
  718. Check( xml.GetTagName() == aszNums[nIT] );
  719. if ( nIT == 6 )
  720. {
  721. for ( int nITinner=0; nITinner<6; ++nITinner )
  722. {
  723. Check( xml.FindChildElem() );
  724. Check( xml.GetChildTagName() == aszNums[nITinner]+strInside );
  725. }
  726. }
  727. Check( xml.OutOfElem() );
  728. }
  729. // Palmer Test
  730. StartCheckZone( _T("Palmer Test") );
  731. xml.SetDoc( _T("") );
  732. Check( xml.AddElem( _T("one") ) );
  733. Check( xml.AddChildElem( _T("two") ) );
  734. Check( xml.RemoveChildElem() );
  735. Check( xml.AddChildElem( _T("three") ) );
  736. // <one>
  737. // <three/>
  738. // </one>
  739. xml.ResetPos();
  740. Check( xml.FindChildElem() );
  741. Check( xml.GetChildTagName() == _T("three") );
  742. // SetData Test, check empty elements, normal, and CDATA
  743. StartCheckZone( _T("SetData Test") );
  744. Check( xml.SetDoc( _T("<?xml version="1.0"?>rn<ROOT>data</ROOT>") ) );
  745. Check( xml.FindElem() );
  746. xml.SetData( _T("moredata<>&") );
  747. Check( xml.GetData() == _T("moredata<>&") );
  748. xml.SetData( _T("n<6"), 1 );
  749. Check( xml.GetData() == _T("n<6") );
  750. xml.SetData( _T("") );
  751. xml.AddChildElem( _T("CHILD") );
  752. xml.SetChildData( _T("data<>&") );
  753. Check( xml.GetChildData() == _T("data<>&") );
  754. xml.SetChildData( _T("n<6"), 1 );
  755. xml.InsertChildElem( _T("CHILD") );
  756. xml.IntoElem();
  757. Check( xml.SetData(_T("")) );
  758. xml.SetData( _T("final") );
  759. Check( xml.GetData() == _T("final") );
  760. xml.FindElem();
  761. Check( xml.GetData() == _T("n<6") );
  762. // Car Test, add and replace randomly chosen attributes
  763. StartCheckZone( _T("Random Car Part Test") );
  764. struct CarTestData { _TCHAR* szLow; _TCHAR* szUp; _TCHAR* szMix; } aCT[] =
  765. {
  766. _T("up"), _T("SKY"), _T("Light"),
  767. _T("down"), _T("FLOOR"), _T("Dust"),
  768. _T("left"), _T("DOOR"), _T("Handle"),
  769. _T("right"), _T("SEAT"), _T("Gear"),
  770. _T("back"), _T("TRUNK"), _T("Tread"),
  771. _T("forward"), _T("GRILL"), _T("Motor"),
  772. _T(""), _T(""), _T("")
  773. };
  774. xml.SetDoc( _T("") );
  775. xml.AddElem( _T("CAR") );
  776. int nAt, nPart;
  777. LPCTSTR szLow, szUp, szMix;
  778. for ( nAt = 0; nAt < 20; ++nAt )
  779. {
  780. szLow = aCT[RandInt(6)].szLow;
  781. szMix = aCT[RandInt(6)].szMix;
  782. xml.SetAttrib( szLow, szMix );
  783. Check( xml.GetAttrib(szLow) == szMix );
  784. }
  785. for ( nPart=0; nPart<100; ++nPart )
  786. {
  787. xml.AddChildElem( aCT[RandInt(6)].szUp );
  788. for ( nAt = 0; nAt < 8; ++nAt )
  789. {
  790. szLow = aCT[RandInt(6)].szLow;
  791. szMix = aCT[RandInt(6)].szMix;
  792. xml.SetChildAttrib( szLow, szMix );
  793. Check( xml.GetChildAttrib(szLow) == szMix );
  794. }
  795. szLow = aCT[RandInt(6)].szLow;
  796. szUp = aCT[RandInt(6)].szUp;
  797. xml.SetChildAttrib( szLow, szUp );
  798. Check( xml.GetChildAttrib(szLow) == szUp );
  799. }
  800. MCD_STR strCarDoc = xml.GetDoc();
  801. Check( xml.SetDoc( strCarDoc ) );
  802. // Car Attrib Speed Test
  803. StartCheckZone( _T("Car Attrib Speed Test") );
  804. xml.SetDoc( NULL );
  805. xml.AddElem( _T("CARSPEED") );
  806. TimeStart();
  807. for ( nPart=0; nPart<200; ++nPart )
  808. {
  809. xml.AddChildElem( aCT[RandInt(6)].szUp );
  810. for ( nAt = 0; nAt < 4; ++nAt )
  811. {
  812. szLow = aCT[RandInt(6)].szLow;
  813. szMix = aCT[RandInt(6)].szMix;
  814. xml.SetChildAttrib( szLow, szMix );
  815. szLow = aCT[RandInt(6)].szLow;
  816. szUp = aCT[RandInt(6)].szUp;
  817. xml.SetChildAttrib( szLow, szUp );
  818. }
  819. }
  820. int nAttribCreateTime = TimeStop();
  821. xml.ResetPos();
  822. TimeStart();
  823. MCD_STR strAttribName, strAttribs;
  824. while ( xml.FindChildElem() )
  825. {
  826. xml.IntoElem();
  827. nAt = 0;
  828. MCD_STRCLEAR(strAttribs);
  829. strAttribName = xml.GetAttribName( nAt );
  830. while ( ! MCD_STRISEMPTY(strAttribName) )
  831. {
  832. strAttribs += xml.GetAttrib( strAttribName );
  833. ++nAt;
  834. strAttribName = xml.GetAttribName( nAt );
  835. }
  836. xml.OutOfElem();
  837. }
  838. int nAttribNavTime = TimeStop();
  839. if ( nAttribCreateTime > 400 || nAttribNavTime > 400 )
  840. {
  841. CString strAttribTime;
  842. strAttribTime.Format( _T("Attribute Performance Results: create %d search %drn"), nAttribCreateTime, nAttribNavTime );
  843. m_csChecks += strAttribTime;
  844. }
  845. // SubDoc Test, use subdocument methods
  846. StartCheckZone( _T("SubDoc Test") );
  847. MCD_STR strTestAttrib = _T("<<&"symb>>");
  848. MCD_STR strSubDoc, strChildSubDoc;
  849. xml.SetDoc( _T("") );
  850. Check( xml.AddElem(_T("ORDER")) );
  851. xml.AddChildElem( _T("ITEM") );
  852. xml.IntoElem();
  853. Check( xml.AddChildSubDoc(_T("<?xml version="1.0"?>rn<ITEM/>rn")) );
  854. Check( xml.AddChildAttrib(_T("test"), strTestAttrib) );
  855. Check( xml.IntoElem() );
  856. Check( xml.AddChildElem(_T("NAME"), _T("carrots")) );
  857. Check( xml.AddChildElem(_T("QTY"), _T("1")) );
  858. strSubDoc = xml.GetSubDoc();
  859. Check( xml.OutOfElem() );
  860. strChildSubDoc = xml.GetChildSubDoc();
  861. Check( strSubDoc == strChildSubDoc );
  862. // Set xml2 from xml subdocument and modify
  863. Check( xml2.SetDoc(xml.GetChildSubDoc()) );
  864. Check( xml2.FindElem() );
  865. Check( xml2.SetAttrib(_T("subtest"), strTestAttrib) );
  866. Check( xml2.SetAttrib(_T("test"), _T("")) );
  867. Check( xml2.FindChildElem(_T("QTY")) );
  868. Check( xml2.RemoveChildElem() );
  869. strSubDoc = xml2.GetDoc();
  870. #if ! defined( MARKUP_MSXML )
  871. // MSXML: Invalid subdocument causes first-chance exception
  872. // It works, but this #ifdef avoids alarming us with the Debug output
  873. Check( ! xml.AddChildSubDoc(_T("invalidsub<doc>")) );
  874. #endif
  875. Check( xml.AddChildSubDoc(strSubDoc) );
  876. Check( xml.IntoElem() );
  877. Check( xml.RemoveElem() );
  878. Check( xml.AddSubDoc(strSubDoc) );
  879. Check( xml.GetAttrib(_T("subtest")) == strTestAttrib );
  880. Check( xml.OutOfElem() );
  881. Check( xml.InsertChildSubDoc(strSubDoc) );
  882. xml.ResetChildPos();
  883. Check( xml.InsertChildSubDoc(strSubDoc) );
  884. xml.IntoElem();
  885. xml.FindChildElem();
  886. Check( xml.GetChildData() == _T("carrots") );
  887. // Brannan Test: subdocument with no children getting flagged as empty in 7.0
  888. xml.ResetChildPos();
  889. xml.FindElem();
  890. xml.FindChildElem( _T("QTY") );
  891. xml.AddChildSubDoc( xml.GetChildSubDoc() );
  892. Check( xml.GetChildData() == _T("1") );
  893. // Comments Test, make sure it bypasses declaration, DTD, and comments
  894. StartCheckZone( _T("Comments Test") );
  895. CString csPTDoc =
  896. _T("<?xml version="1.0"?>n")
  897. _T("<!DOCTYPE PARSETEST [n")
  898. _T("<!ELEMENT PARSETEST (ITEM*)>n")
  899. _T("<!ATTLIST PARSETEST v CDATA "" s CDATA "">n")
  900. _T("<!ELEMENT ITEM ANY>n")
  901. _T("<!ATTLIST ITEM note CDATA "">n")
  902. _T("]>n")
  903. _T("<PARSETEST v="1" s='6'>n")
  904. _T("<!--- </P>& special chars -->n")
  905. _T("<ITEM note="Here&apos;s to &quot;us&quot;"/>n")
  906. _T("<ITEM note="see data">Here's to "us"</ITEM>n")
  907. _T("</PARSETEST>n")
  908. ;
  909. Check( xml.SetDoc( csPTDoc ) );
  910. Check( xml.FindChildElem() );
  911. Check( xml.GetAttrib( _T("v") ) == _T("1") );
  912. Check( xml.GetAttribName(0) == _T("v") );
  913. Check( xml.GetAttribName(1) == _T("s") );
  914. Check( xml.GetAttribName(2) == _T("") );
  915. Check( xml.GetChildAttrib(_T("note")) == _T("Here's to "us"") );
  916. Check( xml.IntoElem() );
  917. Check( xml.FindElem() );
  918. Check( xml.GetData() == _T("Here's to "us"") );
  919. #if ! defined( MARKUP_MSXML )
  920. // Save Restore Position Test
  921. StartCheckZone( _T("Save Restore Position Test") );
  922. xml.SetDoc( NULL );
  923. xml.AddElem( _T("SavePosTest") );
  924. Check( ! xml.RestorePos() ); // crash in 6.6 and 7.x when no saved pos yet
  925. Check( xml.SavePos(_T("xD7")) ); // crash in 7.0 to 8.2 with non-ASCII
  926. xml.IntoElem(); // no main position
  927. xml.SavePos();
  928. xml.ResetPos();
  929. xml.RestorePos();
  930. Check( xml.OutOfElem() );
  931. Check( xml.GetTagName() == _T("SavePosTest") );
  932. CStringArray csaPosNames;
  933. int nSavePos;
  934. const int nSavePosTestSize = 100;
  935. for ( nSavePos=0; nSavePos<nSavePosTestSize; ++nSavePos )
  936. {
  937. // Find an unused random name
  938. MCD_STR strPosName;
  939. while ( 1 )
  940. {
  941. int nPosNameLen = RandInt(10)+1;
  942. for ( int nPosNameChar=0; nPosNameChar<nPosNameLen; ++nPosNameChar )
  943. strPosName += (_TCHAR)(_T('A')+RandInt(26));
  944. if ( ! xml.RestorePos(strPosName) )
  945. break;
  946. }
  947. xml.AddChildElem( strPosName );
  948. xml.SavePos( strPosName );
  949. csaPosNames.Add( MCD_2PCSZ(strPosName) );
  950. }
  951. xml2 = xml;
  952. xml = xml2;
  953. for ( nSavePos=0; nSavePos<csaPosNames.GetSize(); ++nSavePos )
  954. {
  955. Check( xml.RestorePos((LPCTSTR)csaPosNames[nSavePos]) );
  956. Check( xml.GetChildTagName() == (LPCTSTR)csaPosNames[nSavePos] );
  957. // Move saved position to TEMP2 child
  958. Check( xml.IntoElem() );
  959. Check( xml.AddChildElem( _T("TEMP") ) );
  960. Check( xml.IntoElem() );
  961. Check( xml.AddChildElem( _T("TEMP2") ) );
  962. Check( xml.IntoElem() );
  963. xml.SavePos( (LPCTSTR)csaPosNames[nSavePos] );
  964. if ( RandInt(2) ) // 1 in 2
  965. Check( xml.OutOfElem() );
  966. if ( RandInt(2) ) // 1 in 2
  967. Check( xml.OutOfElem() );
  968. if ( nSavePos % 2 )
  969. xml.RemoveElem();
  970. }
  971. for ( nSavePos=0; nSavePos<csaPosNames.GetSize(); ++nSavePos )
  972. {
  973. if ( nSavePos % 2 )
  974. Check( ! xml.RestorePos((LPCTSTR)csaPosNames[nSavePos]) );
  975. else
  976. {
  977. Check( xml.RestorePos((LPCTSTR)csaPosNames[nSavePos]) );
  978. Check( xml.OutOfElem() );
  979. Check( xml.OutOfElem() );
  980. Check( xml.GetTagName() == (LPCTSTR)csaPosNames[nSavePos] );
  981. }
  982. }
  983. // Save Restore Example
  984. int anSomeData[] = { 10, 30, 50, 20, 90, 0 };
  985. int nD;
  986. StartCheckZone( _T("Save Restore Example") );
  987. xml.SetDoc( NULL );
  988. xml.AddElem( _T("SavePosExample") );
  989. xml.IntoElem(); // no main position
  990. xml.AddElem( _T("Total") );
  991. xml.SavePos( _T("Total") );
  992. xml.AddElem( _T("Data") );
  993. xml.SavePos( _T("Data") );
  994. for ( nD=0; anSomeData[nD]; ++nD )
  995. {
  996. xml.RestorePos( _T("Total") );
  997. xml.SetData( _ttoi(MCD_2PCSZ(xml.GetData())) + anSomeData[nD] );
  998. xml.RestorePos( _T("Data") );
  999. xml.AddChildElem( _T("Value"), anSomeData[nD] );
  1000. }
  1001. xml2.SetDoc( NULL );
  1002. xml2.AddElem( _T("SavePosExample") );
  1003. xml2.IntoElem();
  1004. xml2.AddElem( _T("Total") );
  1005. xml2.AddElem( _T("Data") );
  1006. for ( nD=0; anSomeData[nD]; ++nD )
  1007. {
  1008. xml2.ResetMainPos();
  1009. xml2.FindElem();
  1010. xml2.SetData( _ttoi(MCD_2PCSZ(xml2.GetData())) + anSomeData[nD] );
  1011. xml2.FindElem();
  1012. xml2.AddChildElem( _T("Value"), anSomeData[nD] );
  1013. }
  1014. Check( xml.GetDoc() == xml2.GetDoc() );
  1015. // Prepend XML Declaration test
  1016. // (not implemented in MSXML because modifying XML Declaration is restricted)
  1017. StartCheckZone( _T("Prepend XML Declaration") );
  1018. Check( ! xml.SetDoc( _T("<?xml version="1.0"?>rn") ) );
  1019. Check( xml.AddElem( _T("ROOT") ) );
  1020. Check( xml.IntoElem() );
  1021. Check( xml.AddElem( _T("CHILD") ) );
  1022. xml.ResetPos();
  1023. Check( xml.FindElem( _T("ROOT") ) );
  1024. Check( xml.FindChildElem( _T("CHILD") ) );
  1025. // Copy Constructor Test (not MSXML!)
  1026. StartCheckZone( _T("Copy Constructor Test non-MSXML") );
  1027. xml.SetDoc( NULL );
  1028. xml2 = xml;
  1029. xml.AddElem( _T("R") );
  1030. xml.AddChildElem( _T("C") );
  1031. xml2 = xml;
  1032. xml2.FindChildElem();
  1033. Check( xml2.GetChildTagName() == xml.GetChildTagName() );
  1034. xml.IntoElem();
  1035. xml.SavePos();
  1036. xml.RemoveElem();
  1037. xml2 = xml;
  1038. Check( ! xml2.RestorePos() );
  1039. // Ill-formed Markup Test
  1040. StartCheckZone( _T("Ill-formed Markup Test") );
  1041. Check( ! xml.SetDoc( _T("<P>Hello<BR>Hi") ) );
  1042. Check( xml.FindElem( _T("P") ) );
  1043. Check( xml.FindNode() == xml.MNT_TEXT );
  1044. Check( xml.GetData() == _T("Hello") );
  1045. Check( xml.FindElem( _T("BR") ) );
  1046. Check( xml.FindNode() == xml.MNT_TEXT );
  1047. Check( xml.GetData() == _T("Hi") );
  1048. Check( xml.AddElem( _T("P"), _T("Hola") ) );
  1049. Check( xml.GetData() == _T("Hola") );
  1050. Check( ! xml.SetDoc( _T("<P>Hello<BR>Hi</P>") ) );
  1051. Check( xml.FindElem( _T("P") ) );
  1052. xml.SetDocFlags( xml.MDF_IGNORECASE );
  1053. Check( xml.SetDoc( _T("<A></a>") ) );
  1054. Check( xml.FindElem( _T("a") ) );
  1055. Check( xml.SetAttrib( _T("a1"), _T("V1") ) );
  1056. Check( xml.SetAttrib( _T("A1"), _T("v1") ) );
  1057. Check( ! xml.AddSubDoc( _T("<b>") ) );
  1058. xml.ResetPos();
  1059. Check( xml.FindElem( _T("a") ) );
  1060. Check( xml.GetAttrib(_T("A1")) == _T("v1") );
  1061. Check( xml.GetAttrib(_T("a1")) == _T("v1") );
  1062. Check( xml.FindElem( _T("B") ) );
  1063. xml.SetDocFlags( 0 );
  1064. Check( ! xml.SetDoc( _T("<A><B></C></B></A>") ) );
  1065. Check( xml.FindElem() );
  1066. Check( xml.IntoElem() );
  1067. Check( xml.FindElem( _T("B") ) );
  1068. Check( xml.IntoElem() );
  1069. Check( xml.FindNode() == xml.MNT_LONE_END_TAG );
  1070. Check( xml.GetTagName() == _T("C") );
  1071. Check( xml.GetData() == _T("C") );
  1072. Check( xml.OutOfElem() );
  1073. Check( xml.SetElemContent( _T("data") ) );
  1074. Check( ! xml.InsertSubDoc( _T("<S/><S/>") ) );
  1075. Check( ! xml.SetElemContent( _T("<SC>") ) );
  1076. Check( xml.FindElem( _T("S") ) );
  1077. // Multi-Rooted Subdoc Test
  1078. StartCheckZone( _T("Multi-Rooted Subdoc Test") );
  1079. Check( xml.SetElemContent( _T("<SC><SCC/></SC><SC><SCC/></SC><SC/>") ) );
  1080. Check( xml.FindChildElem( _T("SC") ) );
  1081. Check( xml.SetChildAttrib( _T("asc"), _T("verbose") ) );
  1082. Check( xml.IntoElem() );
  1083. Check( xml.FindChildElem( _T("SCC") ) );
  1084. Check( xml.SetChildAttrib( _T("ascc"), _T("verbose") ) );
  1085. Check( xml.OutOfElem() );
  1086. xml.ResetMainPos();
  1087. Check( xml.FindElem( _T("S") ) );
  1088. Check( xml.FindChildElem( _T("SC") ) );
  1089. Check( xml.SetChildAttrib( _T("asc"), _T("verbose") ) );
  1090. Check( xml.SetChildAttrib( _T("asc2"), 2 ) );
  1091. Check( xml.FindElem( _T("S") ) );
  1092. Check( xml.FindChildElem( _T("SC") ) );
  1093. Check( xml.FindChildElem( _T("SC") ) );
  1094. Check( xml.FindElem( _T("B") ) );
  1095. // Don't mistake end slash on non-quoted value for empty element (see cDminus2)
  1096. StartCheckZone( _T("Non Quoted Attribute Test") );
  1097. Check( xml.SetDoc( _T("<A href=/path/>ok</A>") ) );
  1098. Check( xml.FindElem() );
  1099. Check( xml.GetAttrib(_T("href")) == _T("/path/") );
  1100. // AddElem Flags Test
  1101. StartCheckZone( _T("AddElem Flags Test") );
  1102. xml.SetDoc( NULL );
  1103. xml.AddElem( _T("ROOT"), NULL, xml.MNF_WITHNOLINES );
  1104. xml.AddChildElem( _T("A"), _T(""), xml.MNF_WITHNOEND|xml.MNF_WITHNOLINES );
  1105. Check( xml.IntoElem() );
  1106. Check( xml.AddElem( _T("A"), _T(""), xml.MNF_WITHNOEND ) );
  1107. Check( xml.AddChildElem( _T("B") ) );
  1108. Check( xml.AddChildElem( _T("B"), _T("D") ) );
  1109. Check( xml.OutOfElem() );
  1110. xml.AddChildElem( _T("BR"), _T(""), xml.MNF_WITHXHTMLSPACE );
  1111. xml.SetChildAttrib( _T("class"), _T("MinorBrk") );
  1112. Check( ! xml.SetDoc( _T("<A>test") ) );
  1113. Check( xml.FindElem() );
  1114. Check( xml.FindNode() == xml.MNT_TEXT );
  1115. Check( xml.GetData() == _T("test") );
  1116. Check( ! xml.SetDoc( _T("<A>testrn") ) );
  1117. Check( xml.FindElem() );
  1118. Check( xml.FindNode() == xml.MNT_TEXT );
  1119. Check( TruncToLastEOL(MCD_2PCSZ(xml.GetData())) == _T("test") );
  1120. Check( ! xml.SetDoc( _T("<A>testrn  <B>okay") ) );
  1121. Check( xml.FindElem() );
  1122. Check( xml.FindNode() == xml.MNT_TEXT );
  1123. Check( TruncToLastEOL(MCD_2PCSZ(xml.GetData())) == _T("test") );
  1124. Check( xml.FindElem() );
  1125. Check( xml.FindNode() == xml.MNT_TEXT );
  1126. Check( TruncToLastEOL(MCD_2PCSZ(xml.GetData())) == _T("okay") );
  1127. xml.ResetMainPos();
  1128. Check( xml.FindElem() );
  1129. Check( xml.SetData(_T("t2")) );
  1130. Check( xml.GetData() == _T("t2") );
  1131. Check( xml.SetData(_T("test3")) );
  1132. Check( xml.GetData() == _T("test3") );
  1133. xml.SetDoc( NULL );
  1134. xml.AddElem( _T("P"), _T(""), xml.MNF_WITHNOLINES );
  1135. xml.IntoElem();
  1136. Check( xml.AddNode( xml.MNT_TEXT, _T("First line") ) );
  1137. Check( xml.AddElem( _T("BR"), _T(""), xml.MNF_WITHNOEND | xml.MNF_WITHNOLINES ) );
  1138. Check( xml.AddNode( xml.MNT_TEXT, _T("Second line") ) );
  1139. Check( xml.GetDoc() == _T("<P>First line<BR>Second line</P>") );
  1140. xml.OutOfElem();
  1141. xml.SetElemContent( _T("First line<BR>Second line") );
  1142. Check( xml.GetDoc() == _T("<P>First line<BR>Second line</P>") );
  1143. // Ill-formed SubDoc Fragment Test
  1144. StartCheckZone( _T("SubDoc Fragment Test") );
  1145. Check( ! xml.SetDoc( _T("<A/><B/>") ) );
  1146. Check( ! xml.SetDoc( _T(" something ") ) );
  1147. Check( ! xml.AddSubDoc( _T("<A>") ) );
  1148. Check( ! xml.AddSubDoc( _T("<B>") ) );
  1149. Check( ! xml.AddSubDoc( _T("</A>") ) ); // lone end tag
  1150. Check( xml.AddSubDoc( _T("<C/>") ) );
  1151. Check( ! xml.SetElemContent( _T("<CC>") ) );
  1152. Check( xml.GetTagName() == _T("C") );
  1153. Check( xml.FindChildElem() );
  1154. Check( xml.GetChildTagName() == _T("CC") );
  1155. Check( xml.SetElemContent( _T("d") ) );
  1156. Check( xml.GetData() == _T("d") );
  1157. Check( ! xml.SetElemContent( _T("<DD>") ) );
  1158. Check( xml.FindChildElem() );
  1159. Check( xml.GetChildTagName() == _T("DD") );
  1160. // Replace element between two text nodes
  1161. StartCheckZone( _T("Replace Element Test") );
  1162. Check( xml.SetDoc( _T("T<A/>T") ) );
  1163. Check( xml.FindElem( _T("A") ) );
  1164. Check( xml.RemoveNode() );
  1165. Check( xml.GetNodeType() == xml.MNT_TEXT );
  1166. Check( xml.GetData() == _T("T") );
  1167. Check( xml.AddNode( xml.MNT_ELEMENT, _T("B") ) );
  1168. Check( xml.SetAttrib( _T("v"), 1 ) );
  1169. Check( xml.GetTagName() == _T("B") );
  1170. Check( xml.GetAttrib( _T("v") ) == _T("1") );
  1171. Check( xml.IntoElem() );
  1172. Check( xml.AddNode( xml.MNT_TEXT, _T("T0") ) );
  1173. Check( xml.AddNode( xml.MNT_ELEMENT, _T("C1") ) );
  1174. Check( xml.AddNode( xml.MNT_TEXT, _T("T1") ) );
  1175. Check( xml.AddNode( xml.MNT_ELEMENT, _T("C2") ) );
  1176. Check( xml.AddNode( xml.MNT_TEXT, _T("T2") ) );
  1177. xml.ResetMainPos();
  1178. Check( xml.FindElem( _T("C1") ) );
  1179. Check( xml.RemoveNode() );
  1180. Check( xml.GetNodeType() == xml.MNT_TEXT );
  1181. Check( xml.GetData() == _T("T0") );
  1182. Check( xml.AddNode( xml.MNT_ELEMENT, _T("C1") ) );
  1183. Check( xml.FindElem( _T("C2") ) );
  1184. Check( xml.RemoveNode() );
  1185. Check( xml.GetNodeType() == xml.MNT_TEXT );
  1186. Check( xml.GetData() == _T("T1") );
  1187. Check( xml.AddNode( xml.MNT_ELEMENT, _T("C2") ) );
  1188. Check( xml.FindNode() == xml.MNT_TEXT );
  1189. Check( xml.GetData() == _T("T2") );
  1190. xml.ResetMainPos();
  1191. Check( xml.FindElem( _T("C2") ) );
  1192. Check( xml.IntoElem() );
  1193. Check( xml.AddNode( xml.MNT_ELEMENT, _T("D3") ) );
  1194. Check( xml.AddNode( xml.MNT_TEXT, _T("T0") ) );
  1195. Check( xml.AddNode( xml.MNT_ELEMENT, _T("D4") ) );
  1196. Check( xml.IntoElem() );
  1197. Check( xml.AddNode( xml.MNT_ELEMENT, _T("E1") ) );
  1198. Check( xml.SetData( _T("X") ) );
  1199. Check( xml.OutOfElem() );
  1200. Check( xml.OutOfElem() );
  1201. xml.ResetMainPos();
  1202. Check( xml.FindElem() );
  1203. Check( xml.GetTagName() == _T("C1") );
  1204. Check( xml.IntoElem() );
  1205. Check( xml.AddNode( xml.MNT_TEXT, _T("T1") ) );
  1206. Check( xml.AddNode( xml.MNT_ELEMENT, _T("D2") ) );
  1207. Check( xml.AddNode( xml.MNT_TEXT, _T("T2") ) );
  1208. xml.ResetMainPos();
  1209. Check( xml.FindElem() );
  1210. Check( xml.GetTagName() == _T("D2") );
  1211. xml.ResetMainPos();
  1212. Check( xml.InsertNode( xml.MNT_ELEMENT, _T("D1") ) );
  1213. Check( xml.InsertNode( xml.MNT_TEXT, _T("TEST") ) );
  1214. Check( xml.SetData( _T("T0") ) );
  1215. Check( xml.FindNode() == xml.MNT_ELEMENT );
  1216. Check( xml.SetData( _T("X") ) );
  1217. Check( xml.FindElem( _T("D2") ) );
  1218. xml.ResetMainPos();
  1219. Check( xml.FindNode() == xml.MNT_TEXT );
  1220. Check( xml.GetData() == _T("T0") );
  1221. Check( xml.OutOfElem() );
  1222. xml.ResetMainPos();
  1223. Check( xml.FindElem( _T("C2") ) );
  1224. Check( xml.IntoElem() );
  1225. Check( xml.FindNode() == xml.MNT_ELEMENT );
  1226. Check( xml.GetTagName() == _T("D3") );
  1227. Check( xml.FindNode() == xml.MNT_TEXT );
  1228. Check( xml.GetData() == _T("T0") );
  1229. Check( xml.FindNode() == xml.MNT_ELEMENT );
  1230. Check( xml.GetTagName() == _T("D4") );
  1231. Check( xml.FindChildElem() );
  1232. Check( xml.GetChildData() == _T("X") );
  1233. // With Entities Test
  1234. StartCheckZone( _T("With Entities Test") );
  1235. xml.SetDoc(NULL);
  1236. Check( xml.AddElem( _T("A"), _T("&#x20;"), xml.MNF_WITHREFS ) );
  1237. Check( xml.GetData() == _T(" ") );
  1238. Check( xml.AddChildElem( _T("CH"), _T("&amp;"), xml.MNF_WITHREFS ) );
  1239. Check( xml.GetChildData() == _T("&") );
  1240. Check( xml.SetChildData( _T("&#32;"), xml.MNF_WITHREFS ) );
  1241. Check( xml.GetChildData() == _T(" ") );
  1242. Check( xml.SetChildData( _T("&"), xml.MNF_WITHREFS ) );
  1243. Check( xml.GetChildData() == _T("&") );
  1244. Check( xml.SetChildData( _T("&&"), xml.MNF_WITHREFS ) );
  1245. Check( xml.GetChildData() == _T("&&") );
  1246. Check( xml.SetChildData( _T("&#3 2"), xml.MNF_WITHREFS ) );
  1247. Check( xml.GetChildData() == _T("&#3 2") );
  1248. Check( xml.EscapeText( _T("&#3 2"), xml.MNF_WITHREFS ) == _T("&amp;#3 2") );
  1249. Check( xml.EscapeText( _T("""), xml.MNF_ESCAPEQUOTES ) == _T("&quot;") );
  1250. Check( xml.EscapeText( _T(""") ) == _T(""") );
  1251. Check( xml.EscapeText( _T("&#32;'"), xml.MNF_WITHREFS|xml.MNF_ESCAPEQUOTES ) == _T("&#32;&apos;") );
  1252. // Node Error Test -- even gibberish will not stop node navigation
  1253. // But there is no guaranteed node parsing system with gibberish
  1254. StartCheckZone( _T("Node Error Test") );
  1255. Check( ! xml.SetDoc( _T("<) <> <*  ><<>>") ) );
  1256. BOOL bReachedEndOfGibberish = FALSE;
  1257. int nGibberishNodes = 0;
  1258. while ( nGibberishNodes < 100 )
  1259. {
  1260. int nGNType = xml.FindNode();
  1261. if ( nGNType == 0 )
  1262. {
  1263. bReachedEndOfGibberish = TRUE;
  1264. break;
  1265. }
  1266. else if ( nGNType == xml.MNT_NODE_ERROR )
  1267. {
  1268. MCD_STR strJunkNode = xml.GetData();
  1269. Check( ! MCD_STRISEMPTY(strJunkNode) );
  1270. }
  1271. ++nGibberishNodes;
  1272. }
  1273. Check( bReachedEndOfGibberish );
  1274. #endif
  1275. // Character Reference Test, check various character decoding issues
  1276. StartCheckZone( _T("Character Reference Test") );
  1277. Check( xml.SetDoc(
  1278. _T("<?xml version="1.0" encoding="UTF-8"?>n")
  1279. _T("<CHAR v='C&#34;&#x22;S'>n")
  1280. _T("<CORE>&#60;&#x3c;&#62;&#x3e;&#38;&#x26;&#39;&#x27;&#34;&#x22;</CORE>n")
  1281. _T("<SPACE xml:space="preserve">&#32;&#x20;&#9;&#x9;&#10;&#xa;</SPACE>n")
  1282. _T("<REF>&#20013;&#22269;&#20154;</REF>n")
  1283. _T("</CHAR>n")
  1284. ) );
  1285. Check( xml.FindChildElem(_T("CORE")) );
  1286. Check( xml.GetAttrib( _T("v") ) == _T("C""S") );
  1287. Check( xml.GetChildData() == _T("<<>>&&''""") );
  1288. Check( xml.FindChildElem(_T("SPACE")) );
  1289. Check( xml.GetChildData() == _T("  ttnn") );
  1290. Check( xml.FindChildElem(_T("REF")) );
  1291. #if defined( _UNICODE )
  1292. Check( xml.GetChildData() == _T("x4E2Dx56FDx4EBA") );
  1293. #elif ! defined( MARKUP_MSXML )
  1294. #if defined( _MBCS )
  1295. setlocale( LC_ALL, "C" );
  1296. if ( setlocale(LC_CTYPE,".936") ) // is GB2312 DBCS code page available?
  1297. Check( xml.GetChildData() == _T("xD6xD0xB9xFAxC8xCB") ); // DBCS
  1298. else
  1299. Check( xml.GetChildData() == _T("&#20013;&#22269;&#20154;") ); // unmodified
  1300. #else
  1301. // UTF-8 (note: MSXML converts chinese character reference to UCS-2, but not UTF-8)
  1302. Check( xml.GetChildData() == _T("xE4xB8xADxE5x9BxBDxE4xBAxBA") );
  1303. #endif
  1304. #endif
  1305. #if defined( _MBCS )
  1306. // GB2312 Test, check getting and setting of sample GB2312 chars
  1307. StartCheckZone( _T("GB2312 Test") );
  1308. MCD_STR strSampleGB2312Chars = _T("xD6xD0xB9xFAxC8xCB");
  1309. Check( xml.SetDoc(
  1310. _T("<?xml version="1.0" encoding="GB2312"?>n")
  1311. _T("<CHAR>xD6xD0xB9xFAxC8xCB</CHAR>")
  1312. ) );
  1313. Check( xml.FindElem() );
  1314. Check( xml.GetData() == strSampleGB2312Chars );
  1315. Check( xml.SetAttrib(_T("v"),strSampleGB2312Chars) );
  1316. Check( xml.GetAttrib(_T("v")) == strSampleGB2312Chars );
  1317. #endif
  1318. // Empty Data Test
  1319. StartCheckZone( _T("Empty Data") );
  1320. xml.SetDoc( NULL );
  1321. Check( xml.AddElem(_T("A"),_T("data")) );
  1322. Check( xml.SetData(_T("")) );
  1323. Check( xml.AddChildElem(_T("B"),_T("data")) );
  1324. Check( xml.SetChildData(_T("")) );
  1325. Check( xml.IntoElem() );
  1326. Check( xml.IntoElem() );
  1327. Check( xml.AddElem(_T("C"),_T("data")) );
  1328. Check( xml.OutOfElem() );
  1329. Check( xml.OutOfElem() );
  1330. Check( xml.GetChildTagName() == _T("B") );
  1331. Check( xml.GetTagName() == _T("A") );
  1332. // Depth First Traversal Test, loop through all elements
  1333. StartCheckZone( _T("Depth First Traversal Test") );
  1334. xml.SetDoc( _T("<A><B><C/><C/><C><D/></C></B><B><C/></B></A>") );
  1335. CString csListOfTagNames;
  1336. BOOL bFinished = FALSE;
  1337. if ( xml.FindElem() )
  1338. csListOfTagNames = MCD_2PCSZ(xml.GetTagName());
  1339. if ( ! xml.FindChildElem() )
  1340. bFinished = TRUE;
  1341. while ( ! bFinished )
  1342. {
  1343. // Process Element
  1344. xml.IntoElem();
  1345. csListOfTagNames += MCD_2PCSZ(xml.GetTagName());
  1346. // Next element (depth first)
  1347. BOOL bFound = xml.FindChildElem();
  1348. while ( ! bFound && ! bFinished )
  1349. {
  1350. if ( xml.OutOfElem() )
  1351. bFound = xml.FindChildElem();
  1352. else
  1353. bFinished = TRUE;
  1354. }
  1355. }
  1356. Check( csListOfTagNames == _T("ABCCCDBC") );
  1357. // Depth First Traversal Test 2, include root in loop
  1358. StartCheckZone( _T("Depth First Traversal Test 2") );
  1359. csListOfTagNames.Empty();
  1360. bFinished = FALSE;
  1361. xml.ResetPos();
  1362. if ( ! xml.FindElem() )
  1363. bFinished = TRUE;
  1364. while ( ! bFinished )
  1365. {
  1366. // Process element
  1367. CString csTag = MCD_2PCSZ(xml.GetTagName());
  1368. csListOfTagNames += csTag;
  1369. // Next element (depth first)
  1370. BOOL bFound = xml.FindChildElem();
  1371. while ( ! bFound && ! bFinished )
  1372. {
  1373. if ( xml.OutOfElem() )
  1374. bFound = xml.FindChildElem();
  1375. else
  1376. bFinished = TRUE;
  1377. }
  1378. if ( bFound )
  1379. xml.IntoElem();
  1380. }
  1381. Check( csListOfTagNames == _T("ABCCCDBC") );
  1382. // INI-Style Section Entry Test
  1383. StartCheckZone( _T("INI-Style Section Entry Test") );
  1384. MCD_STR strValue;
  1385. xml.SetDoc( NULL );
  1386. SetEntry( xml, _T("Settings"), _T("Count"), _T("10") );
  1387. SetEntry( xml, _T("Settings"), _T("User"), _T("John Smith") );
  1388. SetEntry( xml, _T("Files"), _T("Database"), _T("test1.txt") );
  1389. SetEntry( xml, _T("Files"), _T("Database"), _T("test2.txt") ); // overwrite
  1390. Check( FindEntry(xml,_T("Settings"),_T("Count"),strValue) );
  1391. Check( strValue == _T("10") );
  1392. Check( FindEntry(xml,_T("Files"),_T("Database"),strValue) );
  1393. Check( strValue == _T("test2.txt") );
  1394. // Load/Save Test
  1395. StartCheckZone( _T("Load/Save Test") );
  1396. MCD_STR strLSFilename = _T("CMarkupRunTest.xml");
  1397. BOOL bLSFileLoaded = xml.Load( strLSFilename );
  1398. if ( bLSFileLoaded )
  1399. {
  1400. // Load/Save
  1401. xml.FindElem();
  1402. Check( xml.Save(strLSFilename) );
  1403. Check( xml2.Load(strLSFilename) );
  1404. Check( xml2.FindElem() );
  1405. Check( xml2.GetTagName() == xml.GetTagName() );
  1406. }
  1407. else
  1408. m_csChecks += _T("File I/O tests skippedrn");
  1409. // Node Test, navigate/modify comments and other nodes
  1410. StartCheckZone( _T("Node Test") );
  1411. csPTDoc =
  1412. _T("<?xml version="1.0"?>n")
  1413. // To get MSXML to preserve whitespace in mixed content
  1414. // you can use a DTD and an xml:space attribute
  1415. // otherwise MSXML would not have a whitespace node between </B> <I>
  1416. // See "White Space Handling" in the XML Specification
  1417. // Also note the mixed content declaration of ITEM
  1418. _T("<!DOCTYPE PARSETEST [n")
  1419. _T("<!ELEMENT PARSETEST (ITEM*)>n")
  1420. _T("<!ATTLIST PARSETEST v CDATA '' s CDATA ''>n")
  1421. _T("<!ELEMENT ITEM (#PCDATA|B|I)*>n")
  1422. _T("<!ATTLIST ITEM note CDATA '' xml:space (default|preserve) 'preserve'>n")
  1423. _T("<!ELEMENT B ANY>n")
  1424. _T("<!ELEMENT I ANY>n")
  1425. _T("]>n")
  1426. _T("<!--tightcomment-->n")
  1427. _T("<PARSETEST v="1" s='6'>n")
  1428. _T("<!-- mid comment -->n")
  1429. _T("<ITEM note="hi"/>n")
  1430. _T("<ITEM note="see data">hi</ITEM>n")
  1431. _T("<ITEM> mixed <B>content</B> <I>okay</I></ITEM>n")
  1432. _T("</PARSETEST>n")
  1433. _T("<!-- end comment -->n")
  1434. ;
  1435. Check( xml.SetDoc(csPTDoc) );
  1436. Check( xml.FindNode() == xml.MNT_PROCESSING_INSTRUCTION );
  1437. Check( xml.GetData() == _T("xml version="1.0"") );
  1438. Check( xml.FindNode(xml.MNT_COMMENT) );
  1439. Check( xml.GetData() == _T("tightcomment") );
  1440. Check( xml.SetData( _T("comment 1 changed") ) );
  1441. Check( xml.GetData() == _T("comment 1 changed") );
  1442. Check( xml.FindNode(xml.MNT_EXCLUDE_WHITESPACE) == xml.MNT_ELEMENT );
  1443. Check( xml.GetTagName() == _T("PARSETEST") );
  1444. Check( xml.IntoElem() );
  1445. Check( xml.FindNode(xml.MNT_EXCLUDE_WHITESPACE) == xml.MNT_COMMENT );
  1446. Check( xml.GetData() == _T(" mid comment ") );
  1447. Check( xml.FindNode(xml.MNT_EXCLUDE_WHITESPACE) == xml.MNT_ELEMENT );
  1448. Check( xml.FindNode(xml.MNT_EXCLUDE_WHITESPACE) == xml.MNT_ELEMENT );
  1449. Check( xml.FindNode(xml.MNT_EXCLUDE_WHITESPACE) == xml.MNT_ELEMENT );
  1450. Check( xml.IntoElem() );
  1451. Check( xml.FindNode() == xml.MNT_TEXT );
  1452. Check( xml.GetData() == _T(" mixed ") );
  1453. Check( xml.FindNode() == xml.MNT_ELEMENT );
  1454. Check( xml.GetTagName() == _T("B") );
  1455. Check( xml.IntoElem() );
  1456. Check( xml.FindNode() == xml.MNT_TEXT );
  1457. Check( xml.GetData() == _T("content") );
  1458. Check( xml.FindNode() == 0 );
  1459. Check( xml.OutOfElem() );
  1460. Check( xml.FindNode() == xml.MNT_WHITESPACE );
  1461. Check( xml.GetData() == _T(" ") );
  1462. Check( xml.FindNode() == xml.MNT_ELEMENT );
  1463. Check( xml.GetTagName() == _T("I") );
  1464. Check( xml.IntoElem() );
  1465. Check( xml.FindNode() == xml.MNT_TEXT );
  1466. Check( xml.GetData() == _T("okay") );
  1467. Check( xml.FindNode() == 0 );
  1468. Check( xml.OutOfElem() );
  1469. Check( xml.FindNode() == 0 );
  1470. Check( xml.OutOfElem() );
  1471. // Create a document xml2 by copying all nodes of document xml
  1472. // Resulting document xml2 differs only by attributes and CRLF instead of just LF
  1473. xml2.SetDoc( NULL );
  1474. xml.ResetPos();
  1475. BOOL bBypassWhitespace = FALSE;
  1476. while ( 1 )
  1477. {
  1478. int nType = xml.FindNode();
  1479. if ( nType == 0 )
  1480. {
  1481. if ( ! xml.OutOfElem() )
  1482. break;
  1483. xml2.OutOfElem();
  1484. }
  1485. else
  1486. {
  1487. if ( bBypassWhitespace && nType == xml.MNT_WHITESPACE )
  1488. bBypassWhitespace = FALSE;
  1489. else
  1490. {
  1491. if ( nType == xml.MNT_ELEMENT )
  1492. {
  1493. xml2.AddNode( nType, xml.GetTagName() );
  1494. xml.IntoElem();
  1495. xml2.IntoElem();
  1496. }
  1497. else
  1498. {
  1499. xml2.AddNode( nType, xml.GetData() );
  1500. if ( nType & ( xml.MNT_PROCESSING_INSTRUCTION|xml.MNT_COMMENT|xml.MNT_DOCUMENT_TYPE ) )
  1501. {
  1502. // Bypass whitespace on nodes that automatically add it
  1503. xml2.FindNode( xml2.MNT_WHITESPACE );
  1504. bBypassWhitespace = TRUE;
  1505. }
  1506. }
  1507. }
  1508. }
  1509. }
  1510. // Create a document representing depth first traversal of nodes excluding whitespace
  1511. xml3.SetDoc( NULL );
  1512. xml3.AddElem( _T("NodeTraversal") );
  1513. xml2.ResetPos();
  1514. while ( 1 )
  1515. {
  1516. int nType = xml2.FindNode();
  1517. if ( nType == 0 )
  1518. {
  1519. if ( ! xml2.OutOfElem() )
  1520. break;
  1521. }
  1522. else if ( nType != xml2.MNT_WHITESPACE )
  1523. {
  1524. if ( nType == xml2.MNT_ELEMENT )
  1525. xml3.AddChildElem( _T("Node"), xml2.GetTagName() );
  1526. else
  1527. xml3.AddChildElem( _T("Node"), xml2.GetData() );
  1528. xml3.AddChildAttrib( _T("type"), xml2.GetNodeType() );
  1529. if ( nType == xml2.MNT_ELEMENT )
  1530. xml2.IntoElem();
  1531. }
  1532. }
  1533. // Now double check node traversal in xml3 against original xml
  1534. // This helps verify xml --> xml2 node by node copy
  1535. // and xml2 --> xml3 node traversal transformation into elements
  1536. xml.ResetPos();
  1537. xml3.ResetPos();
  1538. while ( 1 )
  1539. {
  1540. int nType = xml.FindNode();
  1541. if ( nType == 0 )
  1542. {
  1543. if ( ! xml.OutOfElem() )
  1544. break;
  1545. }
  1546. else if ( nType != xml.MNT_WHITESPACE )
  1547. {
  1548. if ( ! xml3.FindChildElem() )
  1549. {
  1550. Alert( _T("Error: missing element in traversal double check") );
  1551. break;
  1552. }
  1553. if ( nType != _ttoi(MCD_2PCSZ(xml3.GetChildAttrib(_T("type")))) )
  1554. {
  1555. Alert( _T("Error: wrong type in traversal double check") );
  1556. break;
  1557. }
  1558. if ( nType == xml.MNT_ELEMENT )
  1559. xml.IntoElem();
  1560. }
  1561. }
  1562. // Add element and remove it using RemoveNode
  1563. // Note that AddElem adds a CRLF (whitespace) after the element
  1564. // which is removed as a separate node
  1565. xml.ResetPos();
  1566. xml.FindElem();
  1567. xml.InsertChildElem( _T("ITEM"), _T("RemoveNode") );
  1568. xml.IntoElem();
  1569. xml.RemoveNode();
  1570. if ( xml.FindNode( xml.MNT_WHITESPACE ) )
  1571. xml.RemoveNode();
  1572. // Remove all whitespace between nodes
  1573. xml3.ResetPos();
  1574. while ( 1 )
  1575. {
  1576. int nType = xml3.FindNode( xml3.MNT_WHITESPACE | xml3.MNT_ELEMENT );
  1577. if ( nType == 0 )
  1578. {
  1579. if ( ! xml3.OutOfElem() )
  1580. break;
  1581. }
  1582. else if ( nType == xml3.MNT_WHITESPACE )
  1583. {
  1584. if ( ! xml3.RemoveNode() )
  1585. Alert( _T("Error: RemoveNode()") );
  1586. }
  1587. else // element
  1588. {
  1589. xml3.IntoElem();
  1590. }
  1591. }
  1592. // Success?
  1593. CString csResults;
  1594. if ( ! m_nErrorCount )
  1595. csResults.Format( _T("RunTest complete %d tests and %d checks for this buildrn"), m_nTotalZones, m_nTotalChecks );
  1596. else
  1597. csResults.Format( _T("Errors: %drn"), m_nErrorCount );
  1598. OutputTestResults( csResults + m_csChecks );
  1599. return 0;
  1600. }
  1601. void CMarkupDlg::OnButtonBrowse() 
  1602. {
  1603. LPCTSTR szTypes =
  1604. _T("XML Files (*.xml)|*.xml|")
  1605. _T("Text Files (*.txt)|*.txt|")
  1606. _T("All Files (*.*)|*.*||");
  1607. CFileDialog dlg( TRUE, _T("xml"), NULL, OFN_HIDEREADONLY, szTypes );
  1608. if ( dlg.DoModal() == IDCANCEL )
  1609. return;
  1610. CString csFilename = dlg.GetPathName();
  1611. GetDlgItem( IDC_EDIT_FILE )->SetWindowText( csFilename );
  1612. OutputParseResults( _T("") );
  1613. }
  1614. int CMarkupDlg::RandInt( int nNumber )
  1615. {
  1616. //
  1617. // Return an integer between 0 and nNumber
  1618. //
  1619. static BOOL bSeeded = FALSE;
  1620. if ( ! bSeeded )
  1621. {
  1622. srand( (unsigned)time( NULL ) );
  1623. bSeeded = TRUE;
  1624. }
  1625. // Sometimes rand() returns something close enough to 1 to make nRandom == nNumber
  1626. int nRandom = rand() * nNumber / RAND_MAX;
  1627. if ( nRandom == nNumber )
  1628. --nRandom;
  1629. return nRandom;
  1630. }
  1631. void CMarkupDlg::TimeStart()
  1632. {
  1633. // Keep track of time before operation
  1634. GetSystemTime( &m_stBefore );
  1635. }
  1636. int CMarkupDlg::TimeStop()
  1637. {
  1638. // Determine time span
  1639. SYSTEMTIME stAfter;
  1640. GetSystemTime( &stAfter );
  1641. int nBefore = m_stBefore.wMilliseconds + m_stBefore.wSecond * 1000 + m_stBefore.wMinute * 60000;
  1642. int nAfter = stAfter.wMilliseconds + stAfter.wSecond * 1000 + stAfter.wMinute * 60000;
  1643. int nDiff = nAfter - nBefore;
  1644. if ( m_stBefore.wHour < stAfter.wHour )
  1645. nDiff += 24*60000;
  1646. return nDiff;
  1647. }
  1648. void CMarkupDlg::OutputParseResults( CString csMsg )
  1649. {
  1650. GetDlgItem( IDC_ST_PARSE_RESULTS )->SetWindowText( csMsg );
  1651. }
  1652. void CMarkupDlg::OnButtonParse() 
  1653. {
  1654. OutputParseResults( _T("") );
  1655. // Get pathname
  1656. CString csPath;
  1657. GetDlgItem( IDC_EDIT_FILE )->GetWindowText( csPath );
  1658. if ( csPath.IsEmpty() )
  1659. {
  1660. OnButtonBrowse();
  1661. GetDlgItem( IDC_EDIT_FILE )->GetWindowText( csPath );
  1662. if ( csPath.IsEmpty() )
  1663. return;
  1664. RedrawWindow();
  1665. }
  1666. // Load and parse with CMarkup
  1667. CWaitCursor wait;
  1668. #ifdef MARKUP_MSXML
  1669. CMarkupMSXML xml;
  1670. #else
  1671. CMarkup xml;
  1672. #endif
  1673. TimeStart();
  1674. BOOL bResult = xml.Load( (LPCTSTR)csPath );
  1675. int nTime = TimeStop();
  1676. // Display results
  1677. CString csMsg;
  1678. CString csError = MCD_2PCSZ(xml.GetError());
  1679. if ( bResult )
  1680. csMsg.Format( _T("Loaded and parsed in %s milliseconds"), AddNumSeps(nTime) );
  1681. else
  1682. csMsg.Format( _T("Load or parse error (after %s milliseconds)"), AddNumSeps(nTime) );
  1683. if ( ! csError.IsEmpty() )
  1684. csMsg = csMsg + _T("rn") + csError;
  1685. OutputParseResults( csMsg );
  1686. }
  1687. void CMarkupDlg::OnTestXmlNew() 
  1688. {
  1689. // TODO: Add your control notification handler code here
  1690. //  CString csFilename;
  1691. //  GetDlgItem( IDC_EDIT_FILE )->GetWindowText( csFilename );
  1692. // #if ! defined(_UNICODE) && ! defined(_MBCS)
  1693. //  csFilename = WinAToUTF8( csFilename );
  1694. // #endif
  1695. //  MCD_STR strFilename = csFilename;
  1696. //  SetEntry( xmlSettings, _T("Settings"), _T("Filename"), strFilename );
  1697. //  CRect rect;
  1698. //  GetWindowRect( &rect );
  1699. //  CString csPos;
  1700. //  csPos.Format( _T("%d,%d"), rect.left, rect.top );
  1701. //  MCD_STR strPos = csPos;
  1702. //  CString pTargetFilePath="d:\1.xml";
  1703. //  CMarkup xml;
  1704. //  SetEntry( xml, _T("Settings"), _T("Position"), "社会主义好" );
  1705. //  xml.Save( (LPCTSTR)pTargetFilePath );
  1706. //  AfxMessageBox("生成完毕,请查看是否生成成功!");
  1707. //  StartXMLContent();//必须要先设定parameters,才能设定Reactions
  1708. //  StartAddListOfSpecies();
  1709. //  AddListOfSpecies("Node1",0);
  1710. //  AddListOfSpecies("Node2",0);
  1711. //  AddListOfSpecies("Node3",0);
  1712. //  AddListOfSpecies("Node0",10);
  1713. //  AddListOfSpecies("Node4",0);
  1714. //  EndAddListOfSpecies();
  1715. // 
  1716. //  StartAddListOfParameters();
  1717. //  AddListOfParameters("J0_J0_k",0.1);
  1718. //  AddListOfParameters("J1_J1_k",0.1);
  1719. //  AddListOfParameters("J2_J2_k",0.1);
  1720. //  AddListOfParameters("J3_J3_k",0.1);
  1721. //  AddListOfParameters("J0_k",0.1);
  1722. //  AddListOfParameters("J1_k",0.1);
  1723. //  AddListOfParameters("J2_k",0.1);
  1724. //  AddListOfParameters("J3_k",0.1);
  1725. //  EndAddListOfParameters();
  1726. // 
  1727. //  StartReactionContent();
  1728. //  AddListOfReaction("J0","Node0","Node1","J0_J0_k*Node0");
  1729. //  AddListOfReaction("J1","Node1","Node2","J1_J1_k*Node1");
  1730. //  AddListOfReaction("J2","Node2","Node3","J2_J2_k*Node2");
  1731. //  AddListOfReaction("J3","Node3","Node4","J3_J3_k*Node3");
  1732. //  EndReactionContent();
  1733. // 
  1734. //  EndXMLContent();
  1735. StartXMLContent();//必须要先设定parameters,才能设定Reactions
  1736. StartAddListOfSpecies();
  1737. AddListOfSpecies("E1",0.5);
  1738. AddListOfSpecies("E2",0.5);
  1739. AddListOfSpecies("E3",0.5);
  1740. AddListOfSpecies("E4",0.5);
  1741. AddListOfSpecies("E5",0.5);
  1742. EndAddListOfSpecies();
  1743. StartAddListOfParameters();
  1744. AddListOfParameters("J0_D1",1.4);
  1745. AddListOfParameters("J0_Km1",0.01);
  1746. AddListOfParameters("J1_D2",0.9);
  1747. AddListOfParameters("J1_Km2",0.01);
  1748. AddListOfParameters("J2_D2",0.9);
  1749. AddListOfParameters("J2_Km2",0.01);
  1750. AddListOfParameters("J3_D1",1.4);
  1751. AddListOfParameters("J3_Input",0.5);
  1752. AddListOfParameters("J3_Km1",0.01);
  1753. AddListOfParameters("J4_Km1",0.01);
  1754. AddListOfParameters("J5_D2",0.9);
  1755. AddListOfParameters("J5_Km2",0.01);
  1756. AddListOfParameters("J4_D1",1.4);
  1757. EndAddListOfParameters();
  1758. StartReactionContent();
  1759. AddListOfReaction("J0","E4","E3","J0_D1*E2*E4/(J0_Km1+E4)");
  1760. AddListOfReaction("J1","E1","E2","J1_D2*E1/(J1_Km2+E1)");
  1761. AddListOfReaction("J2","E5","E6","J2_D2*E5/(J2_Km2+E5)");
  1762. AddListOfReaction("J3","E2","E1","J3_D1*(J3_Input+E6)*E2/(J3_Km1+E2)");
  1763. AddListOfReaction("J4","E6","E5","J4_D1*E4*E6/(J4_Km1+E6)");
  1764. AddListOfReaction("J5","E3","E4","J5_D2*E3/(J5_Km2+E3)");
  1765. EndReactionContent();
  1766.   EndXMLContent();
  1767. }
  1768. void CMarkupDlg::AddListOfReaction(CString pReactionName,CString pNameOfReactants,CString pNameOfProducts,CString pWayOfCalc)
  1769. {
  1770. //  CString str;
  1771. //  str.Format("%s %s %c",numLeft,numRight,pWayOfCalc.GetAt(i));
  1772. //  AfxMessageBox(str);
  1773. CString numLeft,numRight;
  1774. for(int i=0;i<pWayOfCalc.GetLength();i++)
  1775. {
  1776. if(pWayOfCalc.GetAt(i)=='+' || pWayOfCalc.GetAt(i)=='-' || pWayOfCalc.GetAt(i)=='*' || pWayOfCalc.GetAt(i)=='/')
  1777. {
  1778. numLeft=pWayOfCalc.Left(i);
  1779. numRight=pWayOfCalc.Right(pWayOfCalc.GetLength()-i-1);
  1780. //  num1=atof(numLeft.GetBuffer(numLeft.GetLength()));
  1781. //  num2=atof(numRight.GetBuffer(numRight.GetLength()));
  1782. break;
  1783. }
  1784. }
  1785. MCD_STR strNumLeft=numLeft;
  1786. MCD_STR strNumRight=numRight;
  1787. MCD_STR strReactionName = pReactionName;
  1788. MCD_STR strNameOfReactants=pNameOfReactants;
  1789. MCD_STR strNameOfProducts=pNameOfProducts;
  1790. xml.AddElem("reaction");
  1791. xml.SetAttrib("id",strReactionName);
  1792. xml.SetAttrib("reversible","false");
  1793. xml.IntoElem();//into reaction
  1794. xml.AddElem("listOfReactants");
  1795. xml.IntoElem();//into listOfReactants
  1796. xml.AddElem("speciesReference");
  1797. xml.SetAttrib("species",strNameOfReactants);
  1798. xml.OutOfElem();//listOfReactants
  1799. xml.AddElem("listOfProducts");
  1800. xml.IntoElem();//into listOfProducts
  1801. xml.AddElem("speciesReference");
  1802. xml.SetAttrib("species",strNameOfProducts);
  1803. xml.OutOfElem();//speciesReference
  1804. xml.AddElem("kineticLaw");
  1805. xml.IntoElem();////into kineticLaw
  1806. xml.AddElem("math");
  1807. xml.IntoElem();//into math
  1808. xml.AddElem("apply");
  1809. xml.IntoElem();//into apply
  1810. switch (pWayOfCalc.GetAt(i))
  1811. {
  1812. case '+':
  1813. xml.AddElem("plus");
  1814. break;
  1815. case '-':
  1816. xml.AddElem("minus");
  1817. break;
  1818. case '*':
  1819. xml.AddElem("times");
  1820. break;
  1821. case '/':
  1822. xml.AddElem("divide");
  1823. break;
  1824. default:
  1825. return;
  1826. }
  1827. xml.AddElem("ci",strNumLeft);
  1828. xml.AddElem("ci",strNumRight);
  1829. xml.OutOfElem();//apply
  1830. xml.OutOfElem();//math
  1831. xml.OutOfElem();//kineticLaw
  1832. xml.OutOfElem();//reaction
  1833. }
  1834. void CMarkupDlg::AddListOfSpecies(CString pID,double quantity)
  1835. {
  1836. CString str;
  1837. str.Format("%f",quantity);
  1838. MCD_STR strQuantity=str;
  1839. MCD_STR strID=pID;
  1840. xml.AddElem("species");
  1841. xml.SetAttrib("id",strID);
  1842. xml.SetAttrib("initialConcentration",strQuantity);
  1843. xml.SetAttrib("compartment","compartment");
  1844. }
  1845. void CMarkupDlg::AddListOfParameters(CString pID,double quantity)
  1846. {
  1847. CString str;
  1848. str.Format("%f",quantity);
  1849. MCD_STR strQuantity=str;
  1850. MCD_STR strID=pID;
  1851. xml.AddElem("parameter");
  1852. xml.SetAttrib("id",strID);
  1853. xml.SetAttrib("value",strQuantity);
  1854. }
  1855. void CMarkupDlg::StartAddListOfSpecies()
  1856. {
  1857. xml.AddElem("listOfCompartments");
  1858. xml.IntoElem();//into listOfCompartments
  1859. xml.AddElem("compartment");
  1860. xml.SetAttrib("id","compartment");
  1861. xml.OutOfElem();//listOfCompartments
  1862. xml.AddElem("listOfSpecies");
  1863. xml.IntoElem();//into listOfSpecies
  1864. }
  1865. void CMarkupDlg::EndAddListOfSpecies()
  1866. {
  1867. xml.OutOfElem();//listOfSpecies
  1868. }
  1869. void CMarkupDlg::StartAddListOfParameters()
  1870. {
  1871. xml.AddElem("listOfParameters");
  1872. xml.IntoElem();//into listOfParameters
  1873. }
  1874. void CMarkupDlg::EndAddListOfParameters()
  1875. {
  1876. xml.OutOfElem();//listOfParameters
  1877. }
  1878. void CMarkupDlg::StartReactionContent()
  1879. {
  1880. xml.AddElem("listOfReactions");
  1881. xml.IntoElem();
  1882. }
  1883. void CMarkupDlg::EndReactionContent()
  1884. {
  1885. xml.OutOfElem();//listOfReactions
  1886. }
  1887. void CMarkupDlg::StartXMLContent()
  1888. {
  1889. xml.ResetPos();
  1890. xml.SetDoc("<?xml version="1.0" encoding="UTF-8"?>");
  1891. xml.AddElem("sbml");
  1892. xml.SetAttrib("level",2);
  1893. xml.SetAttrib("version",1);
  1894. xml.SetAttrib("xmlns:jd2","http://www.sys-bio.org/sbml/jd2");
  1895. xml.IntoElem();//into sbml
  1896. xml.AddElem("model");
  1897. xml.SetAttrib("id","LinearChain");
  1898. xml.SetAttrib("name","Simple Linear Pathway"); 
  1899. xml.IntoElem();//into model
  1900. xml.AddElem("annotation");
  1901. //  xml.IntoElem();//into annotation
  1902. //  xml.OutOfElem();//annotation
  1903. }
  1904. void CMarkupDlg::EndXMLContent()
  1905. {
  1906. xml.OutOfElem();//model
  1907. xml.OutOfElem();//sbml
  1908. CString str;
  1909. GetDlgItem( IDC_EDIT_FILE )->GetWindowText(str);
  1910. xml.Save((LPCTSTR)str);
  1911. SetTimer(1,500,NULL);
  1912. }
  1913. //  bool Load( MCD_CSTR szFileName );
  1914. //  bool SetDoc( MCD_PCSZ szDoc );
  1915. //  bool SetDoc( const MCD_STR& strDoc );
  1916. //  bool IsWellFormed();
  1917. //  bool FindElem( MCD_CSTR szName=NULL );
  1918. //  bool FindChildElem( MCD_CSTR szName=NULL );
  1919. //  bool IntoElem();
  1920. //  bool OutOfElem();
  1921. //  void ResetChildPos() { x_SetPos(m_iPosParent,m_iPos,0); };
  1922. //  void ResetMainPos() { x_SetPos(m_iPosParent,0,0); };
  1923. //  void ResetPos() { x_SetPos(0,0,0); };
  1924. //  MCD_STR GetTagName() const;
  1925. //  MCD_STR GetChildTagName() const { return x_GetTagName(m_iPosChild); };
  1926. //  MCD_STR GetData() const { return x_GetData(m_iPos); };
  1927. //  MCD_STR GetChildData() const { return x_GetData(m_iPosChild); };
  1928. //  MCD_STR GetElemContent() const { return x_GetElemContent(m_iPos); };
  1929. //  MCD_STR GetAttrib( MCD_CSTR szAttrib ) const { return x_GetAttrib(m_iPos,szAttrib); };
  1930. //  MCD_STR GetChildAttrib( MCD_CSTR szAttrib ) const { return x_GetAttrib(m_iPosChild,szAttrib); };
  1931. //  MCD_STR GetAttribName( int n ) const;
  1932. //  int FindNode( int nType=0 );
  1933. //  int GetNodeType() { return m_nNodeType; };
  1934. //  bool SavePos( MCD_CSTR szPosName=_T("") );
  1935. //  bool RestorePos( MCD_CSTR szPosName=_T("") );
  1936. //  const MCD_STR& GetError() const { return m_strError; };
  1937. //  int GetDocFlags() const { return m_nFlags; };
  1938. //  void SetDocFlags( int nFlags ) { m_nFlags = nFlags; };
  1939. // 
  1940. //  // Create
  1941. //  bool Save( MCD_CSTR szFileName );
  1942. //  const MCD_STR& GetDoc() const { return m_strDoc; };
  1943. //  bool AddElem( MCD_CSTR szName, MCD_CSTR szData=NULL, int nFlags=0 ) { return x_AddElem(szName,szData,nFlags); };
  1944. //  bool InsertElem( MCD_CSTR szName, MCD_CSTR szData=NULL, int nFlags=0 ) { return x_AddElem(szName,szData,nFlags|MNF_INSERT); };
  1945. //  bool AddChildElem( MCD_CSTR szName, MCD_CSTR szData=NULL, int nFlags=0 ) { return x_AddElem(szName,szData,nFlags|MNF_CHILD); };
  1946. //  bool InsertChildElem( MCD_CSTR szName, MCD_CSTR szData=NULL, int nFlags=0 ) { return x_AddElem(szName,szData,nFlags|MNF_INSERT|MNF_CHILD); };
  1947. //  bool AddElem( MCD_CSTR szName, int nValue, int nFlags=0 ) { return x_AddElem(szName,nValue,nFlags); };
  1948. //  bool InsertElem( MCD_CSTR szName, int nValue, int nFlags=0 ) { return x_AddElem(szName,nValue,nFlags|MNF_INSERT); };
  1949. //  bool AddChildElem( MCD_CSTR szName, int nValue, int nFlags=0 ) { return x_AddElem(szName,nValue,nFlags|MNF_CHILD); };
  1950. //  bool InsertChildElem( MCD_CSTR szName, int nValue, int nFlags=0 ) { return x_AddElem(szName,nValue,nFlags|MNF_INSERT|MNF_CHILD); };
  1951. //  bool AddAttrib( MCD_CSTR szAttrib, MCD_CSTR szValue ) { return x_SetAttrib(m_iPos,szAttrib,szValue); };
  1952. //  bool AddChildAttrib( MCD_CSTR szAttrib, MCD_CSTR szValue ) { return x_SetAttrib(m_iPosChild,szAttrib,szValue); };
  1953. //  bool AddAttrib( MCD_CSTR szAttrib, int nValue ) { return x_SetAttrib(m_iPos,szAttrib,nValue); };
  1954. //  bool AddChildAttrib( MCD_CSTR szAttrib, int nValue ) { return x_SetAttrib(m_iPosChild,szAttrib,nValue); };
  1955. //  bool AddSubDoc( MCD_CSTR szSubDoc ) { return x_AddSubDoc(szSubDoc,0); };
  1956. //  bool InsertSubDoc( MCD_CSTR szSubDoc ) { return x_AddSubDoc(szSubDoc,MNF_INSERT); };
  1957. //  MCD_STR GetSubDoc() const { return x_GetSubDoc(m_iPos); };
  1958. //  bool AddChildSubDoc( MCD_CSTR szSubDoc ) { return x_AddSubDoc(szSubDoc,MNF_CHILD); };
  1959. //  bool InsertChildSubDoc( MCD_CSTR szSubDoc ) { return x_AddSubDoc(szSubDoc,MNF_CHILD|MNF_INSERT); };
  1960. //  MCD_STR GetChildSubDoc() const { return x_GetSubDoc(m_iPosChild); };
  1961. //  bool AddNode( int nType, MCD_CSTR szText ) { return x_AddNode(nType,szText,0); };
  1962. //  bool InsertNode( int nType, MCD_CSTR szText ) { return x_AddNode(nType,szText,MNF_INSERT); };
  1963. // 
  1964. //  // Modify
  1965. //  bool RemoveElem();
  1966. //  bool RemoveChildElem();
  1967. //  bool RemoveNode();
  1968. //  bool SetAttrib( MCD_CSTR szAttrib, MCD_CSTR szValue ) { return x_SetAttrib(m_iPos,szAttrib,szValue); };
  1969. //  bool SetChildAttrib( MCD_CSTR szAttrib, MCD_CSTR szValue ) { return x_SetAttrib(m_iPosChild,szAttrib,szValue); };
  1970. //  bool SetAttrib( MCD_CSTR szAttrib, int nValue ) { return x_SetAttrib(m_iPos,szAttrib,nValue); };
  1971. //  bool SetChildAttrib( MCD_CSTR szAttrib, int nValue ) { return x_SetAttrib(m_iPosChild,szAttrib,nValue); };
  1972. //  bool SetData( MCD_CSTR szData, int nFlags=0 ) { return x_SetData(m_iPos,szData,nFlags); };
  1973. //  bool SetChildData( MCD_CSTR szData, int nFlags=0 ) { return x_SetData(m_iPosChild,szData,nFlags); };
  1974. //  bool SetData( int nValue ) { return x_SetData(m_iPos,nValue); };
  1975. //  bool SetChildData( int nValue ) { return x_SetData(m_iPosChild,nValue); };
  1976. //  bool SetElemContent( MCD_CSTR szContent ) { return x_SetElemContent(szContent); };
  1977. // 
  1978. //  // Utility
  1979. //  static bool ReadTextFile( MCD_CSTR szFileName, MCD_STR& strDoc, MCD_STR* pstrError=NULL, int* pnFlags=NULL );
  1980. //  static bool WriteTextFile( MCD_CSTR szFileName, MCD_STR& strDoc, MCD_STR* pstrError=NULL, int* pnFlags=NULL );
  1981. //  static MCD_STR EscapeText( MCD_CSTR szText, int nFlags = 0 );
  1982. //  static MCD_STR UnescapeText( MCD_CSTR szText, int nTextLength = -1 );
  1983. //  static int UTF16To8( char *pszUTF8, const wchar_t* pwszUTF16, int nUTF8Count );
  1984. //  static int DecodeCharUTF8( const char*& pszUTF8 );
  1985. //  static void EncodeCharUTF16( int nUChar, wchar_t* pwszUTF16, int& nWideLen );
  1986. //  static int UTF8To16( wchar_t* pwszUTF16, const char* pszUTF8, int nUTF8Count );
  1987. //  static int DecodeCharUTF16( const wchar_t*& pwszUTF16 );
  1988. //  static void EncodeCharUTF8( int nUChar, char* pszUTF8, int& nUTF8Len );
  1989. //  static MCD_STR UTF8ToA( MCD_CSTR pszUTF8, int* pnFailed = NULL );
  1990. //  static MCD_STR AToUTF8( MCD_CSTR pszANSI );
  1991. //  static MCD_STR GetDeclaredEncoding( MCD_CSTR szDoc );
  1992. // 
  1993. // 
  1994. // SC* CMarkupDlg::Push(SC *s,char c)
  1995. // { 
  1996. //  SC *p=(SC*)malloc(sizeof(SC)); 
  1997. //  p->c=c; 
  1998. //  p->next=s; 
  1999. //  return p; 
  2000. // } 
  2001. // SF* CMarkupDlg::Push(SF *s,float f)
  2002. // { 
  2003. //  SF *p=(SF*)malloc(sizeof(SF)); 
  2004. //  p->f=f; 
  2005. //  p->next=s; 
  2006. //  return p; 
  2007. // } 
  2008. // SC* CMarkupDlg::Pop(SC *s)
  2009. // { 
  2010. //  SC *q=s; 
  2011. //  s=s->next; 
  2012. //  free(q); 
  2013. //  return s; 
  2014. // } 
  2015. // SF* CMarkupDlg::Pop(SF *s)
  2016. // { 
  2017. //  SF *q=s; 
  2018. //  s=s->next; 
  2019. //  free(q); 
  2020. //  return s; 
  2021. // } 
  2022. // 
  2023. // 
  2024. // 
  2025. // float CMarkupDlg::Operate(float a,unsigned char theta, float b) 
  2026. // { 
  2027. //  switch(theta) 
  2028. //  { 
  2029. //  case '+': return a+b; 
  2030. //  case '-': return a-b; 
  2031. //  case '*': return a*b; 
  2032. //  case '/': return a/b; 
  2033. //  case '^': return pow(a,b); 
  2034. //  default : return 0; 
  2035. //  } 
  2036. // } 
  2037. // char OPSET[OPSETSIZE]={'+' , '-' , '*' , '/' ,'(' , ')' , '#','^'}; 
  2038. // 
  2039. // Status CMarkupDlg::In(char Test,char* TestOp) 
  2040. // { 
  2041. //  int Find=false; 
  2042. //  for (int i=0; i< OPSETSIZE; i++) 
  2043. //  { 
  2044. //  if (Test == TestOp[i]) Find= true; 
  2045. //  } 
  2046. //  return Find; 
  2047. // } 
  2048. // CMarkupDlg::ReturnOpOrd(char op,char* TestOp) 
  2049. // { 
  2050. //  for(int i=0; i< OPSETSIZE; i++) 
  2051. //  if (op == TestOp[i]) return i; 
  2052. // } 
  2053. // char CMarkupDlg::precede(char Aop, char Bop) 
  2054. // { 
  2055. //  return Prior[ReturnOpOrd(Aop,OPSET)][ReturnOpOrd(Bop,OPSET)]; 
  2056. // } 
  2057. // void CMarkupDlg::EvaluateExpression(char* MyExpression) 
  2058. // { // 算法3.4 
  2059. //  // 算术表达式求值的算符优先算法。 
  2060. //  // 设OPTR和OPND分别为运算符栈和运算数栈,OP为运算符集合。
  2061. //  UINT count=0;
  2062. //  char ss[11111];
  2063. //  SC *OPTR=NULL; // 运算符栈,字符元素 
  2064. //  vuPara.clear();
  2065. //  SC *OPOP=NULL;//opeartion
  2066. //  vPara.clear();
  2067. //  vPara2.clear();
  2068. //  OPOP=Push(OPOP,'#');
  2069. //  char TempData[20]; 
  2070. //  CString Data,a,b; 
  2071. //  char theta,Dr[]="#"; 
  2072. //  OPTR=Push(OPTR,'#'); 
  2073. //  strcpy(ss,MyExpression);
  2074. //  strcat(ss,Dr); 
  2075. //  //strcpy(c,ss);
  2076. //  strcpy(TempData,"");//字符串拷贝函数
  2077. //  char *p=ss;
  2078. //  while (*p!= '#' || OPTR->c!='#') 
  2079. //  { 
  2080. //  if (!In(*p, OPSET)) 
  2081. //  { 
  2082. //  Dr[0]=*p; 
  2083. //  strcat(TempData,Dr);//字符串连接函数 
  2084. //  p=p+1; 
  2085. //  if (In(*p, OPSET)) 
  2086. //  { 
  2087. //  Data=_T(TempData);//字符串转换函数(double) 
  2088. //  vuPara.push_back(Data);
  2089. //  strcpy(TempData,""); 
  2090. //  } 
  2091. //  }
  2092. //  else 
  2093. //  { // 不是运算符则进栈 
  2094. //  switch (precede(OPTR->c, *p)) 
  2095. //  { 
  2096. //  case '<': // 栈顶元素优先权低 
  2097. //  OPTR=Push(OPTR, *p); 
  2098. //  p++; 
  2099. //  break; 
  2100. //  case '=': // 脱括号并接收下一字符 
  2101. //  OPTR=Pop(OPTR); 
  2102. //  p++; 
  2103. //  break; 
  2104. //  case '>': // 退栈并将运算结果入栈 
  2105. //  theta=OPTR->c;OPTR=Pop(OPTR); 
  2106. // 
  2107. //  iter=vuPara.end();
  2108. //  b=*(iter-1);
  2109. //  vuPara.pop_back();
  2110. // 
  2111. //  iter=vuPara.end();
  2112. //  a=*(iter-1);
  2113. //  vuPara.pop_back();
  2114. //  CString str;
  2115. // 
  2116. //  str.Format("#%d",count);
  2117. //  vuPara.push_back(str);
  2118. //  OPOP=Push(OPOP,theta);
  2119. //  vPara.push_back(a);
  2120. //  vPara2.push_back(b);
  2121. //  count++;
  2122. // //  sprintf(ss,"%f%c%f",a,theta,b);
  2123. // //  puts(ss);
  2124. // //  system("pause");
  2125. //  break; 
  2126. //  } // switch 
  2127. //  } 
  2128. //  } // while 
  2129. // 
  2130. // //  while(OPOP->c!='#')
  2131. // //  {
  2132. // //  theta=OPOP->c;OPOP=Pop(OPOP); 
  2133. // // 
  2134. // //  iter=vPara.end();
  2135. // //  b=*(iter-1);
  2136. // //  vPara.pop_back();
  2137. // //  iter=vPara.end();
  2138. // //  a=*(iter-1);
  2139. // //  vPara.pop_back();
  2140. // //  str+=a;
  2141. // //  str+=_T(theta);
  2142. // //  str+=b;
  2143. // //  str+=_T("rn");
  2144. // //  }
  2145. //  CString str="";
  2146. // 
  2147. //  theta=OPOP->c;OPOP=Pop(OPOP); 
  2148. // 
  2149. //  iter=vPara.end();
  2150. //  b=*(iter-1);
  2151. // 
  2152. //  iter=vPara2.end();
  2153. //  a=*(iter-1);
  2154. //  str+=a;
  2155. //  str+=_T(theta);
  2156. //  str+=b;
  2157. // 
  2158. // 
  2159. //  AfxMessageBox(str);
  2160. //  FormFormula(str);
  2161. //  xml.Save("D:\系统数据\My Documents\SBML Models\new.xml");
  2162. //  AfxMessageBox("生成完毕,请查看是否生成成功!");
  2163. //  return ; 
  2164. // } // EvaluateExpression 
  2165. // 
  2166. // 
  2167. // void CMarkupDlg::OnCalcTest() 
  2168. // {
  2169. //  // TODO: Add your control notification handler code here
  2170. // // EvaluateExpression("1+2*3");
  2171. // // visit("1+#2");
  2172. // //  xml.Save("D:\系统数据\My Documents\SBML Models\new.xml");
  2173. // //  AfxMessageBox("生成完毕,请查看是否生成成功!");
  2174. // 
  2175. // }
  2176. // void CMarkupDlg::visit(CString str)
  2177. // {
  2178. //  CString numLeft,numRight;
  2179. //  int cutArea;
  2180. //  for(int i=0;i<str.GetLength();i++)
  2181. //  {
  2182. //  if(str.GetAt(i)=='+' || str.GetAt(i)=='-' || str.GetAt(i)=='*' || str.GetAt(i)=='/')
  2183. //  {
  2184. // 
  2185. //  numLeft=str.Left(i);
  2186. //  numRight=str.Right(str.GetLength()-i-1);
  2187. //  //  num1=atof(numLeft.GetBuffer(numLeft.GetLength()));
  2188. //  //  num2=atof(numRight.GetBuffer(numRight.GetLength()));
  2189. //  break;
  2190. //  }
  2191. //  }
  2192. //  cutArea=i;
  2193. //  MCD_STR strNumLeft=numLeft;
  2194. //  MCD_STR strNumRight=numRight;
  2195. // 
  2196. //  BOOLEAN returnValLeft=FALSE , returnValRight=FALSE;
  2197. //  for(i=0;i<numLeft.GetLength();i++)
  2198. //  {
  2199. //  if(numLeft.GetAt(i)=='#')
  2200. //  {
  2201. //  returnValLeft=TRUE;
  2202. //  break;
  2203. //  }
  2204. //  }
  2205. //  for(int j=0;j<numRight.GetLength();j++)
  2206. //  {
  2207. //  if(numRight.GetAt(j)=='#')
  2208. //  {
  2209. //  returnValRight=TRUE;
  2210. //  break;
  2211. //  }
  2212. //  }
  2213. //  if(returnValLeft==TRUE)
  2214. //  {
  2215. //  xml.AddElem("apply");
  2216. //  switch (str.GetAt(cutArea))
  2217. //  {
  2218. //  case '+':
  2219. //  xml.AddChildElem("plus");
  2220. //  break;
  2221. //  case '-':
  2222. //  xml.AddChildElem("minus");
  2223. //  break;
  2224. //  case '*':
  2225. //  xml.AddChildElem("times");
  2226. //  break;
  2227. //  case '/':
  2228. //  xml.AddChildElem("divide");
  2229. //  break;
  2230. //  default:
  2231. //  return;
  2232. //  }
  2233. //  return;
  2234. // 
  2235. //  }
  2236. // 
  2237. //  if(returnValRight==TRUE)
  2238. //  {
  2239. //  xml.AddElem("apply");
  2240. // 
  2241. // 
  2242. //  switch (str.GetAt(j))
  2243. //  {
  2244. //  case '+':
  2245. //  xml.AddChildElem("plus");
  2246. //  break;
  2247. //  case '-':
  2248. //  xml.AddChildElem("minus");
  2249. //  break;
  2250. //  case '*':
  2251. //  xml.AddChildElem("times");
  2252. //  break;
  2253. //  case '/':
  2254. //  xml.AddChildElem("divide");
  2255. //  break;
  2256. //  default:
  2257. //  return;
  2258. //  }
  2259. //  return;
  2260. //  }
  2261. //  if(returnValLeft==FALSE || returnValRight==FALSE)
  2262. //  {
  2263. //  xml.AddElem("apply");
  2264. //  xml.IntoElem();//into apply
  2265. // 
  2266. //  switch (str.GetAt(j))
  2267. //  {
  2268. //  case '+':
  2269. //  xml.AddElem("plus");
  2270. //  break;
  2271. //  case '-':
  2272. //  xml.AddElem("minus");
  2273. //  break;
  2274. //  case '*':
  2275. //  xml.AddElem("times");
  2276. //  break;
  2277. //  case '/':
  2278. //  xml.AddElem("divide");
  2279. //  break;
  2280. //  default:
  2281. //  return;
  2282. //  }
  2283. // 
  2284. //  xml.AddElem("ci",strNumLeft);
  2285. //  xml.AddElem("ci",strNumRight);
  2286. //  xml.OutOfElem();//apply
  2287. //  }
  2288. // 
  2289. // }
  2290. // 
  2291. // void CMarkupDlg::FormFormula(CString str)
  2292. // {
  2293. //  CString numLeft,numRight;
  2294. //  int cutArea;
  2295. //  for(int i=0;i<str.GetLength();i++)
  2296. //  {
  2297. //  if(str.GetAt(i)=='+' || str.GetAt(i)=='-' || str.GetAt(i)=='*' || str.GetAt(i)=='/')
  2298. //  {
  2299. // 
  2300. //  numLeft=str.Left(i);
  2301. //  numRight=str.Right(str.GetLength()-i-1);
  2302. //  //  num1=atof(numLeft.GetBuffer(numLeft.GetLength()));
  2303. //  //  num2=atof(numRight.GetBuffer(numRight.GetLength()));
  2304. //  break;
  2305. //  }
  2306. //  }
  2307. //  cutArea=i;
  2308. //  if(cutArea==str.GetLength())
  2309. //  return;
  2310. //  MCD_STR strNumLeft=numLeft;
  2311. //  MCD_STR strNumRight=numRight;
  2312. // 
  2313. //  BOOLEAN returnValLeft=FALSE , returnValRight=FALSE;
  2314. //  for(i=0;i<numLeft.GetLength();i++)
  2315. //  {
  2316. //  if(numLeft.GetAt(i)=='#')
  2317. //  {
  2318. //  returnValLeft=TRUE;
  2319. //  break;
  2320. //  }
  2321. //  }
  2322. //  for(int j=0;j<numRight.GetLength();j++)
  2323. //  {
  2324. //  if(numRight.GetAt(j)=='#')
  2325. //  {
  2326. //  returnValRight=TRUE;
  2327. //  break;
  2328. //  }
  2329. //  }
  2330. //  if(!(returnValLeft==FALSE && returnValRight==FALSE)) //递归调用的终止条件。如果是空树,则不执行任何操作
  2331. //  {
  2332. //  visit(str); //访问树根。注意T既表示树,也表示树根。
  2333. //  iter=vPara.begin();
  2334. //  if(returnValLeft==TRUE)
  2335. //  numLeft=*(iter+atoi(numLeft.Right(numLeft.GetLength()-1)));
  2336. //  iter=vPara2.begin();
  2337. //  if(returnValRight==TRUE)
  2338. //  numRight=*(iter+atoi(numRight.Right(numRight.GetLength()-1)));
  2339. // 
  2340. //  AfxMessageBox(numLeft);
  2341. //  AfxMessageBox(numRight);
  2342. //  FormFormula(numLeft); //先序遍历左子树
  2343. //  FormFormula(numRight); //先序遍历右子树
  2344. //  }
  2345. //  else
  2346. //  visit(str);
  2347. // }
  2348. void CMarkupDlg::OnCompile() 
  2349. {
  2350. // TODO: Add your control notification handler code here
  2351. GetDlgItem(IDC_ST_PARSE_RESULTS)->SetWindowText("Compiling Scamp files...");
  2352. CompileUse.clear();
  2353. int StartPos;
  2354. int EndPos;
  2355. CompileUse.clear();
  2356. CompileUse2.clear();
  2357. CompileUse3.clear();
  2358. CompileUse4.clear();
  2359. CompileUse5.clear();
  2360. CompileUse6.clear();
  2361. UpdateData();
  2362. if(m_cmdEdit=="")
  2363. {
  2364. GetDlgItem(IDC_ST_PARSE_RESULTS)->SetWindowText("Error:Have not found any code here in the code area...");
  2365. return;
  2366. }
  2367. m_cmdEdit.Remove(' ');
  2368. //Species
  2369. StartPos=m_cmdEdit.Find("Dec");
  2370. if(StartPos==-1)
  2371. {
  2372. GetDlgItem(IDC_ST_PARSE_RESULTS)->SetWindowText("Error:Cannot find any node declarations. Not a standard Scamp file...");
  2373. return;
  2374. }
  2375. int junction=StartPos+3;
  2376. CString str="";
  2377. char *pBuf;
  2378. for(int i=StartPos+3;m_cmdEdit.GetAt(i-1)!=';';i++)
  2379. {
  2380. if (m_cmdEdit.GetAt(i+1)==',' || m_cmdEdit.GetAt(i+1)==';')
  2381. {
  2382. pBuf=new char[i-junction+3];
  2383. pBuf[i-junction+1]=0;
  2384. for(int j=junction;j<=i;j++)
  2385. pBuf[j-junction]=m_cmdEdit[j];
  2386. CompileUse.push_back(pBuf);
  2387. junction=i+2;
  2388. i++;
  2389. delete pBuf;
  2390. }
  2391. }
  2392. //Reactions
  2393. StartPos=m_cmdEdit.Find("Reactions");
  2394. CString strTemp;
  2395. strTemp=m_cmdEdit.Right(m_cmdEdit.GetLength()-StartPos-11);
  2396. EndPos=strTemp.Find("end;");
  2397. CString reTemp;
  2398. reTemp=strTemp.Left(EndPos);
  2399.  // AfxMessageBox(reTemp);
  2400. //  int atemp;
  2401. //  atemp=reTemp.Find("[");
  2402. //  CString sdd;
  2403. //  sdd.Format("%d",atemp);
  2404. //  AfxMessageBox(sdd);
  2405. //  static int startSite,endSite;
  2406. //  for(i=0;i<reTemp.GetLength();i++)
  2407. //  {
  2408. //  if(reTemp.GetAt(i)=='[')
  2409. //  startSite=i;
  2410. //  if(reTemp.GetAt(i)==']')
  2411. //  {
  2412. //  endSite=i;
  2413. //  CString str;
  2414. //  str.Mid(startSite,endSite-startSite);
  2415. //  AfxMessageBox(str);
  2416. //  }
  2417. //  }
  2418. reTemp.Remove('[');
  2419. reTemp.Replace(']',' ');
  2420. reTemp.Replace("->"," ");
  2421. reTemp.Replace(';',' ');
  2422. reTemp.Remove('$');
  2423. // AfxMessageBox(reTemp);
  2424. CFile wrrfile("reactions.tmp",CFile::modeCreate|CFile::modeWrite);
  2425. wrrfile.Write(reTemp,strlen(reTemp));
  2426. wrrfile.Close();
  2427. FILE *ff;
  2428. if((ff=fopen("reactions.tmp","r"))==NULL)
  2429. {
  2430. AfxMessageBox("cuowu");
  2431. return;
  2432. }
  2433. else
  2434. {
  2435. while(!feof(ff))
  2436. {
  2437. char ctemp[4][111];
  2438. fscanf(ff,"%s %s %s %s n",ctemp[0],ctemp[1],ctemp[2],ctemp[3]);
  2439. CompileUse3.push_back(ctemp[0]);
  2440. CompileUse4.push_back(ctemp[1]);
  2441. CompileUse5.push_back(ctemp[2]);
  2442. CompileUse6.push_back(ctemp[3]);
  2443. }
  2444. fclose(ff);
  2445. }
  2446. //Initialize Conditions
  2447. float paraArray[111];
  2448. StartPos=m_cmdEdit.Find("Initialise");
  2449. if(StartPos==-1)
  2450. {
  2451. GetDlgItem(IDC_ST_PARSE_RESULTS)->SetWindowText("Error:Cannot find the keyword - Initialise . Not a standard Scamp file...");
  2452. return;
  2453. }
  2454. str=m_cmdEdit.Right(m_cmdEdit.GetLength()-StartPos-12);
  2455. EndPos=str.Find("end;");
  2456. if(EndPos==-1)
  2457. {
  2458. GetDlgItem(IDC_ST_PARSE_RESULTS)->SetWindowText("Error:Cannot find the end flag. Not a standard Scamp file...");
  2459. return;
  2460. }
  2461. CString temp;
  2462. temp=str.Left(EndPos);
  2463. temp.Replace('=',' ');
  2464. temp.Replace(';',' ');
  2465. CFile wrfile("conditions.tmp",CFile::modeCreate|CFile::modeWrite);
  2466. wrfile.Write(temp,strlen(temp));
  2467. wrfile.Close();
  2468. FILE *fp;
  2469. if((fp=fopen("conditions.tmp","r"))==NULL)
  2470. {
  2471. AfxMessageBox("cuowu");
  2472. return;
  2473. }
  2474. else
  2475. {
  2476. int arrayCount=0;
  2477. while(!feof(fp))
  2478. {
  2479. char ctemp[111];
  2480. fscanf(fp,"%s %f n",ctemp,&paraArray[arrayCount++]);
  2481. CompileUse2.push_back(ctemp);
  2482. }
  2483. fclose(fp);
  2484. }
  2485. //开始搞
  2486. StartXMLContent();
  2487. StartAddListOfSpecies();
  2488. for(int sd=0;sd<CompileUse.size();sd++)
  2489. {
  2490. AddListOfSpecies(CompileUse2.at(sd),paraArray[sd]);
  2491. }
  2492. EndAddListOfSpecies();
  2493. StartAddListOfParameters();
  2494. for(sd=CompileUse.size();sd<CompileUse2.size();sd++)
  2495. {
  2496. AddListOfParameters(CompileUse2.at(sd),paraArray[sd]);
  2497. }
  2498. EndAddListOfParameters();
  2499. StartReactionContent();
  2500. for(sd=0;sd<CompileUse3.size();sd++)
  2501. {
  2502. AddListOfReaction(CompileUse3.at(sd),CompileUse4.at(sd),CompileUse5.at(sd),CompileUse6.at(sd));
  2503. }
  2504. EndReactionContent();
  2505. EndXMLContent();
  2506. //CString str;
  2507. //  str.Format("%c",m_cmdEdit.GetAt(StartPos));
  2508. //  AfxMessageBox(str);
  2509. }
  2510. // 
  2511. // StartXMLContent();//必须要先设定parameters,才能设定Reactions
  2512. // StartAddListOfSpecies();
  2513. // AddListOfSpecies("E1",0.5);
  2514. // AddListOfSpecies("E2",0.5);
  2515. // AddListOfSpecies("E3",0.5);
  2516. // AddListOfSpecies("E4",0.5);
  2517. // AddListOfSpecies("E5",0.5);
  2518. // EndAddListOfSpecies();
  2519. // 
  2520. // StartAddListOfParameters();
  2521. // AddListOfParameters("J0_D1",1.4);
  2522. // AddListOfParameters("J0_Km1",0.01);
  2523. // AddListOfParameters("J1_D2",0.9);
  2524. // AddListOfParameters("J1_Km2",0.01);
  2525. // AddListOfParameters("J2_D2",0.9);
  2526. // AddListOfParameters("J2_Km2",0.01);
  2527. // AddListOfParameters("J3_D1",1.4);
  2528. // AddListOfParameters("J3_Input",0.5);
  2529. // AddListOfParameters("J3_Km1",0.01);
  2530. // AddListOfParameters("J4_Km1",0.01);
  2531. // AddListOfParameters("J5_D2",0.9);
  2532. // AddListOfParameters("J5_Km2",0.01);
  2533. // AddListOfParameters("J4_D1",1.4);
  2534. // EndAddListOfParameters();
  2535. // 
  2536. // StartReactionContent();
  2537. // AddListOfReaction("J0","E4","E3","J0_D1*E2*E4/(J0_Km1+E4)");
  2538. // AddListOfReaction("J1","E1","E2","J1_D2*E1/(J1_Km2+E1)");
  2539. // AddListOfReaction("J2","E5","E6","J2_D2*E5/(J2_Km2+E5)");
  2540. // AddListOfReaction("J3","E2","E1","J3_D1*(J3_Input+E6)*E2/(J3_Km1+E2)");
  2541. // AddListOfReaction("J4","E6","E5","J4_D1*E4*E6/(J4_Km1+E6)");
  2542. // AddListOfReaction("J5","E3","E4","J5_D2*E3/(J5_Km2+E3)");
  2543. // EndReactionContent();
  2544. // 
  2545. // EndXMLContent();
  2546. void CMarkupDlg::OnClear() 
  2547. {
  2548. // TODO: Add your control notification handler code here
  2549. m_cmdEdit="";
  2550. UpdateData(FALSE);
  2551. }
  2552. void CMarkupDlg::OnOpenExists() 
  2553. {
  2554. // TODO: Add your control notification handler code here
  2555. CString pDocRoute;
  2556. CFileDialog fileDlg(TRUE);
  2557. fileDlg.m_ofn.lpstrTitle="Choose the cmd file you want to load...";
  2558. fileDlg.m_ofn.lpstrFilter="Scamp Files(*.cmd)*.cmd";
  2559. if(IDOK==fileDlg.DoModal())
  2560. {
  2561. pDocRoute=fileDlg.GetPathName();
  2562. }
  2563. CFile file(pDocRoute,CFile::modeRead);
  2564. char *pBuf;
  2565. DWORD dwFileLen;
  2566. dwFileLen=file.GetLength();
  2567. pBuf=new char[dwFileLen+1];
  2568. pBuf[dwFileLen]=0;
  2569. file.Read(pBuf,dwFileLen);
  2570. file.Close();
  2571. m_cmdEdit=pBuf;
  2572. UpdateData(FALSE);
  2573. }
  2574. void CMarkupDlg::OnSaveAs() 
  2575. {
  2576. // TODO: Add your control notification handler code here
  2577. UpdateData();
  2578. CFileDialog ldFile(false,NULL,NULL,OFN_OVERWRITEPROMPT,"*.cmd"); //false类型对话框为保存文件对话框
  2579. ldFile.m_ofn.lpstrTitle="Choose the path you want to save...";
  2580. ldFile.m_ofn.lpstrFilter="Scamp files(*.cmd)*.cmdAll Files(*.*)*.*";
  2581. if(IDOK==ldFile.DoModal())
  2582. {
  2583. CFile wrfile(ldFile.GetPathName(),CFile::modeCreate|CFile::modeWrite);
  2584. wrfile.Write(m_cmdEdit,strlen(m_cmdEdit));
  2585. wrfile.Close();
  2586. AfxMessageBox("保存成功!");
  2587. }
  2588. }
  2589. void CMarkupDlg::OnTimer(UINT nIDEvent) 
  2590. {
  2591. // TODO: Add your message handler code here and/or call default
  2592. if(nIDEvent==1)
  2593. {
  2594. KillTimer(1);
  2595. GetDlgItem(IDC_ST_PARSE_RESULTS)->SetWindowText("Compilation has successfully Finished!!!!");
  2596. }
  2597. CDialog::OnTimer(nIDEvent);
  2598. }