How to store entire source of xml file as a string in c++

六眼飞鱼酱① 提交于 2019-12-13 06:21:42

问题


The xml can only be referred to in the code as an external link for eg. "www.etc.com". I want to be able to extract certain words from the page source of certain websites, but first i need to dump the source content into a string or CString. Thanks for any help


回答1:


I think what you are asking is how to fetch data from the internet. I found this thread and some source code regarding this.




回答2:


You can use a DOM or SAX parser to retrieve each element.

If you want the entire xml file content in memory, then here is the sample code to make it

 

       ifstream fin("books.xml");

       if ( fin.fail())
          return 1;

       fin.seekg(0, ios::end);
       size_t length = fin.tellg();
       fin.seekg(0, ios::beg);

       char* buffer = new char[length+1];
       fin.read(buffer, length);
       buffer[length] = '\0';

       fin.close();



来源:https://stackoverflow.com/questions/11734371/how-to-store-entire-source-of-xml-file-as-a-string-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!