Click here to Skip to main content
15,881,823 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
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
Posted
Updated 14-Mar-11 20:33pm
v2
Comments
[no name] 15-Mar-11 3:07am    
if you want only data of .xsd file then you could save as this file as .txt and then read file as normal text file,

but reading direct .xsd file may not allows by microsoft.
Graham Shanks 15-Mar-11 9:27am    
The .xsd file is a text file and can be read directly by C++

1 solution

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:

C++
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.

C++
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;
}
 
Share this answer
 
Comments
savita_Bgm 16-Mar-11 0:33am    
getting error for this line
std::ifstream file("myfile.xsd", std::ios::in|std::ios::binary|std::ios::ate);
Graham Shanks 16-Mar-11 5:43am    
A compile error or run-time error? What is the error?

You need to include both of the following include files:

#include <iostream>
#include <fstream>

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900