NSXMLParser : requesting guidance with making grouped tables from an RSS/XML feed - iphone

Im making a group table that is populated from an XML/RSS feed, ive managed to parse the data to the table just fine, but im stuck on how to make the table grouped?
ie, i want an events listing, and i want to organise the events in groups, using the Month for each group, how would i achieve this?
below is my XML structure, its pretty basic
<EventsUpcoming>
<Event id="1">
<month>July</month>
<title>Ian Moss</title>
<date>Saturday, July 1st</date>
<ticket>$35 On the door</ticket>
<description>
Ian Moss from Cold Chisel fame will be touring Australia and the only venue to secure him in Perth is the Blvd.
</description>
</Event>
<Event id="2">
<month>August</month>
<title>Cold Chisel</title>
<date>Saturday, August 3rd</date>
<ticket>$25 on the door</ticket>
<description>
From Khe San fame, Cold Chisel is back with the legendary Jimmy Barnes, dont miss out this gig. Its gonna go down in the books for sure!
</description>
</Event>
<Event id="3">
<month>September</month>
<title>Australian Crawl</title>
<date>Saturday, September 1st</date>
<ticket>Free</ticket>
<description>
They're one of Australia's most iconic band names, be sure to come down and check them out before they die.
</description>
</Event>
</EventsUpcoming>
If anyone knows any tutorial sites that might be helpful or just tips on how to go about doing this, thatd be much appreciated. Thanks in advance :)

NSMutableSet doesn't store the duplicate values,it only stores distinct ones.So at the time of parsing,you can use NSMutableSet to store the 'month' value of each xml element and set the number of sections in a tableview to the count of your NSMutableSet.

Related

How can I create a chatbot that organizes input into selected templates?

I want to create a chatbot that asks questions that, according to their answers, travel down a tree of templates. I'm not very experienced in the coding world, so excuse me if my jargon isn't right!
Here's an example.
I want to write custom reports based on a user's input into a chatbot. Let's imagine the user wants some daily, custom motivation.
How are you feeling today?
Based on user inputs this is categorized into:
"GOOD - BAD - SAD - HAPPY - EXCITED" etc...
Depending on which one, we travel down a "template tree," so any templates that would exist under the "BAD" category are disregarded if the user writes "Pretty Good" and it's categorized as "Good."
Then we ask questions like, "What's your name?", that are stored as variables to incorporate into a text template once we find the right template based on their inputs.
What's the best platform to build this? Is it indeed a chatbot?
Thank you so much for the help!
I tried Pandorabots but it seems too linear - as in a input > response model, there's not much conditional logic. I'm ready to research and learn, so any tips on which platform / approach would be very helpful!
Pandorabots uses AIML to create a chatbot and you can certainly do conditional logic in it. Here's some code that will solve your request:
<?xml version="1.0" encoding="UTF-8"?>
<aiml version="2.0">
<category>
<pattern>HI</pattern>
<template>
Hi there. What is your name?
</template>
</category>
<category>
<pattern>*</pattern>
<that>WHAT IS YOUR NAME</that>
<template>
<think><set name="name"><star/></set></think>
How are you feeling today?
</template>
</category>
<category>
<pattern>*</pattern>
<that>HOW ARE YOU FEELING TODAY</that>
<template>
<think><set name="mood"><star/></set></think>
<condition name="mood">
<li value="good">That's great <get name="name"/>.</li>
<li value="bad">Sorry to hear that <get name="name"/>. Can I help?</li>
<li value="sad">Cheer up <get name="name"/>, it's a beautiful day!</li>
<li value="happy">Oh wow <get name="name"/>. I'm so pleased for you!</li>
<li value="excited">Amazing <get name="name"/>! What's happened?</li>
<li>The day is yours to command <get name="name"/>.</li>
</condition>
</template>
</category>
</aiml>
A sample conversation would look like this:
Using the pattern side tag, you can also do this with Pandorabots to group similar answers together. Create sets called "good" and "bad" with all the emotions that should trigger the templates. Example of the "good" set:
[
["amazing"],
["good"],
["happy"],
["great"]
]
And then use a categories like this:
<category>
<pattern>I FEEL <set>good</set></pattern>
<template>Great to hear!</template>
</category>
<category>
<pattern>I FEEL <set>bad</set></pattern>
<template>Sorry to hear that. Can I help?</template>
</category>
Hope that helps. Pandorabots is capable of FAR more than input - response and I've won the Loebner Prize 4 times for having the world's most humanlike conversational AI using AIML and Pandorabots.
Since you already tried Pandorabots then I assume you are familiar with XML and aiml, that's why I am proposing program O Program O on Github
aiml has a functionality call which can be used to build interactive tree chats.
check my example below. though I guess you might have come across aiml in your research.
<?xml version = "1.0" encoding = "UTF-8"?>
<aiml version = "1.0.1" encoding = "UTF-8"?>
<category>
<pattern>hi</pattern>
<template>How are you feeling today?</template>
</category>
<category>
<pattern>GOOD</pattern>
<that>How are you feeling today?</that>
<template>Nice, I like it that way.</template>
</category>
<category>
<pattern>BAD</pattern>
<that>How are you feeling today?</that>
<template>
<randon>
<li>Ok! I think you need an appointment with a doctor?</li
<li>How exactly are you feeling?</li>
</random>
</template>
</category>
<category>
<pattern>SAD_</pattern>
<that>How are you feeling today?</that>
<template>
<randon>
<li>Ok! what happened?</li
<li>how can i help?</li>
</random>
</template>
</category>
<category>
<pattern>HAPPY_</pattern>
<that>How are you feeling today?</that>
<template>
<randon>
<li>great! its good for you</li
<li>thats what up.</li>
</random>
</template>
</category>
</aiml>

How to use the same WSDL message defenitions in multiple functions?

I had some errors about invalid definitions coming from Visual Studio 2010 when trying to call a WSDL defined function. The problem was that you cannot use the same message definition in two seperate functions. So I have to create multiple message definitions while they do the same.
For instance:
<message name="Hi">
<part name="input" type="xsd:string">
</message>
<message name="Say_hi_back">
<part name="return" type="xsd:string">
</message>
<message name="I_hate_you">
<part name="return" type="xsd:string">
</message>
<portType name="DataPort">
<operation name="sayHello">
<input message="tns:Hi"/>
<output message="tns:Say_hi_back"/>
</operation>
<operation name="sayIHateYou">
<input message="tns:Hi"/>
<output message="tns:I_hate_you"/>
</operation>
</portType>
Now calling either one of the functions will give you an error. Unless I add a Hi2 with exactly the same parts and change one of the input messages in the operation definitions to tns:Hi2.
Why is this? It makes no sense. I'm building up a service where I'm going to have to add the customerID to all the functions I'm going to build. One function for getting the appointments, one for the payments, one for all. This means I'm going to have to copy the message definition like 10 times and name them getCustomerID*N*.
Also a lot of times I'm going to have to have multiple input parameters. Say for instance someone wants to have all appointments between date x and date y. (And this goes for all the information that is stored like payments etc.) While I only need one message with an int, a date and a date. I'm going to have to write a huge document.
So my question is if there is any other way to do this. I've only been working with WSDL for two days and those were two days full of problems and deceiving 'victories'. Where you solve one problem only to find out that opened the gate to the next.
Thanks. :)
You are creating a WSDL reflecting an RPC style as evidenced by the 'type' attributes in the message part definitions. I am not entirely sure why this would cause a problem with VS, but the RPC style has gone out of vogue in favor of the document style (the modern versions of some tools have dropped support for RPC altogether).
You may have better results using the document style (document/literal/wrapped is our standard). You can read a little more about style differences here (http://www.ibm.com/developerworks/webservices/library/ws-whichwsdl/).
The changes required are not too complex and this site (http://wso2.org/library/knowledge-base/convert-rpc-encoded-wsdl-document-literal-wrapped-wsdl) gives some help, although I think the author flipped his rpc vs literal output definitions in the #Output message section.

Umbraco XSLT RenderTemplate Woes

Needing a little guidance with XSLT and Umbraco. Fairly new to XSLT but I think I understand the concepts. Right on one page I have two columns, each with their own separate pickable content. This is done via the standard content picker property (one for each column). The issue is that I need to be able to have two different templates on the page. So in essence the page navigated two which has the columns has to render two of it's child items in its own page.
I have this working with one column using a generic XSLT which I found that basically just renders what ever child item it finds, but I want it to render what ever one the user picked.
I know the Content Picker returns the XML Node ID of the page and that can be used with the Render Template function to display it (I have an example of that), but when it comes to adding in my own properties and then passing them to the RenderTemplate function I get lost. New to this XSLT :).
So far I have...
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library"
xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon"
xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes"
xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath"
xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions"
xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings"
xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets">
<xsl:output method="html" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:variable name="nodeID" select="data[#alias='leftColumn']"/>
<xsl:template match="/">
<xsl:value-of select="umbraco.library:RenderTemplate($nodeID)" disable-output-escaping="yes"/>
</xsl:template>
</xsl:stylesheet>
Any one know why this doesn't work and how to do what I'm after? The above gives a value was either too large or too small error.
You actually have two problems here ...
Calling RenderTemplate()
RenderTemplate actually requires two arguments when using an alternative template, the first being the content node ID, and the second being the chosen template you want applied.
<xsl:value-of
select="umbraco.library:RenderTemplate($nodeID, $templateID)"
disable-output-escaping="yes" />
See the following link for more information : http://our.umbraco.org/wiki/reference/umbracolibrary/rendertemplate
Too large or too small error
This one is simple to fix by putting an if-empty statement around the the code in question.
<xsl:if test="$nodeID != ''">
<xsl:value-of
select="umbraco.library:RenderTemplate($nodeID, $templateID)"
disable-output-escaping="yes" />
</xsl:if>
The XSLT parser likes to assume certain values are null, when in reality they aren't. Another way to get by this is to check the Skip Errors checkbox when saving, but this makes debugging actual erroneous code a bit of a pain.
Hope it helps.

iPhone: How to handle Core Data relationships

I'm new to Core Data and databases in general. Now I need to parse a XML and store the contents in Core Data. The XML looks something like this:
<books>
<book id="123A" name="My Book">
<page id="95D" name="Introduction">
<text id="69F" type="header" value="author text"/>
<text id="67F" type="footer" value="author text"/>
</page>
<page id="76F" name="Chapter 1">
<text id="118" type="selection">
<value data="1">value1</value>
<value data="2">value2</value>
<value data="3">value3</value>
</text>
</page>
</book>
<book id="124A"...
From my understanding I would need four Entities, like "Books", "Book", "Pages" and "Text". I wonder how to set the relationships correctly and how to add for example a Page object to a Book object and how to retrieve a Text object attribute's value? The tutorials I have found mostly deal with one Entity so I didn't really get the idea.. Gtrateful for any help!
No, you'd need three entities. You can think of "Books" as the CoreData database you're using. The CoreData database then includes a number of entities called book.
I think the data model you have is a bit weird, but I guess it makes sense for your application. To map it to CoreData I would:
Add the entities Book, Page, Text
Add a bookId, pageId, textId to them, respectively.
Then add a relation from Page to Book, and from Text to Page.
By then you should be able to print out a whole book by asking for all Pages that have
Book = the book you're interested in
and then order all those Pages by their pageId
and in order, ask for all texts that have
Page = the current page
then order those Texts by their textId.
What might be a problem is that a Text can have multiple Values, as seen in your XML above. You could use this by adding another entity called Value, but I would probably solve it by adding the attributes "value" and "type" to the Text entity directly. (You could then use "value" as a second sort key when printing out a page.
Check out these links:
http://developer.apple.com/iphone/library/documentation/Cocoa/Conceptual/CoreData/
http://developer.apple.com/cocoa/coredatatutorial/index.html (for regular Cocoa, but the same principles hold so this should help)

What is the best way to update data for an iPhone app?

I am developing an application for iPhone and one part of it deals with a list of currencies and daily exchange rates. I am using SQLite to store all these rates.
Now I came to the part where I want to make the update part of my database with the new exchange rates.
The first thought was make a request to a server with a specific date and to read back an XML containing something like:
<date value="2010-10-04">
<currency name="EUR" rate="xxx" />
<currency name="USD" rate="yyy" />
<currency name="GBP" rate="zzz" />
........
</date>
<date value="2010-10-05">
<currency name="EUR" rate="xxx" />
<currency name="USD" rate="yyy" />
<currency name="GBP" rate="zzz" />
........
</date>
But now I was thinking isn't it better to make my own format, something like:
#|2010-10-04#EURxxx#USDyyy#GBPzzz#|2010-10-05#EURxxx#USDyyy#GBPzzz##
The separator will be #. Known that always the date takes 11 characters and starts with | and currency code takes 3 characters, I can search the rate until I will find a # sign.
Because I want to send as little data as I can I think this second approach will be better than the usual XML, even if I reduce the XML to:
<d v="2010-10-04">
<c name="EUR" r="xxx" />
<c name="USD" r="yyy" />
<c name="GBP" r="zzz" />
........
</d>
<d v="2010-10-05">
<c name="EUR" r="xxx" />
<c name="USD" r="yyy" />
<c name="GBP" r="zzz" />
........
</d>
What are your pro & cons for this?
XML is easier to read and parse. Unless you're fetching a zillion currencies and daily rates a day, the # of bytes shouldn't be an issue.
JSON format would split the difference between a proprietary format and a standard format. It is somewhat less verbose than XML and has the flexibility and maintainability vodkhang rightly expects.
The pros:
As you already stated, it is shorter, faster to retrieve.
Faster to parse as well
The cons:
If you develop the server side and the other developer on the mobile side, then he may get confused when there are no meanings
It is hard to scale when you have more and more attributes and if you delete or change some attributes, you have to go over all codes to change it.
CFPropertyList is pretty good if you're using PHP as your server-side language.
Easy to integrate with your server code and has built in support in iOS (e.g. an NSDictionary can be created directly from a plist file).
Link: http://code.google.com/p/cfpropertylist/