OLD | NEW |
(Empty) | |
| 1 // Copyright 2004 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef WEBRTC_LIBJINGLE_XMLLITE_XMLPARSER_H_ |
| 6 #define WEBRTC_LIBJINGLE_XMLLITE_XMLPARSER_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "third_party/xmllite/xmlnsstack.h" |
| 11 #ifdef EXPAT_RELATIVE_PATH |
| 12 #include "expat.h" |
| 13 #else |
| 14 #include "third_party/expat/v2_0_1/Source/lib/expat.h" |
| 15 #endif // EXPAT_RELATIVE_PATH |
| 16 |
| 17 struct XML_ParserStruct; |
| 18 typedef struct XML_ParserStruct* XML_Parser; |
| 19 |
| 20 namespace buzz { |
| 21 |
| 22 class XmlParseHandler; |
| 23 class XmlParseContext; |
| 24 class XmlParser; |
| 25 |
| 26 class XmlParseContext { |
| 27 public: |
| 28 virtual ~XmlParseContext() {} |
| 29 virtual QName ResolveQName(const char * qname, bool isAttr) = 0; |
| 30 virtual void RaiseError(XML_Error err) = 0; |
| 31 virtual void GetPosition(unsigned long * line, unsigned long * column, |
| 32 unsigned long * byte_index) = 0; |
| 33 }; |
| 34 |
| 35 class XmlParseHandler { |
| 36 public: |
| 37 virtual ~XmlParseHandler() {} |
| 38 virtual void StartElement(XmlParseContext * pctx, |
| 39 const char * name, const char ** atts) = 0; |
| 40 virtual void EndElement(XmlParseContext * pctx, |
| 41 const char * name) = 0; |
| 42 virtual void CharacterData(XmlParseContext * pctx, |
| 43 const char * text, int len) = 0; |
| 44 virtual void Error(XmlParseContext * pctx, |
| 45 XML_Error errorCode) = 0; |
| 46 }; |
| 47 |
| 48 class XmlParser { |
| 49 public: |
| 50 static void ParseXml(XmlParseHandler * pxph, std::string text); |
| 51 |
| 52 explicit XmlParser(XmlParseHandler * pxph); |
| 53 bool Parse(const char * data, size_t len, bool isFinal); |
| 54 void Reset(); |
| 55 virtual ~XmlParser(); |
| 56 |
| 57 // expat callbacks |
| 58 void ExpatStartElement(const char * name, const char ** atts); |
| 59 void ExpatEndElement(const char * name); |
| 60 void ExpatCharacterData(const char * text, int len); |
| 61 void ExpatXmlDecl(const char * ver, const char * enc, int standalone); |
| 62 |
| 63 private: |
| 64 |
| 65 class ParseContext : public XmlParseContext { |
| 66 public: |
| 67 ParseContext(); |
| 68 virtual ~ParseContext(); |
| 69 virtual QName ResolveQName(const char * qname, bool isAttr); |
| 70 virtual void RaiseError(XML_Error err) { if (!raised_) raised_ = err; } |
| 71 virtual void GetPosition(unsigned long * line, unsigned long * column, |
| 72 unsigned long * byte_index); |
| 73 XML_Error RaisedError() { return raised_; } |
| 74 void Reset(); |
| 75 |
| 76 void StartElement(); |
| 77 void EndElement(); |
| 78 void StartNamespace(const char * prefix, const char * ns); |
| 79 void SetPosition(int line, int column, long byte_index); |
| 80 |
| 81 private: |
| 82 XmlnsStack xmlnsstack_; |
| 83 XML_Error raised_; |
| 84 XML_Size line_number_; |
| 85 XML_Size column_number_; |
| 86 XML_Index byte_index_; |
| 87 }; |
| 88 |
| 89 ParseContext context_; |
| 90 XML_Parser expat_; |
| 91 XmlParseHandler * pxph_; |
| 92 bool sentError_; |
| 93 }; |
| 94 |
| 95 } // namespace buzz |
| 96 |
| 97 #endif // WEBRTC_LIBJINGLE_XMLLITE_XMLPARSER_H_ |
OLD | NEW |