XmlDocument object from a file

Help
2009-05-31
2013-04-08
  • Hello,
    I try to find solution of my problem with creating a XmlDocument object from a file, but I without success. I just found this piece of code in this forum, so I tried it, but it doesn'w work:

    #include "SmartWin.h"
    #include "SmartXML.h"

    using namespace SmartXML;

    std::basic_ifstream< TCHAR > file( "lang.xml" );
    if ( file.good() )
    {
            XmlDocument ( file );
            ...
    }

    error: no matching function for call to `SmartXML::XmlDocument::XmlDocument()'
    note: candidates are: SmartXML::XmlDocument::XmlDocument(const SmartXML::XmlDocument&)
    note:                 SmartXML::XmlDocument::XmlDocument(std::basic_istream<char, std::char_traits<char> >&)
    note:                 SmartXML::XmlDocument::XmlDocument(const SmartUtil::tstring&, const SmartUtil::tstring&, const SmartUtil::tstring&, const SmartUtil::tstring&, const SmartUtil::tstring&)

    Can you help me? :( Thank.

     
    • andrew7
      andrew7
      2009-05-31

      This is the code I have:

      XmlDocument::XmlDocumentPtr XmlDocument::createDocument( const SmartUtil::tstring & filename )
      {
          std::basic_ifstream< TCHAR > filestream( filename.c_str(), ios_base::binary | ios_base::in );
          if ( ! filestream.good() ) {
              SmartUtil::tstringstream ss( filename );    ss << " File not good" << std::endl;
              throw xCeptionXML( ss.str() );
          }
          XmlDocumentPtr retVal( new XmlDocument( filestream ) );
          return retVal;
      }

      Notice the use of XmlDocumentPtr.

      This is not a complete answer, but it might help.

              /// Constructor creating an XML document from a stream
              /** XML document is loaded from the given stream and built up from that
                */
              explicit XmlDocument( std::basic_istream< TCHAR > & stream );

       
    • Thank you, it works :)