diff options
Diffstat (limited to 'include/assimp/XmlParser.h')
-rw-r--r-- | include/assimp/XmlParser.h | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/include/assimp/XmlParser.h b/include/assimp/XmlParser.h index 800d2e993..ac047cb98 100644 --- a/include/assimp/XmlParser.h +++ b/include/assimp/XmlParser.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2024, assimp team +Copyright (c) 2006-2025, assimp team All rights reserved. @@ -50,6 +50,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "IOStream.hpp" #include <pugixml.hpp> +#include <istream> #include <utility> #include <vector> @@ -128,6 +129,11 @@ public: /// @return true, if the parsing was successful, false if not. bool parse(IOStream *stream); + /// @brief Will parse an xml-file from a stringstream. + /// @param[in] str The input istream (note: not "const" to match pugixml param) + /// @return true, if the parsing was successful, false if not. + bool parse(std::istream &inStream); + /// @brief Will return true if a root node is there. /// @return true in case of an existing root. bool hasRoot() const; @@ -311,7 +317,23 @@ bool TXmlParser<TNodeType>::parse(IOStream *stream) { mDoc = new pugi::xml_document(); // load_string assumes native encoding (aka always utf-8 per build options) //pugi::xml_parse_result parse_result = mDoc->load_string(&mData[0], pugi::parse_full); - pugi::xml_parse_result parse_result = mDoc->load_buffer(&mData[0], mData.size(), pugi::parse_full); + pugi::xml_parse_result parse_result = mDoc->load_buffer(&mData[0], mData.size(), pugi::parse_full); + if (parse_result.status == pugi::status_ok) { + return true; + } + + ASSIMP_LOG_DEBUG("Error while parse xml.", std::string(parse_result.description()), " @ ", parse_result.offset); + + return false; +} + +template <class TNodeType> +bool TXmlParser<TNodeType>::parse(std::istream &inStream) { + if (hasRoot()) { + clear(); + } + mDoc = new pugi::xml_document(); + pugi::xml_parse_result parse_result = mDoc->load(inStream); if (parse_result.status == pugi::status_ok) { return true; } |