![]() |
VR-Forces 4.0.4 Class Documentation
|
00001 /******************************************************************************* 00002 ** Copyright (c) 2005 MAK Technologies, Inc. 00003 ** All rights reserved. 00004 *******************************************************************************/ 00005 /******************************************************************************* 00006 ** $RCSfile: mtFltXmlReader.h,v $ $Revision: 1.8 $ $State: Exp $ 00007 *******************************************************************************/ 00008 00009 #ifndef mtFltXmlReader_H_ 00010 #define mtFltXmlReader_H_ 00011 00012 // 00013 // \file mtFltXmlReader.h 00014 // \brief Represents a reader class that interacts with libXml to read a Metaflight file 00015 // 00016 00017 #include "mtflt/mtfltDefines.h" 00018 #include <vlutil/vlString.h> 00019 #include <libxml/xmlreader.h> 00020 00021 // \brief Represents a reader class that interacts with libXml to read a Metaflight file 00022 // A Metaflight file is represented as a n-ary tree document in which the tags contained 00023 // inside other tags are represented as parent-child relationships. For example, 00024 // \code 00025 // <Ellipsoid name="WGS84"> 00026 // <SemiMajorRadius>6378137</SemiMajorRadius> 00027 // <SemiMinorRadius>6356752.31424518</SemiMinorRadius> 00028 // </Ellipsoid> 00029 // \endcode 00030 // is represented as a tree with the Ellipsoid node as the father and SemiMajorRadius and 00031 // SemiMinorRadius as children. Both SemiMajorRadius and SemiMinorRadius are considered 00032 // atomic nodes since they have no child tags. 00033 00034 class DT_DLL_mtflt DtMtFltXmlReader 00035 { 00036 public: 00037 00038 // Default constructor. 00039 DtMtFltXmlReader(); 00040 00041 DtMtFltXmlReader(xmlNodePtr root, xmlNodePtr node); 00042 00043 // Destructor 00044 virtual ~DtMtFltXmlReader(); 00045 00046 // Copy constructor 00047 DtMtFltXmlReader(const DtMtFltXmlReader& node); 00048 00049 // Assignment operator 00050 DtMtFltXmlReader& operator=(const DtMtFltXmlReader& orig); 00051 00052 // Finds the first node whose tag matches the one given by \p nodeName. 00053 // \param node Starting node for the search inside the xml document 00054 // \param nodeName Name of the node to be searched (e.g. "GridStructure") 00055 // \return 0 if no matches are found. 00056 virtual xmlNodePtr findNode(xmlNodePtr node, const char* nodeName); 00057 00058 // Finds the node named as nodeName and that also has an attribute named 00059 // attrName with a value of attrValue. For example, 00060 // <tt>findNode(nodeptr, "GridStructure", "name", "abc")</tt> searches for a 00061 // node that looks like <br> <br> <tt> 00062 // <GridStructure name="abc"> <br> 00063 // ... <br> 00064 // </GridStructure> 00065 // </tt> 00066 // \return 0 if no matches are found. 00067 virtual xmlNodePtr findNode(xmlNodePtr node, const char* nodeName, 00068 const char* attrName, const char *attrValue); 00069 00070 // Returns the value of the attribute attrname inside the node. Attributes 00071 // are specified inside the node like this <br><br> <tt> 00072 // <node \e attrname=\e value ...> <br> 00073 // ... <br> 00074 // </node> 00075 // </tt> 00076 // \param node Node to access 00077 // \param attrname Name of the attribute to be searched (e.g. "name") 00078 // \return The attribute's value if present or an empty DtSring otherwise. 00079 virtual DtString getAttrValue(xmlNodePtr node, const char* attrname) const; 00080 00081 // Returns the value of an "atomic" node. Atomic nodes are the ones that 00082 // have the following structure <tt><tag>value</tag></tt>. 00083 // \param node Node to start the search of the atomic node 00084 // \param nodeName Name of the atomic node to be searched 00085 // \return It returns an empty DtString if the node has the form or <tag></tag> 00086 virtual DtString getAtomicNodeValue(xmlNodePtr node, const char* nodeName); 00087 00088 // \return the next node which is not a blank text node 00089 virtual void nextNode(xmlNodePtr& node); 00090 00091 // \return the top root node of this reader 00092 virtual xmlNodePtr getRootNode() { return myRootNode; }; 00093 00094 protected: 00095 00096 xmlNodePtr myRootNode; 00097 xmlNodePtr myCurNode; 00098 00099 // Returns the value of an "atomic" node. Atomic nodes are the ones that 00100 // have the following structure <tag>value</tag>. It returns the empty 00101 // string if the node has the form or <tag></tag> 00102 virtual DtString getAtomicNodeValue(xmlNodePtr node) const; 00103 00104 // Returns a pointer to the first child of the node or NULL if not defined 00105 // The reason for this method is because libXml also includes blank text 00106 // nodes sometimes, so they need to be filtered out. This function 00107 // guarantees you get an actual child node as the first node 00108 virtual xmlNodePtr getChildren(xmlNodePtr node) const; 00109 00110 }; 00111 00112 #endif