summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/m_xml.h30
-rw-r--r--src/modules/xml/xmlApi.cpp20
-rw-r--r--src/modules/xml/xmlParser.h28
3 files changed, 50 insertions, 28 deletions
diff --git a/include/m_xml.h b/include/m_xml.h
index 24cb21bf4f..12c7bda369 100644
--- a/include/m_xml.h
+++ b/include/m_xml.h
@@ -39,6 +39,33 @@ typedef enum
}
XML_ELEMENT_TYPE;
+/// Enumeration for XML parse errors.
+typedef enum XMLError
+{
+ eXMLErrorNone = 0,
+ eXMLErrorMissingEndTag,
+ eXMLErrorNoXMLTagFound,
+ eXMLErrorEmpty,
+ eXMLErrorMissingTagName,
+ eXMLErrorMissingEndTagName,
+ eXMLErrorUnmatchedEndTag,
+ eXMLErrorUnmatchedEndClearTag,
+ eXMLErrorUnexpectedToken,
+ eXMLErrorNoElements,
+ eXMLErrorFileNotFound,
+ eXMLErrorFirstTagNotFound,
+ eXMLErrorUnknownCharacterEntity,
+ eXMLErrorCharacterCodeAbove255,
+ eXMLErrorCharConversionError,
+ eXMLErrorCannotOpenWriteFile,
+ eXMLErrorCannotWriteFile,
+
+ eXMLErrorBase64DataSizeIsNotMultipleOf4,
+ eXMLErrorBase64DecodeIllegalCharacter,
+ eXMLErrorBase64DecodeTruncatedData,
+ eXMLErrorBase64DecodeBufferTooSmall
+} XMLError;
+
typedef struct
{
size_t cbSize;
@@ -110,6 +137,9 @@ typedef struct
XML_ELEMENT_POS (*positionOfChildByName)(HXML, LPCTSTR name, int i);
XML_ELEMENT_POS (*positionOfText)(HXML, int i);
XML_ELEMENT_POS (*positionOfClear)(HXML, int i);
+
+ HXML (*parseFile)(LPCTSTR filename, int* datalen, LPCTSTR tag);
+ XMLError (*toFile)(HXML node, LPCTSTR filename);
}
XML_API;
diff --git a/src/modules/xml/xmlApi.cpp b/src/modules/xml/xmlApi.cpp
index 2335b7c6d7..113f2e9ecd 100644
--- a/src/modules/xml/xmlApi.cpp
+++ b/src/modules/xml/xmlApi.cpp
@@ -37,6 +37,19 @@ static void xmlapiDestroyNode(HXML n)
XMLNode tmp; tmp.attach(n);
}
+static HXML xmlapiParseFile(LPCTSTR str, int* datalen, LPCTSTR tag)
+{
+ if (str == NULL) return NULL;
+
+ XMLResults res;
+ XMLNode result = XMLNode::parseFile(str, tag, &res);
+
+ if (datalen != NULL)
+ datalen[0] += res.nChars;
+
+ return (res.error == eXMLErrorNone || (tag != NULL && res.error == eXMLErrorMissingEndTag)) ? result.detach() : NULL;
+}
+
static HXML xmlapiParseString(LPCTSTR str, int* datalen, LPCTSTR tag)
{
if (str == NULL) return NULL;
@@ -155,6 +168,11 @@ static LPTSTR xmlapiToString(HXML _n, int* datalen)
return XMLNode(_n).createXMLString(0, datalen);
}
+static XMLError xmlapiToFile(HXML _n, LPCTSTR filename)
+{
+ return XMLNode(_n).writeToFile(filename, NULL, NULL);
+}
+
static void xmlapiAddAttr(HXML _n, LPCTSTR attrName, LPCTSTR attrValue)
{
if (attrName != NULL && attrValue != NULL)
@@ -382,6 +400,8 @@ static INT_PTR GetXmlApi(WPARAM, LPARAM lParam)
xi->parseString = xmlapiParseString;
xi->toString = xmlapiToString;
xi->freeMem = xmlapiFree;
+ xi->parseFile = xmlapiParseFile;
+ xi->toFile = xmlapiToFile;
xi->addChild = xmlapiAddChild;
xi->addChild2 = xmlapiAddChild2;
diff --git a/src/modules/xml/xmlParser.h b/src/modules/xml/xmlParser.h
index 3820c93c12..546171324f 100644
--- a/src/modules/xml/xmlParser.h
+++ b/src/modules/xml/xmlParser.h
@@ -150,34 +150,6 @@
#define TRUE 1
#endif /* TRUE */
-/// Enumeration for XML parse errors.
-typedef enum XMLError
-{
- eXMLErrorNone = 0,
- eXMLErrorMissingEndTag,
- eXMLErrorNoXMLTagFound,
- eXMLErrorEmpty,
- eXMLErrorMissingTagName,
- eXMLErrorMissingEndTagName,
- eXMLErrorUnmatchedEndTag,
- eXMLErrorUnmatchedEndClearTag,
- eXMLErrorUnexpectedToken,
- eXMLErrorNoElements,
- eXMLErrorFileNotFound,
- eXMLErrorFirstTagNotFound,
- eXMLErrorUnknownCharacterEntity,
- eXMLErrorCharacterCodeAbove255,
- eXMLErrorCharConversionError,
- eXMLErrorCannotOpenWriteFile,
- eXMLErrorCannotWriteFile,
-
- eXMLErrorBase64DataSizeIsNotMultipleOf4,
- eXMLErrorBase64DecodeIllegalCharacter,
- eXMLErrorBase64DecodeTruncatedData,
- eXMLErrorBase64DecodeBufferTooSmall
-} XMLError;
-
-
/// Enumeration used to manage type of data. Use in conjunction with structure XMLNodeContents
typedef enum XMLElementType
{