1

我想从中加载 TinyXml 文档std::istream,但它不包含这样的方法:

/** Load a file using the current document value.
    Returns true if successful. Will delete any existing
    document data before loading.
*/
bool LoadFile( TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
/// Save a file using the current document value. Returns true if successful.
bool SaveFile() const;
/// Load a file using the given filename. Returns true if successful.
bool LoadFile( const char * filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
/// Save a file using the given filename. Returns true if successful.
bool SaveFile( const char * filename ) const;
/** Load a file using the given FILE*. Returns true if successful. Note that this method
    doesn't stream - the entire object pointed at by the FILE*
    will be interpreted as an XML file. TinyXML doesn't stream in XML from the current
    file location. Streaming may be added in the future.
*/
bool LoadFile( FILE*, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );

我看到它包含使用的功能FILE,是否可以转换std::istreamFILE

4

2 回答 2

2

我在这里找到了明确的解决方案:

C++ 风格输入:

  • 基于 std::istream
  • 运营商>>

从流中读取 XML,使其可用于网络传输。棘手的部分是知道 XML 文档何时完成,因为流中几乎肯定会有其他数据。TinyXML 将在读取根元素后假定 XML 数据是完整的。换句话说,包含多个根元素的结构不良的文档将无法正确读取。另请注意,由于 STL 的实现和 TinyXML 的限制,operator>> 比 Parse 慢一些。

例子:

std::istream *in = ResourceManager::getInstance().getResource(resourceName);
if(in) {
   TiXmlDocument doc;
   // load document from resource stream
   *in >> doc;
}
于 2012-09-09T12:04:13.353 回答
1

从 加载整个数据istream,然后使用TiXmlDocument::Parse.

于 2012-09-09T11:02:41.490 回答