Skip to content

Commit 6f26ab8

Browse files
committed
xrCore/XML/XMLDocument: ability to directly set the XML
1 parent 56647fa commit 6f26ab8

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/xrCore/XML/XMLDocument.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,27 @@ bool XMLDocument::Load(pcstr path, pcstr xml_filename, bool fatal)
8787
W.w_stringZ("");
8888
FS.r_close(F);
8989

90-
m_Doc.parse(reinterpret_cast<pcstr>(W.pointer()));
90+
return Set(reinterpret_cast<pcstr>(W.pointer()));
91+
}
92+
93+
// XXX: support #include directive
94+
bool XMLDocument::Set(pcstr text, bool fatal)
95+
{
96+
R_ASSERT(text != nullptr);
97+
m_Doc.parse(text);
9198

9299
if (m_Doc.isError())
93100
{
94101
string1024 str;
95-
xr_sprintf(str, "XML Error! File: %s Description: %s:%u", m_xml_file_name, m_Doc.error(), m_Doc.errorOffset());
96-
char* offsetted = (char*)W.pointer() + m_Doc.errorOffset();
97-
R_ASSERT3(false, str, offsetted ? offsetted : "wrong offset");
102+
xr_sprintf(str, "XML Error! File: %s Description: %s:%u \n", m_xml_file_name, m_Doc.error(), m_Doc.errorOffset());
103+
pcstr offsetted = text + m_Doc.errorOffset();
104+
105+
if (fatal)
106+
R_ASSERT3(false, str, offsetted);
107+
else
108+
Log(str, offsetted);
109+
110+
return false;
98111
}
99112

100113
m_root = m_Doc.firstChildElement();

src/xrCore/XML/XMLDocument.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ class XRCORE_API XMLDocument
138138
bool Load(pcstr path_alias, pcstr path, pcstr xml_filename, bool fatal = true);
139139
bool Load(pcstr path_alias, pcstr path, pcstr path2, pcstr xml_filename, bool fatal = true);
140140

141+
// Set XML directly. Doesn't support #include directive
142+
bool Set(pcstr text, bool fatal = true);
143+
141144
//чтение элементов
142145
pcstr Read(pcstr path, const size_t index, pcstr default_str_val) const;
143146
pcstr Read(XML_NODE start_node, pcstr path, const size_t index, pcstr default_str_val) const;

0 commit comments

Comments
 (0)