Commit 34fabb83 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen Committed by Jean-Baptiste Kempf

dash: XML: handle text nodes.

Signed-off-by: default avatarJean-Baptiste Kempf <jb@videolan.org>
parent 8ceecb11
...@@ -74,24 +74,29 @@ Node* DOMParser::processNode () ...@@ -74,24 +74,29 @@ Node* DOMParser::processNode ()
{ {
const char *data; const char *data;
int type = xml_ReaderNextNode(this->vlc_reader, &data); int type = xml_ReaderNextNode(this->vlc_reader, &data);
if(type != -1 && type != XML_READER_TEXT && type != XML_READER_NONE && type != XML_READER_ENDELEM) if(type != -1 && type != XML_READER_NONE && type != XML_READER_ENDELEM)
{ {
Node *node = new Node(); Node *node = new Node();
node->setType( type );
std::string name = data; if ( type != XML_READER_TEXT )
bool isEmpty = xml_ReaderIsEmptyElement(this->vlc_reader); {
node->setName(name); std::string name = data;
bool isEmpty = xml_ReaderIsEmptyElement(this->vlc_reader);
node->setName(name);
this->addAttributesToNode(node); this->addAttributesToNode(node);
if(isEmpty) if(isEmpty)
return node; return node;
Node *subnode = NULL; Node *subnode = NULL;
while((subnode = this->processNode()) != NULL)
node->addSubNode(subnode);
while((subnode = this->processNode()) != NULL)
node->addSubNode(subnode);
}
else
node->setText( data );
return node; return node;
} }
return NULL; return NULL;
......
...@@ -27,11 +27,16 @@ ...@@ -27,11 +27,16 @@
#include "Node.h" #include "Node.h"
#include <cassert>
#include <vlc_common.h>
#include <vlc_xml.h>
using namespace dash::xml; using namespace dash::xml;
const std::string Node::EmptyString = ""; const std::string Node::EmptyString = "";
Node::Node () Node::Node() :
type( -1 )
{ {
} }
Node::~Node () Node::~Node ()
...@@ -89,9 +94,31 @@ bool Node::hasText () const ...@@ -89,9 +94,31 @@ bool Node::hasText () const
const std::string& Node::getText () const const std::string& Node::getText () const
{ {
return EmptyString; if ( this->type == XML_READER_TEXT )
return this->text;
else
{
assert( this->subNodes.size() == 1 );
return this->subNodes[0]->getText();
}
}
void Node::setText(const std::string &text)
{
this->text = text;
} }
const std::map<std::string,std::string>& Node::getAttributes () const const std::map<std::string,std::string>& Node::getAttributes () const
{ {
return this->attributes; return this->attributes;
} }
int Node::getType() const
{
return this->type;
}
void Node::setType(int type)
{
this->type = type;
}
...@@ -49,13 +49,18 @@ namespace dash ...@@ -49,13 +49,18 @@ namespace dash
std::vector<std::string> getAttributeKeys () const; std::vector<std::string> getAttributeKeys () const;
bool hasText () const; bool hasText () const;
const std::string& getText () const; const std::string& getText () const;
void setText( const std::string &text );
const std::map<std::string, std::string>& getAttributes () const; const std::map<std::string, std::string>& getAttributes () const;
int getType() const;
void setType( int type );
private: private:
static const std::string EmptyString; static const std::string EmptyString;
std::vector<Node *> subNodes; std::vector<Node *> subNodes;
std::map<std::string, std::string> attributes; std::map<std::string, std::string> attributes;
std::string name; std::string name;
std::string text;
int type;
}; };
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment