Hello, I'm stuck and about to put my hands in the air and back away slowly!
Please bare with me as I'm brand spanking new to XML and finding documentation/examples of doing this (C++ MFC Dialog-based app) has been extremely difficult.
Having said that...
I've developed a client/server MFC winsock application (VS6) in which I'd like to incorporate a server-side RSS news aggregator.
In other words, an administrator will be able to subscribe to RSS feeds (syndic8, myrss), the server will periodically check the dates of the requested rss files and if new, copy it to the server, parse the data in the file, and send it to the clients.
For those of you are unfamiliar, in terms of RSS, there are several nodes in the file titled "item" (Did I say that right?). Under each "item" there is a "title" (the news headline) and a "link" (the url of the full news story). These are the only elements/nodes that I care about for my needs... I think.
I want to store the values of "title", add them to an array, send those to the clients, and when clicked, the client should query the XML file on the server for that value, find the "link", and pass it back to the client's default browser.
Everything is complete except for the XML logic. It seems like what I'm trying to do is fairly simple and shouldn't require a more robust solution such as expat or xerces, as RSS files are fairly small and I'm only trying to get values and store them as memory variables.
So, my FIRST and most obvious question is, can TinyXML help me? If not, can someone point me to the right direction? Any help whatsoever on this subject will be extremely appreciated.
Thanks in advance,
Don
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm not sure what the "rdf:li rdf:resource" stuff is for, but it seems like I could just skip all of that and look for the "item" tags and then parse out the "title" and "link" children from those? If I could see how to copy those values to a CString variable, I'm pretty sure I can nail the rest.
Thank you so much for your help!
Regards,
Don
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Lines like that:
TRACE("VALUE: %s", siteurl->FirstChild()->ToText()->Value());
are crashes waiting to happen. Check all those pointers and I'll think you'll be a step closer to your answer.
You're also lacking a top-level element. That may also screw things up, as it means your XML is not well-formed.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks for the quick response. Turns out your advice was helpful. When I started checking my pointers I realized they were all null because my XML was pointing to the wrong file. Fixed the file, and it fixed my problem. Thanks again.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2003-09-02
Hi Yves,
Thanks again for your help. Everything's working great, except for one small detail.
As per the example above, I was hoping to be able to replace "cnn.xml" with http://myrss.com/f/c/n/cnnGf9z390.rss" but my executable is unable to locate the file that way. I either have to enter the full path (c:\\MyDirectory\\cnn.xml) or put it into the source directory, but it's unable to locate it in the same directory as the executable (debug) or directly from the web resource. Is this possible?
I'm sure it's just something simple that I'm overlooking.
Thanks again,
Don
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello, I'm stuck and about to put my hands in the air and back away slowly!
Please bare with me as I'm brand spanking new to XML and finding documentation/examples of doing this (C++ MFC Dialog-based app) has been extremely difficult.
Having said that...
I've developed a client/server MFC winsock application (VS6) in which I'd like to incorporate a server-side RSS news aggregator.
In other words, an administrator will be able to subscribe to RSS feeds (syndic8, myrss), the server will periodically check the dates of the requested rss files and if new, copy it to the server, parse the data in the file, and send it to the clients.
For those of you are unfamiliar, in terms of RSS, there are several nodes in the file titled "item" (Did I say that right?). Under each "item" there is a "title" (the news headline) and a "link" (the url of the full news story). These are the only elements/nodes that I care about for my needs... I think.
I want to store the values of "title", add them to an array, send those to the clients, and when clicked, the client should query the XML file on the server for that value, find the "link", and pass it back to the client's default browser.
Everything is complete except for the XML logic. It seems like what I'm trying to do is fairly simple and shouldn't require a more robust solution such as expat or xerces, as RSS files are fairly small and I'm only trying to get values and store them as memory variables.
So, my FIRST and most obvious question is, can TinyXML help me? If not, can someone point me to the right direction? Any help whatsoever on this subject will be extremely appreciated.
Thanks in advance,
Don
Don,
You should be able to use TinyXML for these RSS feed.
If you post an example of the RSS you need to parse, I can show you the basic code
That's great!
Here's the link for an actual CNN RSS feed from myrss.com.
http://myrss.com/f/c/n/cnnGf9z390.rss
I'm not sure what the "rdf:li rdf:resource" stuff is for, but it seems like I could just skip all of that and look for the "item" tags and then parse out the "title" and "link" children from those? If I could see how to copy those values to a CString variable, I'm pretty sure I can nail the rest.
Thank you so much for your help!
Regards,
Don
Here is the main loop.
I did not add all needed tests, for existence of pointers before to derefence them.
-----------------------
#include "tinyxml.h"
void main ()
{
TiXmlDocument * doc;
TiXmlElement * lev1, * lev2, * link, * title;
doc = new TiXmlDocument;
doc -> LoadFile ("cnn.xml");
lev1 = doc -> FirstChildElement ();
lev2 = lev1 -> FirstChildElement ("item");
while (lev2)
{
printf ("item found\n");
title = lev2 -> FirstChildElement ("title");
printf (" title : %s\n", title -> FirstChild () -> ToText () -> Value ());
link = lev2 -> FirstChildElement ("link");
printf (" link : %s\n", link -> FirstChild () -> ToText () -> Value ());
lev2 = lev2 -> NextSiblingElement ("item");
}
delete doc;
}
I tried to mimic this code to meet my needs for a Windows app I'm writing, but I keep running into a problem. The XML I'm parsing is as follows:
<?xml version="1.0" standalone=no ?>
<site>
<siteid>A0001</siteid>
<sitename>MySite1</sitename>
<siteurl>http://www.mydomain.com</siteurl>
</site>
<site>
<siteid>A0002</siteid>
<sitename>MySite2</sitename>
<siteurl>http://www.myotherdomain.com</siteurl>
</site>
I modified the above code as follows:
void CWebsiteDigest::ProcessData()
{
TiXmlDocument * doc;
TiXmlElement * lev1, * lev2, * siteid, * sitename, * siteurl;
doc = new TiXmlDocument();
doc -> LoadFile ("c:\website_tree.xml");
lev1 = doc -> FirstChildElement();
lev2 = lev1 -> FirstChildElement("site");
while (lev2)
{
TRACE("ITEM FOUND\n");
siteid = lev2->FirstChildElement("siteid");
sitename = lev2->FirstChildElement("sitename");
siteurl = lev2->FirstChildElement("siteurl");
TRACE("VALUE: %s", siteurl->FirstChild()->ToText()->Value());
lev2 = lev2 -> NextSiblingElement ("site");
}
delete doc;
}
It fails when I make the call to FirstChild() as part of the debugging TRACE macro. The line it fails on is in tinyxml.h:
TiXmlNode* FirstChild() const { return firstChild; } ///< The first child of this node. Will be null if there are no children.
Any ideas why this wouldn't work?
Lines like that:
TRACE("VALUE: %s", siteurl->FirstChild()->ToText()->Value());
are crashes waiting to happen. Check all those pointers and I'll think you'll be a step closer to your answer.
You're also lacking a top-level element. That may also screw things up, as it means your XML is not well-formed.
Thanks for the quick response. Turns out your advice was helpful. When I started checking my pointers I realized they were all null because my XML was pointing to the wrong file. Fixed the file, and it fixed my problem. Thanks again.
Hi Yves,
Thanks again for your help. Everything's working great, except for one small detail.
As per the example above, I was hoping to be able to replace "cnn.xml" with http://myrss.com/f/c/n/cnnGf9z390.rss" but my executable is unable to locate the file that way. I either have to enter the full path (c:\\MyDirectory\\cnn.xml) or put it into the source directory, but it's unable to locate it in the same directory as the executable (debug) or directly from the web resource. Is this possible?
I'm sure it's just something simple that I'm overlooking.
Thanks again,
Don
Don,
We don't have an HTTP client inside TinyXML.
You need to find a way to do that yourself.
Yves
Gotcha. You've been extremely helpful. I think I'm finally getting the hang of it. Thank you very much for your help.
Don