- Main Page
- Namespaces
- Classes
- Files
- Related Pages

# /Users/fpy/titan-1-5-MBARI/Mers/Utils/Io/Xml/Stream/Libxml2/test1.cpp

    00001
    00002 //
    00003 // Copyright (c) 2004           Model-based Embedded and Robotic Systems Group
    00004 // All Rights Reserved          Massachusetts Institute of Technology
    00005 //
    00006 // This software is provided as is. Model-based Embedded and Robotic Systems
    00007 // (MERS) group does not assume any responsibility.
    00008 //
    00009 // Organization:        Model-based Embedded and Robotic Systems Group
    00010 //                                      Massachusetts Institute of Technology
    00011 //
    00013
    00014 #include "Libxml2StreamReader.h"
    00015 #include "../XmlStreamException.h"
    00016 #include <iostream>
    00017
    00018 using namespace Mers::Utils::Io::Xml::Stream::Libxml2;
    00019 using namespace std;
    00020
    00021 int main(int argc, char* argv[])
    00022 {
    00023   // initialize the library and check for potential version mismatches
    00024   LIBXML_TEST_VERSION
    00025
    00026   try {
    00027     Libxml2StreamReader reader(argv[1]);
    00028     if(reader.getEventType()==XmlStreamReader::START_DOCUMENT) {
    00029       cout << "StartDocument\n";
    00030     } else {
    00031       cout << "ERROR: getEventType() returned a weird event type!\n";
    00032     }
    00033
    00034     while(reader.hasNext()) {
    00035       reader.next();
    00036       if(reader.isStartElement()) {
    00037         cout << "StartElement: " << reader.getLocalName() << endl;
    00038       } else if(reader.isEndElement()) {
    00039         cout << "EndElement: " << reader.getLocalName() << endl;
    00040       } else if(reader.isCharacters()) {
    00041         cout << "Characters: " << reader.getText() << endl;
    00042       } else if(reader.isWhiteSpace()) {
    00043         cout << '.';
    00044       } else if(reader.getEventType()==XmlStreamReader::END_DOCUMENT) {
    00045         cout << "EndDocument";
    00046       } else {
    00047         cout << "Unrecognized event. " << endl;
    00048       }
    00049     }
    00050
    00051     // clean-up function for libxml2
    00052     xmlCleanupParser();
    00053
    00054   } catch(XmlStreamException e) {
    00055     cerr << e.what() << endl;
    00056   } catch(...) {
    00057     cerr << "Unknown exception" << endl;
    00058   }
    00059 }