X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=XMLDocShredder.cpp;h=d2e4a7503c105115d093d863344b1e6584c4ef5c;hb=6c60812f1f494f273d6074fcccf2707a6097cfaa;hp=3daaf45dfbbcdc4a53cef508465a013e42d1d29f;hpb=9be0c0e2a5597148fdc3a3cca2bdaf69da0aa27d;p=SXSI%2Fxpathcomp.git diff --git a/XMLDocShredder.cpp b/XMLDocShredder.cpp index 3daaf45..d2e4a75 100644 --- a/XMLDocShredder.cpp +++ b/XMLDocShredder.cpp @@ -59,6 +59,7 @@ XMLDocShredder::XMLDocShredder(const unsigned char * data, reader_ = new TextReader(data,size,""); setProperties(); storageIfc_ = new SXSIStorageInterface(); + buffer = ""; } XMLDocShredder::XMLDocShredder(const string inFileName) @@ -67,7 +68,7 @@ XMLDocShredder::XMLDocShredder(const string inFileName) reader_ = new TextReader(inFileName); setProperties(); storageIfc_ = new SXSIStorageInterface(); - + buffer = ""; } XMLDocShredder::~XMLDocShredder() @@ -84,10 +85,9 @@ void XMLDocShredder::processStartElement() ustring name = reader_->get_name(); bool empty = false; - if (!last_text) - storageIfc_->newText(""); //prevText - last_text = false; - + storageIfc_->newText(buffer); //prevText + buffer.erase(); + storageIfc_->newChild(name); /* We must be really carefull here. calling process attributes moves @@ -110,17 +110,13 @@ void XMLDocShredder::processStartElement() }; - - - } void XMLDocShredder::processEndElement() { // 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_->newText(buffer); //prevText + buffer.erase(); storageIfc_->nodeFinished(reader_->get_name()); } @@ -129,19 +125,18 @@ void XMLDocShredder::processPCDATA() // send the content of this PCDATA node to the storage interface as a text node if (reader_->has_value()) - { - storageIfc_->newText(reader_->get_value()); - last_text = true; - } - else - storageIfc_->newText(""); + { + buffer += reader_->get_value(); + }; + } void XMLDocShredder::processAttributes() { reader_->move_to_first_attribute(); - string nspaceStr = "xmlns"; + string nspaceStr = "xmlns"; + storageIfc_->newText(""); //prevText storageIfc_->newChild("<@>"); do { @@ -178,9 +173,8 @@ void XMLDocShredder::processAttributes() void XMLDocShredder::processSignificantWhitespace() { - ustring value = reader_->get_value(); - // each significant whitespace sequence constructs a text node - storageIfc_->newText(value); + // each significant whitespace sequence constructs a text node + buffer += reader_->get_value(); }