(file) Return to XmlParser.h CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

  1 mike  1.3 //%/////////////////////////////////////////////////////////////////////////////
  2 mike  1.1 //
  3           // Copyright (c) 2000 The Open Group, BMC Software, Tivoli Systems, IBM
  4           //
  5           // Permission is hereby granted, free of charge, to any person obtaining a
  6           // copy of this software and associated documentation files (the "Software"),
  7           // to deal in the Software without restriction, including without limitation
  8           // the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9           // and/or sell copies of the Software, and to permit persons to whom the
 10           // Software is furnished to do so, subject to the following conditions:
 11           //
 12           // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 13           // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 14           // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 15           // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 16           // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 17           // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 18           // DEALINGS IN THE SOFTWARE.
 19           //
 20 mike  1.3 //==============================================================================
 21 mike  1.1 //
 22 mike  1.3 // Author: Mike Brasher (mbrasher@bmc.com)
 23 mike  1.1 //
 24 mike  1.3 // Modified By:
 25 mike  1.2 //
 26 mike  1.3 //%/////////////////////////////////////////////////////////////////////////////
 27 mike  1.1 
 28           ////////////////////////////////////////////////////////////////////////////////
 29           //
 30           // XmlParser.h
 31           //
 32           ////////////////////////////////////////////////////////////////////////////////
 33           
 34           #ifndef Pegasus_XmlParser_h
 35           #define Pegasus_XmlParser_h
 36           
 37           #include <Pegasus/Common/Config.h>
 38           #include <Pegasus/Common/Array.h>
 39           #include <Pegasus/Common/Exception.h>
 40           #include <Pegasus/Common/Stack.h>
 41           
 42           PEGASUS_NAMESPACE_BEGIN
 43           
 44           class PEGASUS_COMMON_LINKAGE XmlException : public Exception
 45           {
 46           public:
 47           
 48 mike  1.1     enum Code
 49               {
 50           	BAD_START_TAG = 1,
 51           	BAD_END_TAG,
 52           	BAD_ATTRIBUTE_NAME,
 53           	EXPECTED_EQUAL_SIGN,
 54           	BAD_ATTRIBUTE_VALUE,
 55           	MINUS_MINUS_IN_COMMENT,
 56           	UNTERMINATED_COMMENT,
 57           	UNTERMINATED_CDATA,
 58           	UNTERMINATED_DOCTYPE,
 59           	TOO_MANY_ATTRIBUTES,
 60           	MALFORMED_REFERENCE,
 61           	EXPECTED_COMMENT_OR_CDATA,
 62           	START_END_MISMATCH,
 63           	UNCLOSED_TAGS,
 64           	MULTIPLE_ROOTS,
 65           	VALIDATION_ERROR,
 66           	SEMANTIC_ERROR
 67               };
 68           
 69 mike  1.1     XmlException(
 70           	Code code, 
 71           	Uint32 lineNumber,
 72           	const String& message = String());
 73           
 74               XmlException::Code getCode() const { return _code; }
 75           
 76           private:
 77           
 78               Code _code;
 79           };
 80           
 81           class PEGASUS_COMMON_LINKAGE XmlValidationError : public XmlException
 82           {
 83           public:
 84           
 85               XmlValidationError(Uint32 lineNumber, const String& message);
 86           };
 87           
 88           class PEGASUS_COMMON_LINKAGE XmlSemanticError : public XmlException
 89           {
 90 mike  1.1 public:
 91           
 92               XmlSemanticError(Uint32 lineNumber, const String& message);
 93           };
 94           
 95           struct XmlAttribute
 96           {
 97               const char* name;
 98               const char* value;
 99           };
100           
101           struct PEGASUS_COMMON_LINKAGE XmlEntry
102           {
103 mike  1.2     enum CIMType
104 mike  1.1     {
105           	XML_DECLARATION,
106           	START_TAG, 
107           	EMPTY_TAG, 
108           	END_TAG, 
109           	COMMENT,
110           	CDATA,
111           	DOCTYPE,
112           	CONTENT
113               };
114           
115               enum { MAX_ATTRIBUTES = 10 };
116           
117 mike  1.2     CIMType type;
118 mike  1.1     const char* text;
119               XmlAttribute attributes[MAX_ATTRIBUTES];
120               Uint32 attributeCount;
121           
122               void print() const;
123           
124               const XmlAttribute* findAttribute(const char* name) const;
125           
126               Boolean getAttributeValue(const char* name, Uint32& value) const;
127           
128               Boolean getAttributeValue(const char* name, Real32& value) const;
129           
130               Boolean getAttributeValue(const char* name, const char*& value) const;
131           
132               Boolean getAttributeValue(const char* name, String& value) const;
133           };
134           
135           class PEGASUS_COMMON_LINKAGE XmlParser
136           {
137           public:
138           
139 mike  1.1     // Warning: this constructor modifies the text.
140           
141               XmlParser(char* text);
142           
143               Boolean next(XmlEntry& entry);
144           
145               void putBack(XmlEntry& entry);
146           
147               ~XmlParser();
148           
149 mike  1.4     Uint32 getStackSize() const { return _stack.size(); }
150 mike  1.1 
151               Uint32 getLine() const { return _line; }
152           
153           private:
154           
155               void _skipWhitespace(char*& p);
156           
157               Boolean _getElementName(char*& p);
158           
159               Boolean _getOpenElementName(char*& p, Boolean& openCloseElement);
160           
161               void _getAttributeNameAndEqual(char*& p);
162           
163               void _getAttributeValue(char*& p);
164           
165               void _getComment(char*& p);
166           
167               void _getCData(char*& p);
168           
169               void _getDocType(char*& p);
170           
171 mike  1.1     void _getContent(char*& p);
172           
173               void _substituteReferences(char* text);
174           
175               void _getElement(char*& p, XmlEntry& entry);
176           
177               Uint32 _line;
178               char* _text;
179               char* _current;
180               char _restoreChar;
181               Stack<char*> _stack;
182               Boolean _foundRoot;
183               Stack<XmlEntry> _putBackStack;
184           };
185           
186 mike  1.5 PEGASUS_COMMON_LINKAGE void XmlAppendCString(
187 mike  1.1     Array<Sint8>& out, 
188 mike  1.5     const char* str);
189 mike  1.1 
190           PEGASUS_NAMESPACE_END
191           
192           #endif /* Pegasus_XmlParser_h */

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2