diff options
author | George Hazan <george.hazan@gmail.com> | 2013-03-27 13:18:30 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2013-03-27 13:18:30 +0000 |
commit | 4021aa231eba31a0d925e4d7c9013d44ccf79f30 (patch) | |
tree | 029c5884634b2f0d1edf5e5737a28ef0207f8cfa /src/modules/xml | |
parent | f952f1e1441eadb162cf49d41b2ee4977f872971 (diff) |
XML API extended by two file operations: save to & read from file
git-svn-id: http://svn.miranda-ng.org/main/trunk@4217 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'src/modules/xml')
-rw-r--r-- | src/modules/xml/xmlApi.cpp | 20 | ||||
-rw-r--r-- | src/modules/xml/xmlParser.h | 28 |
2 files changed, 20 insertions, 28 deletions
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
{
|