Solved

How can I put the values from an xml file ,no keyboard reading is required

Posted on 2003-10-25
5
221 Views
Last Modified: 2010-04-01
I have a programm which reads data from an xml file,I would like to put this data in to another class & would like to creat instances of the classes to access the values which is obtained by xml file.
The program which reads data from xml file is as follows:


CMarkup xml;
{
 xml.load(out.xml)//out.xml is an xml file from which data is reading
xml.Reset Pos();
xml.FindElem("root")
xml.IntoElem();

xml.FindchildElem("field1);
xml.IntoElem();

xml.FindchildElem("Data");
xml.IntoElem();
xml.FindchildElem("name")
csstring csname=xml.GetchildData();//here geting the the name from xml file
cout<<csname<<endl;//for displaying on consol

xml.FindchildElem("type")
csstring cstype=xml.GetchildData();//here geting the the type from xml file
cout<<cstype<<endl;//for displaying on consol



xml.FindchildElem("sizebytes")
csstring sizebytes=xml.GetchildData();//here geting the the sizebyte from xml file
cout<<cssizebyte<<endl;//for displaying on consol



OutofElem();
OutofElem();

}

Now I would like to create a class structure which contain the variables like name ,type,length,& would like to put whole the data which I am getting from the above programm without reading from keyboard(means I don't want to display the data on the console in the first programm but want directly putting  the data into this class variables then would like to creat instances of this class for further access.






0
Comment
Question by:syed110
  • 2
5 Comments
 

Author Comment

by:syed110
Comment Utility
there is no answer till now,seems nobody is interested to reply me.Plz.if someone can give attention towards thi´s question.
thanx
syed110
0
 
LVL 1

Accepted Solution

by:
kellycoinguy earned 30 total points
Comment Utility

The first thing you need to do is create a factory method that constructs new objects based upon the name of the types you encounter in your XML file. Fortunately, due to the runtime binding features of C# this is fairly easy to do.

Examine the
using System.Reflection;
namespace and you will find the functions you need to create a name from type. I haven't done it yet, but I remember reading the APIs and this did seem rather straightforward.

Populating public fields and properties dynamically is also fairly easy to do with the System.Reflection namespace.

If you need a great deal of Dynamic classes in your program, you can go REALLY crazy with the System.Reflection.Emit classes, but you're in way over your head if you start there... It allows you to dynamically create new classes on the fly.

I hope this begins to answer your questions, or at least send you off in the right direction.

-Kelly
0
 

Author Comment

by:syed110
Comment Utility
thanx kelly,let me try....
0
 
LVL 9

Expert Comment

by:tinchos
Comment Utility
No comment has been added lately, so it's time to clean up this question.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: kellycoinguy {http:#9624835}

Please leave any comments here within the next four days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Tinchos
EE Cleanup Volunteer
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now