#include <iostream>
#include "XMLDocShredder.h"
-#include "OCamlStorageInterface.h"
+#include "SXSIStorageInterface.h"
#include <libxml++/exceptions/parse_error.h>
#include "Utils.h"
XMLDocShredder::XMLDocShredder(const unsigned char * data,
TextReader::size_type size)
{
+ last_text = false;
reader_ = new TextReader(data,size,"");
setProperties();
- storageIfc_ = new OCamlStorageInterface();
- //tagsID_ = new unordered_map<int,string>(107);
- //idTags_ = new unordered_map<string,int>(107);
+ storageIfc_ = new SXSIStorageInterface();
}
XMLDocShredder::XMLDocShredder(const string inFileName)
{
+ last_text = false;
reader_ = new TextReader(inFileName);
setProperties();
- storageIfc_ = new OCamlStorageInterface();
- // tagsID_ = new unordered_map<int,string>(107);
- // idTags_ = new unordered_map<string,int>(107);
+ storageIfc_ = new SXSIStorageInterface();
+
}
XMLDocShredder::~XMLDocShredder()
}
-int XMLDocShredder::tagID(string name)
-{
- int res = tagsID_[name];
- return res;
-}
-string XMLDocShredder::idTag(int id)
-{
-
- return idTags_[id];
-}
-
void XMLDocShredder::processStartElement()
{
// fetch element name; this will be the full qualified name
ustring name = reader_->get_name();
bool empty = false;
+
+ if (!last_text)
+ storageIfc_->newText(""); //prevText
+ last_text = false;
storageIfc_->newChild(name);
if (empty){
- DPRINT("Node " << name <<" is empty!\n")
- storageIfc_->nodeFinished();
+ storageIfc_->newText(""); //myText
+ storageIfc_->nodeFinished(name);
};
void XMLDocShredder::processEndElement()
{
- // tell the storage interface that the current node has been completely processed
- storageIfc_->nodeFinished();
+ // tell the storage interface that the current node has been completely processed
+ if (!last_text)
+ storageIfc_->newText(""); //nextText of previous node
+ last_text = false;
+ storageIfc_->nodeFinished(reader_->get_name());
}
void XMLDocShredder::processPCDATA()
{
// send the content of this PCDATA node to the storage interface as a text node
+
if (reader_->has_value())
{
- storageIfc_->newChild("<$>");
storageIfc_->newText(reader_->get_value());
+ last_text = true;
}
+ else
+ storageIfc_->newText("");
}
void XMLDocShredder::processAttributes()
if ((name.find(nspaceStr.c_str(), 0, 5)) == 0)
{
storageIfc_->newChild(":" + value);
- storageIfc_->nodeFinished();
+ storageIfc_->nodeFinished(":" + value);
}
/* otherwise, this is an ordinary attribute, so we construct a new child node of the
else
{
- storageIfc_->newChild(name);
- storageIfc_->newChild("<$>");
- storageIfc_->newText(value);
- storageIfc_->nodeFinished();
- // storageIfc_->nodeFinished();
+ storageIfc_->newText(""); //prevText
+ storageIfc_->newChild(name);
+ storageIfc_->newText(value);
+ storageIfc_->nodeFinished(name);
}
}
while (reader_->move_to_next_attribute());
- storageIfc_->nodeFinished();
+ storageIfc_->newText(""); //nextText
+ storageIfc_->nodeFinished("<@>");
}
void XMLDocShredder::processSignificantWhitespace()
{
- ustring value = reader_->get_value();
-
+ ustring value = reader_->get_value();
// each significant whitespace sequence constructs a text node
- storageIfc_->newChild("<$>");
storageIfc_->newText(value);
- //storageIfc_->nodeFinished();
}
void XMLDocShredder::processStartDocument(const string docName)
{
// tell storage interface to construct the document name
- // storageIfc_->newChild("");
+ storageIfc_->newChild("");
+
}
void XMLDocShredder::processEndDocument()
{
/* tell the storage interface that document parsing has finished, and structures
* can now be written to disk. */
- // storageIfc_->nodeFinished();
+ storageIfc_->newText("");
+ storageIfc_->nodeFinished("");
storageIfc_->parsingFinished();
}
* model. Instead, we simply pass the converted text value to the storage interface as
* a text node attached to the current context node.
*/
+
ustring value = reader_->get_value();
- storageIfc_->newChild("<$>");
storageIfc_->newText(value);
- // storageIfc_->nodeFinished();
+ last_text = true;
}