Re: Error while parsing form istream



Thanks a lot for your help.
Reading the header file of the ZipArchiveEntry (https://bitbucket.org/wbenny/ziplib/src/176e4b6d51fc913fc7f7fb44df8f946374dc2c0c/Source/ZipLib/ZipArchiveEntry.h?at=master&fileviewer=file-view-default) this is the declaration:

 /**
     * \brief Gets decompression stream.
     *        If the file is encrypted and correct password is not provided, it returns nullptr.
     *
     * \return  null if it fails, else the decompression stream.
     */
    std::istream* GetDecompressionStream();

So adding "*" to my code works great. 
Thanks again.
Marco



On Thu, Aug 9, 2018 at 5:06 PM Kjell Ahlstedt <kjellahlstedt gmail com> wrote:

You don't show how decompressStream is declared. From the compiler output I guess it's
std::istream*
decompressStream;
i.e. a pointer to an std::istream. If that's true, the call to parse_stream() shall be
parser.parse_stream(*decompressStream);

If decompressStream is an std::istream (no pointer), the call shall be
parser.parse_stream(decompressStream);

Kjell

On 2018-08-09 10:37, Marco Olimpi via libxmlplusplus-list wrote:
Hi,
I'm new in C++ programming and I'm trying to create a little program the parse some xml inside a zip file. For the zip part I used the library https://bitbucket.org/wbenny/ziplib and for parsing the xml I want to use libxml++.

The problem is that I get this error with g++ that I realy don't understand:

src/zip/UnzipFile.cc: In member function ‘void Dopc::UnzipFile::open(const string&)’:
src/zip/UnzipFile.cc:50:54: error: no matching function for call to ‘xmlpp::DomParser::parse_stream(std::basic_istream<char>**)’
                 parser.parse_stream(&decompressStream);
                                                      ^
In file included from /usr/local/include/libxml++-3.0/libxml++/libxml++.h:54:0,
                 from src/zip/UnzipFile.cc:6:
/usr/local/include/libxml++-3.0/libxml++/parsers/domparser.h:75:8: note: candidate: virtual void xmlpp::DomParser::parse_stream(std::istream&)
   void parse_stream(std::istream& in) override;
        ^~~~~~~~~~~~
/usr/local/include/libxml++-3.0/libxml++/parsers/domparser.h:75:8: note:   no known conversion for argument 1 from ‘std::basic_istream<char>**’ to ‘std::istream& {aka std::basic_istream<char>&}’

This is the code of my program:

void UnzipFile::open(const string& p_fileName)
{
    ZipArchive::Ptr archive = ZipFile::Open(p_fileName);
    size_t entries = archive->GetEntriesCount();

    printf("[o] Listing archive (comment: '%s'):\n", archive->GetComment().c_str());
    printf("[o] Entries count: %lu\n", entries);

    for (size_t i = 0; i < entries; ++i)
    {
        auto entry = archive->GetEntry(int(i));

        if (entry->GetFullName() == "[Content_Types].xml")
        {
            auto decompressStream = entry->GetDecompressionStream();  
            printf("[o] -- %s\n", "File XML decompress");    

            try{
               
                xmlpp::DomParser parser;
                parser.set_validate();
                parser.parse_stream(&decompressStream);
                if (parser)
                {
                    const auto pNode = parser.get_document()->get_root_node();
                    cout << "XML READ SUCCESS" << endl;
                }
               
            } catch (const std::exception& ex){
                cerr << "Exception caught: " << ex.what() << endl;
            }
        } else {
            printf("[o] -- %s\n", entry->GetFullName().c_str());
        }
    }
    printf("\n");
}

The strange is that "decompressStream" is a std::istream like the one that parse_stream want. But g++ say the is a no known conversion.

Thanks in advance for your help.

Regards
Marco




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]