0031340: LDOM fails to read XML file starting with BOM
[occt.git] / src / LDOM / LDOMParser.hxx
CommitLineData
b311480e 1// Created on: 2001-07-20
2// Created by: Alexander GRIGORIEV
973c2be1 3// Copyright (c) 2001-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
b311480e 15
04232180 16//AGV 060302: Input from std::istream
7fd59977 17
18#ifndef LDOMParser_HeaderFile
19#define LDOMParser_HeaderFile
20
21#include <LDOM_Document.hxx>
22#include <LDOM_OSStream.hxx>
23
24class LDOM_XmlReader;
04232180 25//class std::istream;
7fd59977 26
27// Class LDOMParser
28//
29
30class LDOMParser
31{
32 public:
33 // ---------- PUBLIC METHODS ----------
34
35 LDOMParser () : myReader (NULL), myCurrentData (16384) {}
36 // Empty constructor
37
38 virtual Standard_EXPORT ~LDOMParser ();
39 // Destructor
40
41 Standard_EXPORT LDOM_Document
42 getDocument ();
43 // Get the LDOM_Document
44
45 Standard_EXPORT Standard_Boolean
46 parse (const char * const aFileName);
47 // Parse a file
48 // Returns True if error occurred, then GetError() can be called
49
50 Standard_EXPORT Standard_Boolean
04232180 51 parse (std::istream& anInput,
5fce1605 52 const Standard_Boolean theTagPerStep = Standard_False,
53 const Standard_Boolean theWithoutRoot = Standard_False);
7fd59977 54 // Parse a C++ stream
5fce1605 55 // theTagPerStep - if true - extract characters from anInput until '>'
56 // extracted character and parse only these characters.
57 // if false - extract until eof
58 // theWithoutRoot - if true - create fictive "document" element before parsing
59 // and consider that document start element has been already read
60 // - if false - parse a document as usual (parse header, document tag and etc)
7fd59977 61 // Returns True if error occurred, then GetError() can be called
62
63 Standard_EXPORT const TCollection_AsciiString&
64 GetError (TCollection_AsciiString& aData) const;
65 // Return text describing a parsing error, or Empty if no error occurred
66
8f34d47e 67 // Returns the byte order mask defined at the start of a stream
68 Standard_EXPORT LDOM_OSStream::BOMType GetBOM() const;
69
7fd59977 70 protected:
71 // ---------- PROTECTED METHODS ----------
72
73 Standard_EXPORT virtual Standard_Boolean
74 startElement ();
75 // virtual hook on 'StartElement' event for descendant classes
76
77 Standard_EXPORT virtual Standard_Boolean
78 endElement ();
79 // virtual hook on 'EndElement' event for descendant classes
80
81 Standard_EXPORT LDOM_Element
82 getCurrentElement () const;
83 // to be called from startElement() and endElement()
84
85 private:
86 // ---------- PRIVATE METHODS ----------
5fce1605 87 Standard_Boolean ParseDocument (Standard_IStream& theIStream, const Standard_Boolean theWithoutRoot = Standard_False);
7fd59977 88
4ff92abe 89 Standard_Boolean ParseElement (Standard_IStream& theIStream);
7fd59977 90
91 // ---------- PRIVATE (PROHIBITED) METHODS ----------
92
93 LDOMParser (const LDOMParser& theOther);
94 // Copy constructor
95
96 LDOMParser& operator = (const LDOMParser& theOther);
97 // Assignment
98
99 private:
100 // ---------- PRIVATE FIELDS ----------
101
102 LDOM_XmlReader * myReader;
103 Handle(LDOM_MemManager) myDocument;
104 LDOM_OSStream myCurrentData;
105 TCollection_AsciiString myError;
106};
107
108#endif