[vlc-commits] dash: XML: handle text nodes.

Hugo Beauzée-Luyssen git at videolan.org
Tue Jan 24 23:21:54 CET 2012


vlc/vlc-1.2 | branch: master | Hugo Beauzée-Luyssen <beauze.h at gmail.com> | Sun Dec 25 00:51:52 2011 +0100| [f36d6273bf67f2da64888e846102b095d2d8a443] | committer: Jean-Baptiste Kempf

dash: XML: handle text nodes.

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
(cherry picked from commit 34fabb830ca5fcb4dfc39c39691a41715e72ab0e)

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc/vlc-1.2.git/?a=commit;h=f36d6273bf67f2da64888e846102b095d2d8a443
---

 modules/stream_filter/dash/xml/DOMParser.cpp |   27 +++++++++++++---------
 modules/stream_filter/dash/xml/Node.cpp      |   31 ++++++++++++++++++++++++-
 modules/stream_filter/dash/xml/Node.h        |    5 ++++
 3 files changed, 50 insertions(+), 13 deletions(-)

diff --git a/modules/stream_filter/dash/xml/DOMParser.cpp b/modules/stream_filter/dash/xml/DOMParser.cpp
index 4736fba..ab562f3 100644
--- a/modules/stream_filter/dash/xml/DOMParser.cpp
+++ b/modules/stream_filter/dash/xml/DOMParser.cpp
@@ -74,24 +74,29 @@ Node*   DOMParser::processNode              ()
 {
     const char *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->setType( type );
 
-        std::string name    = data;
-        bool        isEmpty = xml_ReaderIsEmptyElement(this->vlc_reader);
-        node->setName(name);
+        if ( type != XML_READER_TEXT )
+        {
+            std::string name    = data;
+            bool        isEmpty = xml_ReaderIsEmptyElement(this->vlc_reader);
+            node->setName(name);
 
-        this->addAttributesToNode(node);
+            this->addAttributesToNode(node);
 
-        if(isEmpty)
-            return node;
+            if(isEmpty)
+                return node;
 
-        Node *subnode = NULL;
-
-        while((subnode = this->processNode()) != NULL)
-            node->addSubNode(subnode);
+            Node *subnode = NULL;
 
+            while((subnode = this->processNode()) != NULL)
+                node->addSubNode(subnode);
+        }
+        else
+            node->setText( data );
         return node;
     }
     return NULL;
diff --git a/modules/stream_filter/dash/xml/Node.cpp b/modules/stream_filter/dash/xml/Node.cpp
index fe8c4ca..8e90e7e 100644
--- a/modules/stream_filter/dash/xml/Node.cpp
+++ b/modules/stream_filter/dash/xml/Node.cpp
@@ -27,11 +27,16 @@
 
 #include "Node.h"
 
+#include <cassert>
+#include <vlc_common.h>
+#include <vlc_xml.h>
+
 using namespace dash::xml;
 
 const std::string   Node::EmptyString = "";
 
-Node::Node  ()
+Node::Node() :
+    type( -1 )
 {
 }
 Node::~Node ()
@@ -89,9 +94,31 @@ bool                                Node::hasText               () 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
 {
     return this->attributes;
 }
+
+int Node::getType() const
+{
+    return this->type;
+}
+
+void Node::setType(int type)
+{
+    this->type = type;
+}
diff --git a/modules/stream_filter/dash/xml/Node.h b/modules/stream_filter/dash/xml/Node.h
index e4973a5..f11662f 100644
--- a/modules/stream_filter/dash/xml/Node.h
+++ b/modules/stream_filter/dash/xml/Node.h
@@ -49,13 +49,18 @@ namespace dash
                 std::vector<std::string>            getAttributeKeys    () const;
                 bool                                hasText             () const;
                 const std::string&                  getText             () const;
+                void                                setText( const std::string &text );
                 const std::map<std::string, std::string>& getAttributes () const;
+                int                                 getType() const;
+                void                                setType( int type );
 
             private:
                 static const std::string            EmptyString;
                 std::vector<Node *>                 subNodes;
                 std::map<std::string, std::string>  attributes;
                 std::string                         name;
+                std::string                         text;
+                int                                 type;
 
         };
     }



More information about the vlc-commits mailing list