From 4021aa231eba31a0d925e4d7c9013d44ccf79f30 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 27 Mar 2013 13:18:30 +0000 Subject: 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 --- src/modules/xml/xmlApi.cpp | 20 ++++++++++++++++++++ src/modules/xml/xmlParser.h | 28 ---------------------------- 2 files changed, 20 insertions(+), 28 deletions(-) (limited to 'src') 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 { -- cgit v1.2.3