0031340: LDOM fails to read XML file starting with BOM
[occt.git] / src / LDOM / LDOM_XmlReader.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// AGV 130302: bug corr: was error if strlen(root_elem_name) < 7
18
19#ifndef LDOM_XmlReader_HeaderFile
20#define LDOM_XmlReader_HeaderFile
21
22//#define XML_BUFFER_SIZE 1000
23#define XML_BUFFER_SIZE 20480
24
25#include <LDOM_BasicElement.hxx>
8f34d47e 26#include <LDOM_OSStream.hxx>
7fd59977 27
28class TCollection_AsciiString;
7fd59977 29
30// Class LDOM_XmlReader
31//
32
33class LDOM_XmlReader
34{
35 public:
36 enum RecordType {
37 XML_UNKNOWN,
38 XML_HEADER,
39 XML_DOCTYPE,
40 XML_COMMENT,
41 XML_START_ELEMENT,
42 XML_END_ELEMENT,
43 XML_FULL_ELEMENT,
44 XML_TEXT,
45 XML_CDATA,
46 XML_EOF
47 };
48
49 // ---------- PUBLIC METHODS ----------
4ff92abe 50 LDOM_XmlReader (const Handle(LDOM_MemManager)& aDocument,
5fce1605 51 TCollection_AsciiString& anErrorString,
52 const Standard_Boolean theTagPerStep = Standard_False);
7fd59977 53 // Constructor - takes a file descriptor for input
04232180 54 // Constructor - takes an std::istream for input
7fd59977 55
4ff92abe 56 RecordType ReadRecord (Standard_IStream& theIStream, LDOM_OSStream& theData);
7fd59977 57 // reading a markup or other element of XML format
58
59 LDOM_BasicElement& GetElement () const { return * myElement; }
60 // get the last element retrieved from the stream
61
5fce1605 62 void CreateElement (const char *theName, const Standard_Integer theLen);
63
7fd59977 64 static Standard_Boolean getInteger (LDOMBasicString& theValue,
65 const char * theStart,
66 const char * theEnd);
67 // try convert string theStart to LDOM_AsciiInteger, return False on success
68
8f34d47e 69 // Returns the byte order mask defined at the start of a stream
70 LDOM_OSStream::BOMType GetBOM() const { return myBOM; }
71
7fd59977 72 private:
73 // ---------- PRIVATE (PROHIBITED) METHODS ----------
74 LDOM_XmlReader (const LDOM_XmlReader& theOther);
75 // Copy constructor
76
77 LDOM_XmlReader& operator = (const LDOM_XmlReader& theOther);
78 // Assignment
79
80 private:
81 // ---------- PRIVATE FIELDS ----------
82
83 Standard_Boolean myEOF;
7fd59977 84 TCollection_AsciiString & myError;
85 Handle(LDOM_MemManager) myDocument;
86 LDOM_BasicElement * myElement;
87 const LDOM_BasicNode * myLastChild; // optim. reading attributes
88 const char * myPtr;
89 const char * myEndPtr;
90 char myBuffer [XML_BUFFER_SIZE+4];
5fce1605 91 Standard_Boolean myTagPerStep;
8f34d47e 92 LDOM_OSStream::BOMType myBOM;
7fd59977 93};
94
95#endif