1 /*========================================================================= 2 3 Program: Visualization Toolkit 4 Module: TestXML.cxx 5 6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 7 All rights reserved. 8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 9 10 This software is distributed WITHOUT ANY WARRANTY; without even 11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 12 PURPOSE. See the above copyright notice for more information. 13 14 =========================================================================*/ 15 // .NAME Test of vtkXMLParser 16 // .SECTION Description 17 // 18 19 #include "vtkXMLParser.h" 20 #include "vtkOutputWindow.h" 21 #include "vtkObjectFactory.h" 22 23 24 class vtkMyXML : public vtkXMLParser 25 { 26 public: 27 vtkTypeMacro(vtkMyXML, vtkXMLParser); 28 static vtkMyXML* New(); 29 30 protected: vtkMyXML()31 vtkMyXML() {} StartElement(const char *,const char **)32 void StartElement(const char*, const char**) {} EndElement(const char *)33 void EndElement(const char*) {} 34 35 private: 36 vtkMyXML(const vtkMyXML&); // Not implemented 37 void operator=(const vtkMyXML&); // Not implemented 38 }; 39 40 vtkStandardNewMacro(vtkMyXML); 41 TestXML(int argc,char * argv[])42int TestXML(int argc, char *argv[]) 43 { 44 int res = 0; 45 vtkOutputWindow::GetInstance()->PromptUserOn(); 46 if ( argc <= 1 ) 47 { 48 cout << "Usage: " << argv[0] << " <xml file>" << endl; 49 return 1; 50 } 51 52 vtkMyXML *parser = vtkMyXML::New(); 53 parser->SetFileName(argv[1]); 54 if ( ! parser->Parse() ) 55 { 56 cout << "Cannot parse the file: " << argv[1] << endl; 57 res = 1; 58 } 59 parser->SetFileName(0); 60 61 if( !parser->Parse("<xml>This is an XML file</xml>") ) 62 { 63 cout << "Cannot parse message" << endl; 64 res = 1; 65 } 66 67 parser->Delete(); 68 69 return res; 70 } 71