Commit 53beda0a authored by Francois Cartegnie's avatar Francois Cartegnie

demux: dash: fix and debug DOM Parsing

parent 98df0fd9
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "../Helper.h" #include "../Helper.h"
#include <vector> #include <vector>
#include <stack>
#include <vlc_xml.h> #include <vlc_xml.h>
#include <vlc_stream.h> #include <vlc_stream.h>
...@@ -68,43 +69,74 @@ bool DOMParser::parse () ...@@ -68,43 +69,74 @@ bool DOMParser::parse ()
if(!this->vlc_reader) if(!this->vlc_reader)
return false; return false;
this->root = this->processNode(); root = processNode();
if ( this->root == NULL ) if ( root == NULL )
return false; return false;
return true; return true;
} }
Node* DOMParser::processNode ()
Node* DOMParser::processNode()
{ {
const char *data; const char *data;
int type = xml_ReaderNextNode(this->vlc_reader, &data); int type;
if(type != -1 && type != XML_READER_NONE && type != XML_READER_ENDELEM) std::stack<Node *> lifo;
{
Node *node = new Node();
node->setType( type );
if ( type != XML_READER_TEXT ) while( (type = xml_ReaderNextNode(vlc_reader, &data)) > 0 )
{
switch(type)
{ {
std::string name = data; case XML_READER_STARTELEM:
bool isEmpty = xml_ReaderIsEmptyElement(this->vlc_reader); {
node->setName(name); bool empty = xml_ReaderIsEmptyElement(vlc_reader);
Node *node = new (std::nothrow) Node();
this->addAttributesToNode(node); if(node)
{
if(!lifo.empty())
lifo.top()->addSubNode(node);
lifo.push(node);
node->setName(std::string(data));
addAttributesToNode(node);
}
if(empty)
lifo.pop();
break;
}
case XML_READER_TEXT:
{
if(!lifo.empty())
lifo.top()->setText(std::string(data));
break;
}
case XML_READER_ENDELEM:
{
if(lifo.empty())
return NULL;
Node *node = lifo.top();
lifo.pop();
if(lifo.empty())
return node;
}
default:
break;
}
}
if(isEmpty) while( lifo.size() > 1 )
return node; lifo.pop();
Node *subnode = NULL; if(!lifo.empty())
delete lifo.top();
while((subnode = this->processNode()) != NULL)
node->addSubNode(subnode);
}
else
node->setText( data );
return node;
}
return NULL; return NULL;
} }
void DOMParser::addAttributesToNode (Node *node) void DOMParser::addAttributesToNode (Node *node)
{ {
const char *attrValue; const char *attrValue;
......
...@@ -94,20 +94,9 @@ std::vector<std::string> Node::getAttributeKeys () const ...@@ -94,20 +94,9 @@ std::vector<std::string> Node::getAttributeKeys () const
return keys; return keys;
} }
bool Node::hasText () const
{
return false;
}
const std::string& Node::getText () const const std::string& Node::getText () const
{ {
if ( this->type == XML_READER_TEXT ) return text;
return this->text;
else
{
assert( this->subNodes.size() == 1 );
return this->subNodes[0]->getText();
}
} }
void Node::setText(const std::string &text) void Node::setText(const std::string &text)
...@@ -129,3 +118,18 @@ void Node::setType(int type) ...@@ -129,3 +118,18 @@ void Node::setType(int type)
{ {
this->type = type; this->type = type;
} }
std::vector<std::string> Node::toString(int indent) const
{
std::vector<std::string> ret;
std::string text(indent, ' ');
text.append(getName());
ret.push_back(text);
std::vector<Node *>::const_iterator l;
for(l = subNodes.begin(); l < subNodes.end(); l++)
{
std::vector<std::string> sub = (*l)->toString(indent + 1);
ret.insert(ret.end(), sub.begin(), sub.end());
}
return ret;
}
...@@ -48,12 +48,12 @@ namespace dash ...@@ -48,12 +48,12 @@ namespace dash
void addAttribute (const std::string& key, const std::string& value); void addAttribute (const std::string& key, const std::string& value);
const std::string& getAttributeValue (const std::string& key) const; const std::string& getAttributeValue (const std::string& key) const;
std::vector<std::string> getAttributeKeys () const; std::vector<std::string> getAttributeKeys () const;
bool hasText () const;
const std::string& getText () const; const std::string& getText () const;
void setText( const std::string &text ); 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; int getType() const;
void setType( int type ); void setType( int type );
std::vector<std::string> toString(int) const;
private: private:
static const std::string EmptyString; static const std::string EmptyString;
......
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