Solved

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

Posted on 2003-10-25
5
239 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 

Author Comment

by:syed110
ID: 9623088
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
ID: 9624835

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
ID: 9626353
thanx kelly,let me try....
0
 
LVL 9

Expert Comment

by:tinchos
ID: 10546142
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

615 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