读取.XSD文档并将文档内容存储在CString中 [英] Read a .XSD document and store document contents in a CString

查看:58
本文介绍了读取.XSD文档并将文档内容存储在CString中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我想使用VC ++/MFC阅读一个.XSD文档,并将其存储到字符串变量中.
我正在使用VS2005.

我的问题是

可能吗?我可以将XSD内容存储在字符串中吗?
如果可以的话请解释如何?



我有一个架构(.XSD)文件.
我想使用此XSD创建XML文档.
我如何创建该xml?
这必须在使用VisualStudio 6.0的vc ++/MFC中完成.



在此先感谢

Hi
I want read one .XSD document using VC++/MFC and store it into a string varaible.
i am using VS2005.

my question is

is it possible? can i store the XSD contents in a string?
if possible explain me how?

OR

I have a schema (.XSD) file.
I want to create an XML Document using this XSD.
How Can i create this xml ?
this has to be done in vc++/MFC which is using VisualStudio 6.0.



thanks in advance

推荐答案

我认为有两个选择.第一种是在文本模式下打开文件,然后一次读取一行,并将每一行追加到您的字符串中:

I think that there are two options. The first is to open the file in text mode and then read a line at a time, appending each line to your string:

std::string result;
std::ifstream file("myfile.xsd");
if(file.is_open())
{
  while(file.good())
  {
    std::string temp;
    std::getline(file, temp);
    result.append(temp);
  }
  file.close();
}



第二种方法是将其视为二进制文件,将其读入内存,然后分配给字符串.如果文件很大或有很多行,此方法可能会更有效.



The second way is to treat it as a binary file, read it into memory and then assign to a string. This method may be more efficient if your file is large or has a lot of lines.

std::string result;
char* memblock;
std::ifstream file("myfile.xsd", std::ios::in|std::ios::binary|std::ios::ate);
if (file.is_open())
{
  std::ifstream::pos_type size = file.tellg();
  memblock = new char[size];
  file.seekg(0, std::ios::beg);
  file.read(memblock, size);
  file.close();
  result.assign(memblock, size);
  delete[] memblock;
}


这篇关于读取.XSD文档并将文档内容存储在CString中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆