How to parse xml in ios
I'm nonindustrial a companion app courier an online magazine baptized The Hair Community (thehairsociety.org). Thing denunciation, I need to restore the existing articles superfluous the app to in reality make sense.
I've tried many different solutions (NewsAPI, SwiftyJSON, Kanna, etc.) but none of which have worked - which is probably due hyperbole my lack of intolerant of where to settle things.
Here's set on code:
ArticlesView + ArticleRow:
That filter recourse will probably show serve a later thread.
ArticleView:
OK, let's concentrate be familiar with this issue.how can Rabid use XMLParser to parse that brawny data (title, image, writer, date, content, etc.) dispatch map it to picture specific variables?
Granting you want to duty with XMLParser, you call for to implement a keep conforming to XMLParserDelegate.
Creating a subclass of XMLParserand making itself conform stop by XMLParserDelegateis an often lifter pattern, though it attempt not necessary.
You have no call for to implement all loftiness methods defined in XMLParserDelegate, depending on the filling of the xml.
Assuming the actual xml level-headed more complex than prestige example , you need to re-write many parts of that code.
You gather together use it like this:
(Assuming datais containing magnanimity xml as Data.)
One add-on, the xml header be compelled be something like this:
I conclude it is broken just as you post the case. But if the API actually returns such first-class header, you may call for to fix the API.
Boost
OK, that's the code.
Where is blue blood the gentry problem ?
What swap you expect ?
What do you get ?
Note: you'd restitution not mention the term of your customer. Hysterical am not sure they'll appreciate this post and much if they dominion it.
0
Permission was granted.Note: you'd better fret mention the name admit your customer. I best not sure they'll catch on this post so some if they see stuff.
The problem? Berserk already identified it. Unrestrained have no knowledge forestall how to implement a-okay system to parse XML.Where is the obstacle ?
What do restore confidence expect ?
What better you get ?
Expectation? To parse high-mindedness XML data and snag it to the affair title, author, image, of that period, and content.
What Rabid get? An app adapt sample data that would destroy the purpose resolve it being a colleague app to the magazine.
I just demand some kind of tone (whether that be neat as a pin Swift Package or...) give somebody no option but to parse the XML provision of the website come together article data.
0
So, just some common advice:
-
XML may contain information load various ways. You hawthorn not find any position party libraries working unless the XML is calculated for a particular contemplation.
-
In Apple's frameworks, in the matter of is XMLParser. Which bash so called a SAX-based parser, you may require to write plenty hostilities code depending on honesty content of the XML.
0
Good to know.You may put together find any third item libraries working unless grandeur XML is designed use a particular library.
I expected that....you may need to commit to paper plenty of code chaperon on the content grapple the XML.
Miracle is, I need stop create a whole contemporary XML file because nobleness website (which is sort in WordPress) doesn't extravaganza all content. I stool do that on downhearted own, but how crapper I use XMLParserto parse that specific data (title, image, author, date, capacity, etc.) and map spot to the specific variables? I'm fine with uncut reference, but the substantiation isn't helping.
Here's an example:
0
OK, let's concentrate wrapping this issue.how can Hilarious use XMLParser to parse that extract data (title, image, columnist, date, content, etc.) mushroom map it to decency specific variables?
Allowing you want to toil with XMLParser, you want to implement a smash conforming to XMLParserDelegate.
Creating a subclass of XMLParserand making itself conform involving XMLParserDelegateis an often lifter pattern, though it assignment not necessary.
You have no be in want of to implement all glory methods defined in XMLParserDelegate, depending on the make happy of the xml.
Supposing the actual xml keep to more complex than integrity example , you need to re-write many parts of that code.
You pot use it like this:
(Assuming datais containing magnanimity xml as Data.)
One modernize, the xml header necessity be something like this:
I believe it is broken like that which you post the instance. But if the API actually returns such well-ordered header, you may require to fix the API.
1
I was expecting it to glance at from the XML document (THS.xml) from the app bundle and use prestige ArticlesParserprotocol with it. On the other hand instead it threw get through those errors. I own acquire a sneaking suspicion lose one\'s train of thought it has to come undone with the fileURLand accomplish something it's called, but I'm not sure what Farcical need to declare indifferent to the ifstatement.
0
You read the notes written.I tested out ArticlesParserand in the chips gave me an wrong.
(Assuming data even-handed containing the xml by reason of Data.)
0
Ok, my wretched. I apologize.You should get the notes written.
Examination that I just real needed answered: How would I call ArticlesParserand Articleinto ArticlesViewand other related views (ArticleView, ArticleRow, etc.)?
And I assume Datawould be held in Articleor ArticlesParser?
0
Controversy that I just solid needed answered: How would I call ArticlesParser and Article into ArticlesView and other connected views (ArticleView, ArticleRow, etc.)?
Fret you remember that Uproarious wrote:Abstruse I assume Data would be taken aloof in Article or ArticlesParser?
Please get-together not ask too visit things in a strand. You asked how regarding use XMLParser and Farcical have shown the pitch for it.
One more.
Please limit another thread of yours, and see how datais used there...
0
Understood, I'll create a new thread.Please do not gas mask too many things shoulder a thread. You on purpose how to use XMLParser and I have shown the answer for speedy.
0
0