00001 /* 00002 * 00003 * Copyright (C) 2003-2010, OFFIS e.V. 00004 * All rights reserved. See COPYRIGHT file for details. 00005 * 00006 * This software and supporting documentation were developed by 00007 * 00008 * OFFIS e.V. 00009 * R&D Division Health 00010 * Escherweg 2 00011 * D-26121 Oldenburg, Germany 00012 * 00013 * 00014 * Module: dcmsr 00015 * 00016 * Author: Joerg Riesmeier 00017 * 00018 * Purpose: 00019 * classes: DSRXMLDocument 00020 * 00021 * Last Update: $Author: joergr $ 00022 * Update Date: $Date: 2010-10-14 13:16:33 $ 00023 * CVS/RCS Revision: $Revision: 1.7 $ 00024 * Status: $State: Exp $ 00025 * 00026 * CVS/RCS Log at end of file 00027 * 00028 */ 00029 00030 00031 #ifndef DSRXMLD_H 00032 #define DSRXMLD_H 00033 00034 #include "dcmtk/config/osconfig.h" /* make sure OS specific configuration is included first */ 00035 00036 #include "dcmtk/ofstd/ofstream.h" 00037 #include "dcmtk/dcmsr/dsrtypes.h" 00038 #include "dcmtk/dcmsr/dsrxmlc.h" 00039 00040 00041 /*--------------------* 00042 * type definitions * 00043 *--------------------*/ 00044 00045 #ifndef WITH_LIBXML 00046 // define types if 'libxml' absent 00047 typedef void (*xmlDocPtr); 00048 typedef void (*xmlCharEncodingHandlerPtr); 00049 typedef char xmlChar; 00050 #endif 00051 00052 00053 /*---------------------* 00054 * class declaration * 00055 *---------------------*/ 00056 00063 class DSRXMLDocument 00064 : protected DSRTypes 00065 { 00066 00067 public: 00068 00069 // --- constructors and destructor --- 00070 00073 DSRXMLDocument(); 00074 00077 virtual ~DSRXMLDocument(); 00078 00079 00080 // --- misc routines --- 00081 00084 void clear(); 00085 00089 OFBool valid() const; 00090 00091 // --- input and output --- 00092 00099 OFCondition read(const OFString &filename, 00100 const size_t flags = 0); 00101 00102 00103 // --- character encoding --- 00104 00109 OFBool encodingHandlerValid() const; 00110 00116 OFCondition setEncodingHandler(const char *charset); 00117 00118 00119 // --- navigation and checking --- 00120 00124 DSRXMLCursor getRootNode() const; 00125 00135 DSRXMLCursor getNamedNode(const DSRXMLCursor &cursor, 00136 const char *name, 00137 const OFBool required = OFTrue) const; 00138 00144 OFBool matchNode(const DSRXMLCursor &cursor, 00145 const char *name) const; 00146 00152 OFCondition checkNode(const DSRXMLCursor &cursor, 00153 const char *name) const; 00154 00155 00156 // --- get attributes and node content --- 00157 00163 OFBool hasAttribute(const DSRXMLCursor &cursor, 00164 const char *name) const; 00165 00177 OFString &getStringFromAttribute(const DSRXMLCursor &cursor, 00178 OFString &stringValue, 00179 const char *name, 00180 const OFBool encoding = OFFalse, 00181 const OFBool required = OFTrue) const; 00182 00193 OFCondition getElementFromAttribute(const DSRXMLCursor &cursor, 00194 DcmElement &delem, 00195 const char *name, 00196 const OFBool encoding = OFFalse, 00197 const OFBool required = OFTrue) const; 00198 00207 OFString &getStringFromNodeContent(const DSRXMLCursor &cursor, 00208 OFString &stringValue, 00209 const char *name = NULL, 00210 const OFBool encoding = OFFalse, 00211 const OFBool clearString = OFTrue) const; 00212 00220 OFCondition getElementFromNodeContent(const DSRXMLCursor &cursor, 00221 DcmElement &delem, 00222 const char *name = NULL, 00223 const OFBool encoding = OFFalse) const; 00224 00232 E_ValueType getValueTypeFromNode(const DSRXMLCursor &cursor) const; 00233 00240 E_RelationshipType getRelationshipTypeFromNode(const DSRXMLCursor &cursor) const; 00241 00242 00243 // --- error/warning messages --- 00244 00248 void printUnexpectedNodeWarning(const DSRXMLCursor &cursor) const; 00249 00254 void printGeneralNodeError(const DSRXMLCursor &cursor, 00255 const OFCondition &result) const; 00256 00257 protected: 00258 00264 OFBool convertUtf8ToCharset(const xmlChar *fromString, 00265 OFString &toString) const; 00266 00271 void printMissingAttributeError(const DSRXMLCursor &cursor, 00272 const char *name) const; 00273 00274 // --- static function --- 00275 00282 static OFString &getFullNodePath(const DSRXMLCursor &cursor, 00283 OFString &stringValue, 00284 const OFBool omitCurrent = OFFalse); 00285 00286 00287 private: 00288 00290 xmlDocPtr Document; 00292 xmlCharEncodingHandlerPtr EncodingHandler; 00293 00294 // --- declaration copy constructor and assignment operator 00295 00296 DSRXMLDocument(const DSRXMLDocument &); 00297 DSRXMLDocument &operator=(const DSRXMLDocument &); 00298 }; 00299 00300 00301 #endif 00302 00303 00304 /* 00305 * CVS/RCS Log: 00306 * $Log: dsrxmld.h,v $ 00307 * Revision 1.7 2010-10-14 13:16:33 joergr 00308 * Updated copyright header. Added reference to COPYRIGHT file. 00309 * 00310 * Revision 1.6 2009-10-13 14:57:51 uli 00311 * Switched to logging mechanism provided by the "new" oflog module. 00312 * 00313 * Revision 1.5 2005-12-08 16:05:36 meichel 00314 * Changed include path schema for all DCMTK header files 00315 * 00316 * Revision 1.4 2004/01/05 14:35:44 joergr 00317 * Renamed XML attribute "ref_id" to "ref". 00318 * 00319 * Revision 1.3 2003/12/01 15:46:18 joergr 00320 * Changed XML encoding of by-reference relationships if flag 00321 * XF_valueTypeAsAttribute is set. 00322 * 00323 * Revision 1.2 2003/08/07 17:31:00 joergr 00324 * Removed libxml dependency from header files. Simplifies linking (MSVC). 00325 * 00326 * Revision 1.1 2003/08/07 12:16:37 joergr 00327 * Added interface classes hiding the access to libxml (document and cursor 00328 * class). 00329 * 00330 * 00331 */