mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 06:06:10 -04:00
FeedReader:
- Changed compare of node names to case insensitive. More feeds should be supported now. - added ATOM format git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6056 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
35cc460e71
commit
c44d10a6a1
4 changed files with 120 additions and 29 deletions
|
@ -42,6 +42,24 @@ XMLWrapper::~XMLWrapper()
|
|||
xmlCharEncCloseFunc(mCharEncodingHandler);
|
||||
}
|
||||
|
||||
void XMLWrapper::trimString(std::string &string)
|
||||
{
|
||||
/* trim left */
|
||||
std::string::size_type find = string.find_first_not_of(" \t\r\n");
|
||||
if (find != std::string::npos) {
|
||||
string.erase(0, find);
|
||||
|
||||
/* trim right */
|
||||
find = string.find_last_not_of(" \t\r\n");
|
||||
if (find != std::string::npos) {
|
||||
string.erase(find + 1);
|
||||
}
|
||||
} else {
|
||||
string.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
XMLWrapper &XMLWrapper::operator=(const XMLWrapper &xml)
|
||||
{
|
||||
cleanup();
|
||||
|
@ -124,7 +142,7 @@ bool XMLWrapper::readXML(const char *xml)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool XMLWrapper::getContent(xmlNodePtr node, std::string &content)
|
||||
bool XMLWrapper::getContent(xmlNodePtr node, std::string &content, bool trim)
|
||||
{
|
||||
content.clear();
|
||||
|
||||
|
@ -140,6 +158,10 @@ bool XMLWrapper::getContent(xmlNodePtr node, std::string &content)
|
|||
bool result = convertToString(xmlContent, content);
|
||||
xmlFree(xmlContent);
|
||||
|
||||
if (result && trim) {
|
||||
trimString(content);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -160,6 +182,41 @@ bool XMLWrapper::setContent(xmlNodePtr node, const char *content)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool XMLWrapper::nodeDump(xmlNodePtr node, std::string &content, bool trim)
|
||||
{
|
||||
content.clear();
|
||||
|
||||
if (!mDocument) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!node) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool result = false;
|
||||
|
||||
xmlBufferPtr buffer = xmlBufferCreate();
|
||||
if (buffer) {
|
||||
xmlOutputBufferPtr outputBuffer = xmlOutputBufferCreateBuffer(buffer, NULL);
|
||||
if (outputBuffer) {
|
||||
xmlNodeDumpOutput(outputBuffer, mDocument, node, 0, 0, "UTF8");
|
||||
xmlOutputBufferClose(outputBuffer);
|
||||
outputBuffer = NULL;
|
||||
|
||||
result = convertToString(buffer->content, content);
|
||||
|
||||
if (result && trim) {
|
||||
trimString(content);
|
||||
}
|
||||
}
|
||||
xmlBufferFree(buffer);
|
||||
buffer = NULL;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string XMLWrapper::nodeName(xmlNodePtr node)
|
||||
{
|
||||
std::string name;
|
||||
|
@ -229,6 +286,16 @@ bool XMLWrapper::getChildText(xmlNodePtr node, const char *childName, std::strin
|
|||
return false;
|
||||
}
|
||||
|
||||
if (getAttr(child, "type") == "xhtml") {
|
||||
/* search div */
|
||||
xmlNodePtr div = findNode(child->children, "div", false);
|
||||
if (!div) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return nodeDump(div, text, true);
|
||||
}
|
||||
|
||||
if (child->children->type != XML_TEXT_NODE) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -33,6 +33,9 @@ public:
|
|||
XMLWrapper();
|
||||
~XMLWrapper();
|
||||
|
||||
// find better place
|
||||
static void trimString(std::string &string);
|
||||
|
||||
XMLWrapper &operator=(const XMLWrapper &xml);
|
||||
|
||||
void cleanup();
|
||||
|
@ -48,9 +51,11 @@ public:
|
|||
xmlNodePtr findNode(xmlNodePtr node, const char *name, bool children = false);
|
||||
bool getChildText(xmlNodePtr node, const char *childName, std::string &text);
|
||||
|
||||
bool getContent(xmlNodePtr node, std::string &content);
|
||||
bool getContent(xmlNodePtr node, std::string &content, bool trim);
|
||||
bool setContent(xmlNodePtr node, const char *content);
|
||||
|
||||
bool nodeDump(xmlNodePtr node, std::string &content, bool trim);
|
||||
|
||||
std::string getAttr(xmlNodePtr node, xmlAttrPtr attr);
|
||||
std::string getAttr(xmlNodePtr node, const char *name);
|
||||
bool setAttr(xmlNodePtr node, const char *name, const char *value);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue