iOS Parse XML iTunes:image tag - ios

I am trying to parse a podcast to build a table view of its contents in my app. The picture for the podcast is in a tag listed as:
<itunes:image href="http://www.site.com/picture.jpg" />
In my app, I try to get the contents of the string using:
NSString *articleImage = [item valueForChild:#"itunes:image"];
When I run a log for this string, nothing shows up. So, how would I go about getting the URL of the jpg from this particular tag?

The url is in an attribute called href, valueForChild gets the text value of the element, which is quite correctly empty.
You want to use [item attributeForName:#"href"] where item is your itunes:image element.

Related

Core Data imports attributes (from type NSString) with spaces and new line

I am importing some data using NSXMLParser from XML into Core Data.
xml looks like:
<Translation>
<LanguageCode>EN</LanguageCode>
<SurahName>Al Anfal (The Spoils of War)</SurahName>
<TranslatedText>Believers areā€¦</TranslatedText>
</Translation>
XML is ok i mean there aren't existing spaces there.
Then i want to display saved data on the App.
I concatenate different attributes into one string but it is not displayed in one line. (Integer values coming from other entity)
After debug, i realised that the attributes from type NSString added wrong into the core data. Namely they are containing spaces and line break.
I am using following code to concatenate string with integer values:
NSString *result = [NSString stringWithFormat:#"%# - :%i / %i",currentTranslation.surahName,surahNr,verseNr];
Result should be a string without line breaks, but surahName pushes following integers to the next line.
Result:
Al Anfal (The Spoils of War)
- :8 / 2
As you see this part "- :8 / 2" printed in new line which pushed by surahName.
I searched this problem but i didn't find something. I don't know what i am doing wrong.
I hope the description above was clear.
Thank you in advance
The problem should be in the way you parse your XML.
In the exemple you give, there is a new line caracter after the ending of each element.
Here is the delegate's methods called to parse your surahname line:
didStartElement (<SurahName>)
foundCharacters (Al Anfal (The Spoils of War))
didEndElement (</SurahName>)
foundCharacters (new line caracter)
In foundCaracters method you have to check if those caracters are in an opened element, and if this element is supposed to contain caracters.
If you determine caracters as usefull, add it to your current content, else don't use it.

Parsing XML issue

I have been trying to parse an XML file and all is going well except for one thing.
this is what my XML looks like:
<portfolio>
<item>
<image url="http://www.google.com" />
<title>my first title here.</title>
<desc>my first description here...</desc>
<date>15/07/2010</date>
<skills>skills 1, skills 2, skills 3</skills>
</item>
</portfolio>
I have been parsing: title, desc, date, and skills perfectly. The only issue I am having is parsing the image url. I am using this simple parser: https://github.com/robertmryan/Simple-XML-Parser
Anyway this is how I am setting up the element names to parse:
parser.elementNames = #[#"image", #"title", #"desc", #"date", #"skills"];
Anyway what do I feed into the element name for the image url based upon the XML snippet I gave above?
Thanks!
Edit:
I logged the dictionary it returns after trying the following 3 bits of code:
parser.attributeNames = #[#"image url"];
parser.attributeNames = #[#"image"];
parser.attributeNames = #[#"url"];
Each one of those (after being parsed), returns a dictionary which I logged as this:
dict keys: (
title,
skills,
desc,
date
)
So something is not working right.
The image element has a url attribute so you need to specify that you want the attribute to be parsed out too. Do this by setting the value of the attributeNames property on your parser.
This parser is really basic though so it has some limitations. Most important for you is that attributeNames is only used on the 'main' element (specified with rowElementName) so to do what you want to do you will need to edit the parser class to change that.

two same attributes in POST

I need to upload file with Yii. In view I have row:
<?php echo CHtml::activefileField($qualificationModel, 'picture'); ?>, where
$qualificationModel = new SkillsMapping;
Part of controller:
$skillsModel = SkillsMapping::model();
$skillsModel->attributes=$_POST['SkillsMapping'];
$skillsModel->picture=CUploadedFile::getInstance($skillsModel,'picture');
echo var_dump($_FILES);
if($skillsModel->validate())
{
if($skillsModel->save())
{
$skillsModel->picture->saveAs('images/qual-pics');
$this->redirect(array('view','id'=>$model->user_id));
}
}
When i chose photo and clicked button i have a error Picture cannot be blank.
After checking POST request i founded strange thing - request have two attributes - SkillsMapping[picture]= and SkillsMapping[picture]=Lighthouse.jpg. If commented echo in top of this post, both attributes disappear. How to remove empty SkillsMapping[picture] and why it's going? Thanks.
You do not need to remove the empty hidden field because it's there to help you, not hurt you (Yii itself automatically puts it there; see the relevant part of the source).
The hidden field is there so that $_POST is populated with an empty value when no file has been selected to upload. If a file has been selected the file input control will provide its own POST value that overwrites the empty "guard value".

Showing unicode in the console in the right format

NSSet *subFolders = [_account subscribedFolders];
NSLog(#"subFolders: %#",subFolders);
Output:
...
"[Gmail]/\U05d8\U05d9\U05d5\U05d8\U05d5\U05ea",
"[Gmail]/\U05d7\U05e9\U05d5\U05d1"
...
Is there any way I can show the above text in its original language (Hebrew) ?
Things I tried:
changing the debugger from LLDB to GDB - Didn't work
Checking under preferences -> Text Editing UTF-* is selected
Thanks
There is no issue with displaying unicode characters in the console, so I would assume it's the way the string is getting into the set in the first place.
I would suggest iterating over all the objects inside subFolders with something like:
for( id object in [subFolders allObjects] ) {
//Print out the name of the item explicitly
}
Even if this doesn't work, it at least lets you work with the strings directly. If it's still printing out:
"[Gmail]/\U05d8\U05d9\U05d5\U05d8\U05d5\U05ea"
It would look as if you're being sent escaped unicode characters, and I would suggest this: https://stackoverflow.com/a/7861345/352891 - this may work directly on NSSet's description
NSString* strOld=[NSString stringWithFormat:#"%#",responseObject];
NSLog(#"%#",[NSString
stringWithCString:[strOld cStringUsingEncoding:NSUTF8StringEncoding]
encoding:NSNonLossyASCIIStringEncoding]);

How to use locale entity in js-code

is it possible to get the value of an entity
<!ENTITY gatwayError "Gateway error">
using javascript? For now I reference them in my xul file using
&gatewayError;
UPDATE: In my ff-sidebar.xul within the <page> I have
<stringbundleset id="stringbundleset">
<stringbundle id="strings"
src="chrome://myaddon/locale/de/sidebar.properties"/>
</stringbundleset>
In my ff-sidebar.js I do on click:
var strbundle = document.getElementById("strings");
var localizedString = strbundle.getString("test");
This gives me following error
Should it not be
var strbundle = document.getElementById("stringbundleset");
This gives me no error but no result too.
Basically what Neil posted there is what you need to do (minus first paragraph rant :P )
Here's an example (basically digest from Neil's links):
Your XUL file:
<stringbundleset id="strbundles">
<stringbundle id="strings" src="chrome://yourextension/locale/something.properties"/>
</stringbundleset>
Your something.properties (there you define your localized strings key=value). Of course you can have as many files as you want/need:
something=Some text for localization
something2=Some more text
Your js file:
var strbundle = document.getElementById("strings");
var localizedString = strbundle.getString("something");
Hope this helps.
This works for small numbers of entities. For instance, menuitems sometimes have two entities with slightly different text depending on what the menuitem will be used for, and the correct entity is then copied to the label. The worst abuse of this was for the Delete menuitem in Thunderbird and SeaMonkey's mail windows, which had labels for unsubscribing from newsgroups, deleting folders, cancelling news posts, deleting single or multiple messages, or undeleting single or multiple messages from folders using the IMAP mark as delete model. Phew!
If you have lots of locale data then the best thing is to put it in its own .properties file and read it using a <stringbundle>. If your script doesn't have access to a <stringbundle> element it is also possible to manually retrieve an nsIStringBundle from the nsIStringBundleService.

Resources