/** * @file XTPMarkupParser.h * * @copyright * (c) 1998-2025 Codejock Software, All Rights Reserved. * * This source file is the property of Codejock Software and must not be * redistributed by any means without the explicit written permission of * Codejock Software. * * The use of this source code is governed by the terms and conditions specified * in the Toolkit Pro license agreement. Codejock Software grants you, as a * single software developer, the limited right to use this software on one * computer only. * * Contact Information: * support@codejock.com * http://www.codejock.com * */ /** @cond */ #if !defined(__XTPMARKUPPARSER_H__) # define __XTPMARKUPPARSER_H__ /** @endcond */ # if _MSC_VER > 1000 # pragma once # endif // _MSC_VER > 1000 # include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" /** @cond */ class CXTPComInitializer; # define XTP_MAX_TOKEN_SIZE 1024 # define XTP_MAX_NAME_SIZE 128 /** * @brief * Internal class used to parse XAML text to a Markup tree. */ class _XTP_EXT_CLASS CXTPMarkupParser { public: CXTPMarkupParser(); virtual ~CXTPMarkupParser(); public: /** * @brief * Sets ANSI XML data. * @param lpszStart Pointer to the first character of the sequence to parse. * @param lpszEnd Pointer to the next after the last character of the sequence to parse. * @return * TRUE if successful. */ BOOL SetBuffer(LPCSTR lpszStart, LPCSTR lpszEnd); /** * @brief * Sets Unicode XML data. * @param lpszStart Pointer to the first character of the sequence to parse. * @param lpszEnd Pointer to the next after the last character of the sequence to parse. * @return * TRUE if successful. */ BOOL SetBuffer(LPCWSTR lpszStart, LPCWSTR lpszEnd); /** * @brief * Reads XML data from a stream. * @param pStream Pointer to the stream to read XML data from. * @return * TRUE if successful. */ BOOL SetDataStream(IStream* pStream); /** * @brief * Provides access to the XML document instance. * @return * A valid pointer to the XML document instance, or an empty pointer * if no XML document instance is loaded. */ XTPXML::IXMLDOMDocumentPtr GetXmlDocument(); /** * @brief * Provides information about loading and parsing an XML error. */ struct ErrorInfo { HRESULT nCode; /**< Error code. */ BOOL bXml; /**< If TRUE, then the following fields contain valid values. */ long nLine; /**< Line number where an error occured. */ long nPosition; /**< Position in a line where an error occured. */ _bstr_t strReason; /**< Error description. */ _bstr_t strSource; /**< Source line where an error occured. */ }; /** * @brief * Provides access to error information. * @return * A reference to error information. */ const ErrorInfo& GetErrorInfo() const; /** * @brief * Formats a user friendly error message. * @return * A user friendly error message. */ CString FormatErrorMessage() const; /** * @brief * Formats a user friendly markup error message. * @return * A user friendly markup error message. */ CString FormatMarkupErrorMessage() const; private: struct MEMORY_BLOB { SIZE_T cbSize; LPCVOID pBlobData; }; BOOL CreateDataStream(LPCSTR lpString, SIZE_T cch, IStream** ppStream) const; BOOL CreateDataStream(LPCWSTR lpString, SIZE_T cch, IStream** ppStream) const; BOOL CreateDataStream(const MEMORY_BLOB* pBlobs, UINT nBlobs, IStream** ppStream) const; void ObtainComErrorInfo(HRESULT hr) const; void ObtainXmlErrorInfo(XTPXML::IXMLDOMDocument* pXmlDocument, HRESULT hr = S_OK); void ResetErrorInfo(); void ReleaseXml(); HGLOBAL ReadStreamData(IStream* pStream) const; LPWSTR ReadStreamDataAsUnicode(IStream* pStream, UINT* pchUnicodeText) const; // Backward compatibility tools. BOOL FixReferenceToUndeclaredNamespacePrefixX(IStream* pInputStream, IStream** ppOutputStream) const; BOOL FixRequiredWhiteSpaceWasMissing(IStream* pInputStream, IStream** ppOutputStream) const; private: CXTPComInitializer* m_pComInitializer; XTPXML::IXMLDOMDocumentPtr m_pXmlDocument; mutable ErrorInfo m_errorInfo; BOOL m_bInFixReferenceToUndeclaredNamespacePrefixX; static const BYTE UnicodeBOM[2]; }; AFX_INLINE const CXTPMarkupParser::ErrorInfo& CXTPMarkupParser::GetErrorInfo() const { return m_errorInfo; } AFX_INLINE XTPXML::IXMLDOMDocumentPtr CXTPMarkupParser::GetXmlDocument() { return m_pXmlDocument; } /** @endcond */ # include "Common/Base/Diagnostic/XTPEnableNoisyWarnings.h" /** @cond */ #endif // !defined(__XTPMARKUPPARSER_H__) /** @endcond */