diff --git a/src/LDOM/LDOMParser.cxx b/src/LDOM/LDOMParser.cxx index 341d902067..adf8d9b883 100644 --- a/src/LDOM/LDOMParser.cxx +++ b/src/LDOM/LDOMParser.cxx @@ -55,13 +55,14 @@ inline #endif LDOM_XmlReader::RecordType ReadRecord (LDOM_XmlReader& aReader, Standard_IStream& theIStream, - LDOM_OSStream& aData) + LDOM_OSStream& aData, + Standard_Boolean& theDocStart) { #ifdef LDOM_PARSER_TRACE static aCounter = 0; ++ aCounter; #endif - const LDOM_XmlReader::RecordType aType = aReader.ReadRecord (theIStream, aData); + const LDOM_XmlReader::RecordType aType = aReader.ReadRecord (theIStream, aData, theDocStart); #ifdef LDOM_PARSER_TRACE static FILE * ff = NULL; TCollection_AsciiString aTraceFileName; @@ -172,11 +173,13 @@ Standard_Boolean LDOMParser::ParseDocument (std::istream& theIStream, const Stan Standard_Boolean isDoctype = Standard_False; Standard_Boolean isInsertFictRootElement = Standard_False; + Standard_Boolean aDocStart = Standard_True; + for(;;) { LDOM_XmlReader::RecordType aType = (theWithoutRoot && !isInsertFictRootElement ? LDOM_XmlReader::XML_START_ELEMENT : - ReadRecord (*myReader, theIStream, myCurrentData)); + ReadRecord (*myReader, theIStream, myCurrentData, aDocStart)); switch (aType) { case LDOM_XmlReader::XML_HEADER: if (isDoctype || isElement) { @@ -234,7 +237,7 @@ Standard_Boolean LDOMParser::ParseDocument (std::istream& theIStream, const Stan myError = "User abort at startElement()"; break; } - isError = ParseElement (theIStream); + isError = ParseElement (theIStream, aDocStart); if (isError) break; continue; } @@ -266,7 +269,7 @@ Standard_Boolean LDOMParser::ParseDocument (std::istream& theIStream, const Stan //purpose : parse one element, given the type of its XML presentation //======================================================================= -Standard_Boolean LDOMParser::ParseElement (Standard_IStream& theIStream) +Standard_Boolean LDOMParser::ParseElement (Standard_IStream& theIStream, Standard_Boolean& theDocStart) { Standard_Boolean isError = Standard_False; const LDOM_BasicElement * aParent = &myReader->GetElement(); @@ -275,7 +278,7 @@ Standard_Boolean LDOMParser::ParseElement (Standard_IStream& theIStream) LDOM_Node::NodeType aLocType; LDOMBasicString aTextValue; char *aTextStr; - LDOM_XmlReader::RecordType aType = ReadRecord (* myReader, theIStream, myCurrentData); + LDOM_XmlReader::RecordType aType = ReadRecord (* myReader, theIStream, myCurrentData, theDocStart); switch (aType) { case LDOM_XmlReader::XML_UNKNOWN: isError = Standard_True; @@ -300,7 +303,7 @@ Standard_Boolean LDOMParser::ParseElement (Standard_IStream& theIStream) myError = "User abort at startElement()"; break; } - isError = ParseElement (theIStream); + isError = ParseElement (theIStream, theDocStart); break; case LDOM_XmlReader::XML_END_ELEMENT: { diff --git a/src/LDOM/LDOMParser.hxx b/src/LDOM/LDOMParser.hxx index d064e5d019..fbcf560b2a 100644 --- a/src/LDOM/LDOMParser.hxx +++ b/src/LDOM/LDOMParser.hxx @@ -86,7 +86,7 @@ class LDOMParser // ---------- PRIVATE METHODS ---------- Standard_Boolean ParseDocument (Standard_IStream& theIStream, const Standard_Boolean theWithoutRoot = Standard_False); - Standard_Boolean ParseElement (Standard_IStream& theIStream); + Standard_Boolean ParseElement (Standard_IStream& theIStream, Standard_Boolean& theDocStart); // ---------- PRIVATE (PROHIBITED) METHODS ---------- diff --git a/src/LDOM/LDOM_XmlReader.cxx b/src/LDOM/LDOM_XmlReader.cxx index a72e9fc0c7..17c15c90a3 100644 --- a/src/LDOM/LDOM_XmlReader.cxx +++ b/src/LDOM/LDOM_XmlReader.cxx @@ -84,7 +84,8 @@ LDOM_XmlReader::LDOM_XmlReader ( //======================================================================= LDOM_XmlReader::RecordType LDOM_XmlReader::ReadRecord (Standard_IStream& theIStream, - LDOM_OSStream& theData) + LDOM_OSStream& theData, + Standard_Boolean& theDocStart) { theData.Clear(); myError.Clear(); @@ -93,7 +94,6 @@ LDOM_XmlReader::RecordType LDOM_XmlReader::ReadRecord (Standard_IStream& theIStr LDOMBasicString anAttrName, anAttrValue; char anAttDelimiter = '\0'; Standard_Boolean aHasRead = Standard_False; - Standard_Boolean isFileStart = !myEOF && theIStream.tellg() == std::iostream::pos_type(0); for(;;) { // Check if the current file buffer is exhausted @@ -155,9 +155,9 @@ LDOM_XmlReader::RecordType LDOM_XmlReader::ReadRecord (Standard_IStream& theIStr myBuffer[aBytesRest + aNBytes] = '\0'; } } - if (isFileStart) + if (theDocStart && !myEOF) { - isFileStart = Standard_False; + theDocStart = Standard_False; // check for BOM block Standard_Utf8UChar aFirstChar = Standard_Utf8UChar(myPtr[0]); switch(aFirstChar) { diff --git a/src/LDOM/LDOM_XmlReader.hxx b/src/LDOM/LDOM_XmlReader.hxx index cc8965ffd0..9703f025fa 100644 --- a/src/LDOM/LDOM_XmlReader.hxx +++ b/src/LDOM/LDOM_XmlReader.hxx @@ -53,17 +53,19 @@ class LDOM_XmlReader // Constructor - takes a file descriptor for input // Constructor - takes an std::istream for input - RecordType ReadRecord (Standard_IStream& theIStream, LDOM_OSStream& theData); + RecordType ReadRecord (Standard_IStream& theIStream, + LDOM_OSStream& theData, + Standard_Boolean& theDocStart); // reading a markup or other element of XML format - LDOM_BasicElement& GetElement () const { return * myElement; } + LDOM_BasicElement& GetElement() const { return * myElement; } // get the last element retrieved from the stream void CreateElement (const char *theName, const Standard_Integer theLen); - static Standard_Boolean getInteger (LDOMBasicString& theValue, - const char * theStart, - const char * theEnd); + static Standard_Boolean getInteger (LDOMBasicString& theValue, + const char * theStart, + const char * theEnd); // try convert string theStart to LDOM_AsciiInteger, return False on success // Returns the byte order mask defined at the start of a stream