HEllo Everybody.....

feels nice to be part of daniweb..community..joined only today......
i am quite ignorant of XML.....but now i have to develop a c/c++ program which reads a XML file......stored on LAN.....retreives the content of the file...and do necesarry manipulation with the retreived data......actually the xml file contains the name of an image and the coordinates of certain points in that image......so the task is to read xml file....then open the corresponding image file and plot the retreived points...in the image.........since i work in image processing..so i have written the code for opening the image and plotting the points...but since i know a little about xml....so i dont know how to reteive the name of image and coordinates from the xml file......
Please help!!!!
Thanks
Paramveer

try any one of these, but be prepared to learn lots of COM stuff. This is one case I recommend doing it in VB.

Hello
Thanks for replying...actually by C/C++ i meant Visual C++.....so instead of VB.....as you said........cant it be done easily in Visual C++....if possible tell me how to do in Visual C++......i cannot use VB...because rest of my code is in Visual C++.....please tell me by some giving some points...as to what the approach should be....instead of giving google links....
Thanks a LOT for Replying.....

>>please tell me by some giving some points...as to what the approach should be....instead of giving google links

The link I posted was incorrect -- see my next post for some good ones.

you really need to learn to do some research on your own. reading xls files isn't a simple task. The file format is a Microsoft secret, subject to change from one version of Excell to another, and requires knowedge of COM because you will be calling some Excell functions to manipulate the file, you don't do it in your program directly because you will not know the file format. If you really want to do that there is information out there that you will need to study. google is the FIRST place you should be looking and maybe a book from www.amazon.com or your local book store.

The link should have been this one. But then you could have easily found that out yourself.

And here are some others about Excel Automation

Um. I think you got it confused dragon. He is infact looking to read an XML file. So I think your first link is correct.

Um. I think you got it confused dragon. He is infact looking to read an XML file. So I think your first link is correct.

Well, in that case forget what I posted about Excell Automation -- it has nothing to do with XML files. Guess I must be getting senile in my old age:mrgreen:

I think Boost Libraries has some xml parsing functions that might help

Hello Everybody....
But what about the way ...how to do it....googgle gives results for xml parsers etc....please tell me how to proceed by maybe giving some points....
Thanks

I am totally confused please tell me how to proceed....
Thanks....

Here is an XML file and a C++ program that processes it. XML file structure is user defined. So this won't work for your XML file. But you can get an idea on how to proceed by studing this example. Now you figure how to do it for your XML file on your own.

This c++ example from boost looks promising. Never used it myself.

Are you using one specific XML file?
Is this file going to be changing over a period of time?
If so, will you have to deal with the changes?

Please answer the questions.

in the meantime, you should be able to view the xml file by:
1 copy to desktop
2 change file extention to .txt instead of .xml
3 you may then read contents with a text editor
(notepad worked for me)
This may give you more insight about what you are up against.
Here is contents of a small xml file I found on my computer.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<options>
  <scheme ID="main">Vegas</scheme>
  <template ID="main"></template>
  <bufferspace ID="main">5</bufferspace>
  <candlewidth ID="main">3</candlewidth>
  <lastbox ID="main">False</lastbox>
  <lastlinecolor ID="main">False</lastlinecolor>
  <manualcandle ID="main">False</manualcandle>
  <zoomed ID="main">False</zoomed>
  <zoompoints ID="main">20</zoompoints>
</options>

Hello Wolfpack and Ancient Dragon,
Thanks for your reply...it was useful.....it works...but what if each time i need to load a different XML file...say...xyz1 then xyz2 then xyz3 and so on.....i.e open first xml file(xyz1) read it open next(xyz2)....and so on but in a loop so could you tell me how to increment the name of xml file in each loop..i.e xyz1...then xyz2.....which C functions can do this
Thanks

what if each time i need to load a different XML file...say...xyz1 then xyz2 then xyz3 and so on.....i.e open first xml file(xyz1) read it open next(xyz2)....and so on but in a loop so could you tell me how to increment the name of xml file in each loop..i.e xyz1...then xyz2.....which C functions can do this
Thanks

You will have to create the filename by using a function like sprintf or snprintf . snprintf is much safer.
something like

for ( int file_number = 1; file_number<= 3; file_number++ )
{
     char filename[ 20 ] = "";
     snprintf( filename, 19, "xyz%d.xml", file_number );
     printf("%s\n", filename );
     // pass filename to your xml file opening function
}

should do the trick.

Thanks a lots...i worked with similar sprintf() function in MATLAB but didnt know similar function exists in C also....
anyways relating to the xml code link that you gave that day.....it was in German(maybe)..so i couldnt understand the comments...so about strtok()...i searched it on google... it said that it is a parser which looks for a given delimiter in a string like <> in your case XML
... but the initial code in that xml file said for(i=0;i<5;i++) but you corrected it to for(i=0;i<3;i++) and the program wirked ...could you tell me what was the problem with initial code...........Please
Thanks

Thanks a lots...i worked with similar sprintf() function in MATLAB but didnt know similar function exists in C also....

MATLAB is more or less like C, so most functions in MATLAB are available in C.

anyways relating to the xml code link that you gave that day.....it was in German(maybe)..so i couldnt understand the comments...

Damned if I knew either. More like Dutch I suppose.

... but the initial code in that xml file said for(i=0;i<5;i++) but you corrected it to for(i=0;i<3;i++) and the program wirked ...could you tell me what was the problem with initial code...........Please
Thanks

The line that should be parsed was <Pindala> 83858km² </Pindala><Rahvaarv>8 116 000</Rahvaarv> So after searching for the Word Pindala , we should stop at the word Rahvaarv , because that is processed in the next part.

if (strcmp(pos, "Rahvaarv") == 0)

That means starting from the word P, how many delimiters should we parse to get to Rahvaarv? [B]<[/B]Pindala[B]>[/B] 83858km² [B]<[/B]/Pindala><Rahvaarv>8 116 000</Rahvaarv> The answer is 3. The ones in Blue are taken care of by the pos = strtok(rida,"<>"); at the beginning.
So you should have 3 strtoks.
Those 3 are

if (strcmp(pos, "Pindala") == 0)
			{
				for (i=0;i<3;i++)
				{
					pos = strtok(NULL,"<>"); // Called 3 times

So that makes 3. If you put 5, it would stop somewhere after Raahvarv and you will not be able to parse the values needed in the next if statement. Anyway I suggest you look at how strtok conducts it's search given in this page. That will make it more clearer.

Also note that I didnt look at the code much at that time; I only wanted to get him going, so even now I can see a lot of cleaning needs to be done in it. For example if ((pos != NULL)&&(k==0)) does not need the check for k, and i++; can be safely removed from the code. You can clean up the code before you use it. That makes understanding the code much easier. Oh well.

Hello,
I couldnot understand the working of strtok().....does it parse the string in <>.....then how come it displays the names of countries etc. which are not in <>......or it parses only 1 delimiter < at a time......but then why do we write strok(s1,"<>"); .....i followed the link you gave me but i couln ot understand its working so could you throw some light on this topic.......
Thanks

Hello,
I couldnot understand the working of strtok().....does it parse the string in <>.....then how come it displays the names of countries etc. which are not in <>......or it parses only 1 delimiter < at a time......but then why do we write strok(s1,"<>"); .....i followed the link you gave me but i couln ot understand its working so could you throw some light on this topic.......
Thanks

I suggest you try parsing just one line instead of the whole file, and see what are the contents pointed by pos, and the original array step by step by adding some printf statements. Then try to see how that agrees with the explaination given by that site. You will have a better chance of understanding the code that way.

I think Boost Libraries has some xml parsing functions that might help

Hi please help me, I want to read an xml file with c++. Means, using COM+ logics how I can send my xml file in the local directory to my c++ code to read it? It would be really thankful if you could give me some ideas about that.

Hi please help me, I want to read an xml file with c++. Means, using COM+ logics how I can send my xml file in the local directory to my c++ code to read it? It would be really thankful if you could give me some ideas about that.

Read the links I posted. COM++ is very difficult and not for beginners, even people with advanced c++ knowledge have difficulties with it. So the boost libraries are probably what you would want, but you will have to do at least some of the research youself. I don't have neigher the time nor the inclination to do your work for you. Download boost, if you have not already done so, the read the documentation is is provided.

Hi every one, ihad a problem... how can i read de names of the tags that are in an xml documnt.

for example

I need to get the first node name from the next xml

<Books>
<test>"something"</test>
</Books>

i need to get 'what is in the first <>'? (as a string)

i hope someone understand me..
i need to do something GENERIC that can be able to read any xml file.

please help me

Hi every one, ihad a problem... how can i read de names of the tags that are in an xml documnt.

for example

I need to get the first node name from the next xml

<Books>
<test>"something"</test>
</Books>

i need to get 'what is in the first <>'? (as a string)

i hope someone understand me..
i need to do something GENERIC that can be able to read any xml file.

please help me

xz

If you know the basics of C and/or C++ then you should have no problem figuring out how to read that xls file. Afterall, it's nothing more or less than a text file. If you don't have the basics down then forget about reading that file for now and concentrate on learning the language.

now i know c and c++ but i dont know how do i Read a XML File in C/C++

If you know C/C++ then you know how to read xml files

int main()
{
   ifstream in("filename.xml");
   std::string line;
   while( getline(in, line) )
   {
     // blabla
   }
}

For something more complex you might look at boost libraries because I think it has a parser class

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.