MaterialX 1.39.1
Loading...
Searching...
No Matches
XmlIo.h
Go to the documentation of this file.
1//
2// Copyright Contributors to the MaterialX Project
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#ifndef MATERIALX_XMLIO_H
7#define MATERIALX_XMLIO_H
8
11
13
15
18
19MATERIALX_NAMESPACE_BEGIN
20
21class XmlReadOptions;
22
23extern MX_FORMAT_API const string MTLX_EXTENSION;
24
27using XmlReadFunction = std::function<void(DocumentPtr, const FilePath&, const FileSearchPath&, const XmlReadOptions*)>;
28
31class MX_FORMAT_API XmlReadOptions
32{
33 public:
35 ~XmlReadOptions() { }
36
40
44
48
52
56};
57
60class MX_FORMAT_API XmlWriteOptions
61{
62 public:
65
69
73};
74
77class MX_FORMAT_API ExceptionParseError : public Exception
78{
79 public:
80 using Exception::Exception;
81};
82
85class MX_FORMAT_API ExceptionFileMissing : public Exception
86{
87 public:
88 using Exception::Exception;
89};
90
93
105MX_FORMAT_API void readFromXmlBuffer(DocumentPtr doc, const char* buffer, FileSearchPath searchPath = FileSearchPath(), const XmlReadOptions* readOptions = nullptr);
106
118MX_FORMAT_API void readFromXmlStream(DocumentPtr doc, std::istream& stream, FileSearchPath searchPath = FileSearchPath(), const XmlReadOptions* readOptions = nullptr);
119
133MX_FORMAT_API void readFromXmlFile(DocumentPtr doc,
134 FilePath filename,
135 FileSearchPath searchPath = FileSearchPath(),
136 const XmlReadOptions* readOptions = nullptr);
137
149MX_FORMAT_API void readFromXmlString(DocumentPtr doc, const string& str, const FileSearchPath& searchPath = FileSearchPath(), const XmlReadOptions* readOptions = nullptr);
150
154
161MX_FORMAT_API void writeToXmlStream(DocumentPtr doc, std::ostream& stream, const XmlWriteOptions* writeOptions = nullptr);
162
170MX_FORMAT_API void writeToXmlFile(DocumentPtr doc, const FilePath& filename, const XmlWriteOptions* writeOptions = nullptr);
171
178MX_FORMAT_API string writeToXmlString(DocumentPtr doc, const XmlWriteOptions* writeOptions = nullptr);
179
183
188MX_FORMAT_API void prependXInclude(DocumentPtr doc, const FilePath& filename);
189
191
192MATERIALX_NAMESPACE_END
193
194#endif
The top-level Document class.
shared_ptr< Document > DocumentPtr
A shared pointer to a Document.
Definition: Document.h:22
std::function< bool(ConstElementPtr)> ElementPredicate
A standard function taking an ElementPtr and returning a boolean.
Definition: Element.h:72
Cross-platform support for file and search paths.
Library-wide includes and types.
vector< string > StringVec
A vector of strings.
Definition: Library.h:55
Macros for declaring imported and exported symbols.
std::function< void(DocumentPtr, const FilePath &, const FileSearchPath &, const XmlReadOptions *)> XmlReadFunction
A standard function that reads from an XML file into a Document, with optional search path and read o...
Definition: XmlIo.h:27
MX_FORMAT_API void readFromXmlStream(DocumentPtr doc, std::istream &stream, FileSearchPath searchPath=FileSearchPath(), const XmlReadOptions *readOptions=nullptr)
Read a Document as XML from the given input stream.
MX_FORMAT_API void readFromXmlBuffer(DocumentPtr doc, const char *buffer, FileSearchPath searchPath=FileSearchPath(), const XmlReadOptions *readOptions=nullptr)
Read a Document as XML from the given character buffer.
MX_FORMAT_API void writeToXmlFile(DocumentPtr doc, const FilePath &filename, const XmlWriteOptions *writeOptions=nullptr)
Write a Document as XML to the given filename.
MX_FORMAT_API void readFromXmlFile(DocumentPtr doc, FilePath filename, FileSearchPath searchPath=FileSearchPath(), const XmlReadOptions *readOptions=nullptr)
Read a Document as XML from the given filename.
MX_FORMAT_API void prependXInclude(DocumentPtr doc, const FilePath &filename)
Add an XInclude reference to the top of a Document, creating a generic element to hold the reference ...
MX_FORMAT_API string writeToXmlString(DocumentPtr doc, const XmlWriteOptions *writeOptions=nullptr)
Write a Document as XML to a new string, returned by value.
MX_FORMAT_API void writeToXmlStream(DocumentPtr doc, std::ostream &stream, const XmlWriteOptions *writeOptions=nullptr)
Write a Document as XML to the given output stream.
MX_FORMAT_API void readFromXmlString(DocumentPtr doc, const string &str, const FileSearchPath &searchPath=FileSearchPath(), const XmlReadOptions *readOptions=nullptr)
Read a Document as XML from the given string.
An exception that is thrown when a requested file cannot be opened.
Definition: XmlIo.h:86
The base class for exceptions that are propagated from the MaterialX library to the client applicatio...
Definition: Exception.h:22
An exception that is thrown when a requested document cannot be parsed.
Definition: XmlIo.h:78
A generic file path, supporting both syntactic and file system operations.
Definition: File.h:27
A sequence of file paths, which may be queried to find the first instance of a given filename on the ...
Definition: File.h:219
A set of options for controlling the behavior of XML read functions.
Definition: XmlIo.h:32
bool readNewlines
If true, then XML newlines will be read into documents as newline elements.
Definition: XmlIo.h:43
bool readComments
If true, then XML comments will be read into documents as comment elements.
Definition: XmlIo.h:39
StringVec parentXIncludes
The vector of parent XIncludes at the scope of the current document.
Definition: XmlIo.h:55
XmlReadFunction readXIncludeFunction
If provided, this function will be invoked when an XInclude reference needs to be read into a documen...
Definition: XmlIo.h:51
bool upgradeVersion
If true, then documents from earlier versions of MaterialX will be upgraded to the current version.
Definition: XmlIo.h:47
A set of options for controlling the behavior of XML write functions.
Definition: XmlIo.h:61
bool writeXIncludeEnable
If true, elements with source file markings will be written as XIncludes rather than explicit data.
Definition: XmlIo.h:68
ElementPredicate elementPredicate
If provided, this function will be used to exclude specific elements (those returning false) from the...
Definition: XmlIo.h:72