How would I achieve a similar connection through Juce? I looked at InterprocessConnection, but (and this might be because I haven’t done much coding lately, I’m somewhat rusty) it just doesn’t seem clear how I should open a connection and receive data.
Since I would love to sort of figure it out on my own (instead of being spoon-fed code). Are there any similar examples of others that I could use to look at?
Wow, looks like there’s even a function to download an xml file (readEntireXmlStream()).
Thing is, I’m still not sure as to how to use it. The documentation only shows one function argument, whether or not a url should be downloaded using a POST command.
Even if that’s somewhat close, I’m still not sure how I should go about saving the xml data to a variable (from which I would parse, or… is there an xml parser built-in?).
the readEntireXmlStream(true); will return an XmlElement object witch you can use as described in the XmlElement manual:
if (myElement->hasTagName ("ANIMALS"))
{
// now we'll iterate its sub-elements looking for 'giraffe' elements..
forEachXmlChildElement (*myElement, e)
{
if (e->hasTagName ("GIRAFFE"))
{
// found a giraffe, so use some of its attributes..
String giraffeName = e->getStringAttribute ("name");
int giraffeAge = e->getIntAttribute ("age");
bool isFriendly = e->getBoolAttribute ("friendly");
}
}
}
This is probably better if you want to do anything with the data provided by the XML file.
So the above is for a simple xml file download or any file for that matter, xml, jpg, gifs, etc.
If your calling a web service then use:
Obviously you have to know the web service function name parameter names and values.
And I think the URL class is also valid if your web service has multiple parameters, because if im not mistaken the URL::withParameter function adds you parameter name and values to a StringPairArray.
Well, I might end up using the download method later on to actually… download and save a stream to a file, when I need to download files described in the XML file.
Alright, I’ve got everything pretty close to finished. Here’s my code:
class slResults
{
private:
URL seeqpodResults;
XmlElement *searchResultsXML;
int numOfResults;
String createdURL;
public:
void createURL(String iText)
{
// Still need to parse anything with spaces to replace spaces with '%20'
createdURL = "http://www.seeqpod.com/api/music/anonSearchPaginationFlash?s=0&n=50&q=" + iText;
}
slResults(String iURL)
{
seeqpodResults = new URL(T("%s", iURL));
searchResultsXML = seeqpodResults.readEntireXmlStream(true);
}
String getElement(int resultNum, String elementDescription)
{
if(searchResultsXML -> hasTagName("playlist"))
{
if(searchResultsXML -> hasTagName("trackList"))
{
// Go to 'elementDescription' number 'resultNum', and get result, pass back as String-type
}
}
}
int getNumTrackResults()
{
if(searchResultsXML -> hasAttribute("total"))
{
return searchResultsXML.getIntAttribute("total");
}
else
{
// Print error that there was no 'total' attribute found in document
}
}
};
This is to read a file pretty much similar to this:
<playlist version="1" start="0" end="49" total="169" prev="None" next="50">
<trackList>
<track>
<location>
http://www.thisurl.com/DYTM.mp3
</location>
<title>
I Dare You To Move
</title>
<creator>
Switchfoot
</creator>
<album>
Learning to Breathe
</album>
</track>
<track>
<location>
http://www.thisurl.com/YATMT.mp3
</location>
<title>
You Already Take Me There
</title>
<creator>
Switchfoot
</creator>
<album>
Learning to Breathe
</album>
</track>
</trackList>
</playlist>
Now, as you can see… my function ‘getElement’ is not quite complete. Basically, what I’d like to do is let the user say, "Hey, I’d like to get the result for element ‘album’ (or ‘creator’, whatever) at it’s Xth occurance.
Is there a way to get the Xth XML element in a document with more than one? Would it be just a loop through getting the ‘next’ one each time until I would reach the Xth?
Thanks again for your awesome help!
FlyingIsFun1217