XPathQuery for ObjC
Introduction
XPathQuery4ObjC is a wrapper class for NSXMLParser to query XML documents such as Web API responses with XPath more easily.
I know that some wrapper classes for Objective-C was already released such as XPathQuery. However, these are not appropriate to use for me because I would like to query more directly using XPath and these wrappers have some bugs 🙁
I have developed other my original DOM parsers which are implemented using some native XML parsers such as Xerese, libxml2 and expat on !MacOSX and iOS platforms, but I decided to use NSXMLParser to implement XPathQuery because I know that it is difficult to support all XML features using the native XML parsers. Please check CyberLinkForC, or CyberLinkForCC and CyberX3DForCC if you want to know other my DOM parsers in more detail.
For example, you can query XML element nodes in Web API responses such as Media RSS using the XPathQuery as the following.
NSURL *rssURL = [NSURL URLWithString:@"http://rss.news.yahoo.com/rss/topstories"];
CGXPathQuery *xpathQuery = [[CGXPathQuery alloc] initWithContentsOfURL:rssURL];
if ([xpathQuery parse] == YES) {
NSString *title = [xpathQuery valueForXPath:@"/rss/channel/title"];
..........
NSArray *entries = [xpathQuery objectsForXPath:@"/rss/channel/item"];
for (CGXPathObject *xpathObject in entries) {
NSString *entryTitle = [xpathObject valueForXPath:@"title"];
..........
NSURL *linkUrl = [NSURL URLWithString:[xpathObject valueForXPath:@"link"]];
..........
NSString *imageUrl = nil;
CGXPathObject *mediaContent = [xpathObject objectForXPath:@"media:content"];
if (mediaContent != nil) {
imageUrl = [NSURL URLWithString:[[mediaContent attributes] valueForKey:@"url"]];
}
..........
}
}
Installation
To use XPathQuery on your XCode project, you have to only add the two files, XPathQuery.h and CGXPathQuety.m, into your project 🙂
Classes
XPathQuery is composed of the following two classes, XPathQuery and CGXPathObject.
CGXPathQuery
XPathQuery is a base class to parse XML documents, you have to initialize with the XML data or the URL. You have to use absolute !XPaths to pass the methods such as objectForXPath:.
@interface CGXPathQuery : NSObject {
}
@property(retain) NSError *parserError;
- (id)initWithContentsOfURL:(NSURL *)url;
- (id)initWithData:(NSData *)data;
- (BOOL)parse;
- (NSArray *)objectsForXPath:(NSString *)absoluteXPath;
- (CGXPathObject *)objectForXPath:(NSString *)absoluteXPath;
- (NSArray *)valuesForXPath:(NSString *)absoluteXPath;
- (NSString *)valueForXPath:(NSString *)absoluteXPath;
@end
CGXPathObject
CGXPathObject is a base object of XPathQuery response. CGXPathObject extends NSDictionary to add some useful methods using a category interface. You have to use relative !XPaths to pass the methods such as objectForXPath:.
#define CGXPathObject NSDictionary
@interface CGXPathObject(CGXPathQuery)
- (NSArray *)children;
- (NSString *)name;
- (NSString *)value;
- (NSDictionary *)attributes;
- (NSArray *)objectsForXPath:(NSString *)relativeXPath;
- (CGXPathObject *)objectForXPath:(NSString *)relativeXPath;
- (NSArray *)valuesForXPath:(NSString *)relativeXPath;
- (NSString *)valueForXPath:(NSString *)relativeXPath;
@end
Limitation
XPathQuery supports only the following simple !XPath specification which is minimal subset of XPath, and it doesn’t support the complex specifications currently.
LocationPath ::= RelativeLocationPath
| AbsoluteLocationPath
AbsoluteLocationPath ::= '/' RelativeLocationPath
RelativeLocationPath ::= ElementName
| RelativeLocationPath '/' ElementName
ElementName ::= [a-zA-Z0-9]+
Additionally, XPathQuery doesn’t support traversal queries which jumps the parent element. For example, the following code get only a first title element instead of all title elements..
XML document
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" Ö..>
Ö..
<item>
<title>...</title>
.....
</item>
<item>
<title>...</title>
.....
</item>
</rss>
Inappropriate Code
CGXPathQuery *xpathQuery = [[CGXPathQuery alloc] initWithContentsOfURL:rssURL];
if ([xpathQuery parse] == YES) {
NSArray *itemTitles = [xpathQuery objectsForXPath:@"/rss/channel/item/title"];
for (CGXPathObject *titleObject in itemTitles) {
NSString *title = [titleObject value];
.....
}
}
Appropriate Code
To get all title elements normally, use the following steps.
CGXPathQuery *xpathQuery = [[CGXPathQuery alloc] initWithContentsOfURL:rssURL];
if ([xpathQuery parse] == YES) {
NSArray *items = [xpathQuery objectsForXPath:@"/rss/channel/item"];
for (CGXPathObject *itemObject in entries) {
NSString *title = [itemObject valueForXPath:@"title"];
.....
}
}
Resources
Repositories
Please see the following pages on GitHub to get the source codes with the examples such as a simple RSS reader 🙂
Pingback: Leandro Farland
Pingback: MILF City
Pingback: Madelyn Monroe MILF
Pingback: best-premium-domains
Pingback: Assignment help
Pingback: calendula oil
Pingback: personalized pillow cover
Pingback: Click Here
Pingback: Click Here
Pingback: Click Here
Pingback: Click Here
Pingback: Click Here
Pingback: Click Here
Pingback: Click Here
Pingback: Click Here
Pingback: Click Here
Pingback: Click Here
Pingback: Click Here
Pingback: Click Here
Pingback: Click Here
Pingback: Click Here
Pingback: Click Here
Pingback: Click Here
Pingback: moveit studio
Pingback: spaceros
Pingback: Click Here
Pingback: Click Here
Pingback: Reputation Defenders
Pingback: Click Here
Pingback: Click Here
Pingback: Reputation Defenders
Pingback: Reputation Defenders
Pingback: Reputation Defenders
Pingback: Click Here
Pingback: Click Here
Pingback: Click Here
Pingback: Click Here
Pingback: Click Here
Pingback: Click Here
Pingback: Click Here
Pingback: Click Here
Pingback: Click Here
Pingback: Click Here
Pingback: Click Here
Pingback: Click Here
Pingback: grand rapids teeth whitening
Pingback: grand rapids dentist
Pingback: Click Here
Pingback: Click Here
Pingback: https://gquery.org/
Pingback: Click Here
Pingback: Click Here
Pingback: Click Here
Pingback: 카지노사이트정보
Pingback: Click Here
Pingback: Click Here
Pingback: Click Here
Pingback: Click Here
Pingback: Click Here
Pingback: Click Here
Pingback: Click Here
Pingback: Referral Code
Pingback: Click Here
Pingback: Click Here
Pingback: Click Here
Pingback: Click Here
Pingback: Click Here
Pingback: Click Here
Pingback: Click Here
Pingback: Click Here
Pingback: Click Here
Pingback: Click Here
Pingback: Click Here
Pingback: Click Here
Pingback: Click Here
Pingback: 프로그레시브 잭팟
Pingback: 무료 카지노 게임
Pingback: Do antibiotics make you poop how does plaquenil work
Pingback: domain
Pingback: Do antibiotics weaken your immune system
Pingback: domain-broker
Pingback: Why does a man get erect in the morning
Pingback: What are 6 signs of an asthma attack
Pingback: What is the shortest word in America
Pingback: What is the longest dead person revived Zestril
Pingback: best tech startup books
Pingback: how to choose a cardano stake pool
Pingback: Stromectol 12 mg | What are the top 3 bacterial infections
Pingback: Tadalafil over the counter: What is quality of patient care | ScwCMD.com
Pingback: para q sirve la vidalista 20 sildenafil generic
Pingback: z pack antibiotic side effects Do antibiotics make you tired
Pingback: Was ist das beste Mittel bei Erektionsstorungen wo kann ich kamagra kaufen
Pingback: Google reviews
Pingback: furosemide dosing
Pingback: Comment batir une famille meilleure parapharmacie en ligne 2022
Pingback: Comment Fait-on l'amour a une femme enceinte pharmacie en ligne france livraison belgique
Pingback: What position can you conceive a girl?
Pingback: What is the number one thing a man wants in a woman?
Pingback: What are 3 symptoms of a parasite infection ivermectin stromectol where to buy?
Pingback: reputation defenders
Pingback: Is it my fault my husband has erectile dysfunction?
Pingback: How can I love my wife physically?
Pingback: Can two sperms make a baby?
Pingback: Is it rude to ask someone to take an STD test Hydroxychloroquine 200 mg
Pingback: Which organ is affected first in sepsis zithromax 250mg online
Pingback: Quel couleur represente la famille - dangers du viagra apres 70 ans.
Pingback: How long until antibiotics are out of your system ivermectin for goats
Pingback: What a man should not do in a relationship buy cenforce
Pingback: How long do antibiotics last
Pingback: Is 5 days of antibiotics enough
Pingback: 2023 Books
Pingback: How long does it take for good bacteria to restore after antibiotics
Pingback: What is the strongest natural antibiotic for humans
Pingback: Can I drink Coca Cola while taking antibiotics
Pingback: obituaries
Pingback: rip
Pingback: How many antibiotics can I take in a year
Pingback: cemetery location
Pingback: tombstones
Pingback: Is it OK to eat spicy food while taking antibiotics
Pingback: What antibiotics cause anxiety
Pingback: IRA Empire
Pingback: What are symptoms of too much antibiotics
Pingback: What can replace antibiotics traitement gale stromectol
Pingback: vardenafil pills
Pingback: Do antibiotics improve skin
Pingback: what is levitra for
Pingback: viagra buy online no prescription uk
Pingback: Is Ginger a natural antibiotic
Pingback: Is 5 days of antibiotics enough
Pingback: Can I eat yogurt after antibiotics
Pingback: How many antibiotics per day
Pingback: What is the strongest antibiotic for bacterial infection
Pingback: Can antibiotics do more harm than good
Pingback: Is lemon a natural antibiotic
Pingback: Treblab | beats headphones wireless
Pingback: how to bet on football and win
Pingback: buy stromectol 12 mg online Can amoxicillin make your blood pressure go up?
Pingback: mini speakers bluetooth wireless
Pingback: What are the most common side effects of antibiotics - ivermectin stromectol
Pingback: Chirurgie esthétique Tunisie
Pingback: skullcandy earbuds wireless bluetooth
Pingback: Chirurgie esthétique Tunisie
Pingback: sony headphones wireless bluetooth
Pingback: National Chi Nan University
Pingback: Can you get albuterol over the counter prescriber directions for ventolin
Pingback: What is the first drug of choice for asthma ventolin hfa 90 mcg inhaler
Pingback: Which inhaler is best for breathing problem ventolin inhaler price?
Pingback: What is a heart cough furosemide patient handout?
Pingback: What is the most common inhaler for asthma ventolin inhaler generic name
Pingback: Can I drink water after using an inhaler | $15 ventolin
Pingback: Which inhaler is best for shortness of breath | ventolin hfa coupon
Pingback: Can high blood pressure make you tired and dizzy what is chlorthalidone 25 mg used for
Pingback: Board Of Advisors fue
Pingback: Professional Human Resources Management education
Pingback: Faculty of Commerce and Business Administration
Pingback: Econometrics
Pingback: كلية الاقتصاد
Pingback: Pharmacognos
Pingback: Innovative scientific research
Pingback: علاج الاسنان بالمجان
Pingback: Master's degree in dentistry
Pingback: افضل جامعة في مصر
Pingback: practical training
Pingback: student life at the College of Engineering
Pingback: engineering jobs
Pingback: Faculty Regulations
Pingback: Mission of the Faculty of Computer Science
Pingback: Faculty of Engineering
Pingback: MBA in FUE
Pingback: Entrance exams for future university
Pingback: خطابات توصية لجامعة المستقبل
Pingback: Entrance exams for future university
Pingback: Comment s'appelle celui qui aime faire l'amour viagra vente libre pays
Pingback: Comment s'appelle les trois grandes familles d'instruments acheter du cialis
Pingback: 112 mg synthroid | Dry and hoarse cough that persists for an extended period can be a sign of thyroid deficiency
Pingback: Can cholesterol levels be improved through consuming fermented soy products like tempeh or miso - lipitor price comparison
Pingback: Can I drink alcohol 3 days after antibiotics?
Pingback: Which yogurt has most probiotics?
Pingback: Is it OK to take painkillers with antibiotics?
Pingback: What are 2 problems with antibiotics?
Pingback: Comment bander avec du Coca levitra 20 mg prix
Pingback: Quel est l'animal qui fait le plus lamour | viagra naturel
Pingback: Est-ce que le bebe pleure dans le ventre generique cialis en pharmacie
Pingback: Can walking everyday flatten your stomach
Pingback: Is zinc Good for erectile dysfunction: vidalista 20 price
Pingback: How can I regain erectile strength - vidalista 40
Pingback: Increased susceptibility to infections, such as frequent colds or respiratory illnesses, may indicate an underactive thyroid?
Pingback: What is the success rate of intrauterine insemination (IUI) in treating female infertility?
Pingback: Are there any specific mind-body interventions, such as fertility visualization or positive affirmations, that support women during fertility treatment cycles?
Pingback: What are the benefits of consuming a diet rich in antioxidants like vitamin C and E for heart health
Pingback: Can cholesterol levels be reduced by consuming herbal teas like hibiscus or green tea
Pingback: How do you know she's a player - Priligy 30 mg tablet
Pingback: How can I be special in bed - 25 mg viagra cost
Pingback: مجلة المستقبل للعلوم الاجتماعية
Pingback: الإرشاد الاكاديمي
Pingback: Higher education in public administration
Pingback: Get in Touch with Faculty of pharmacy
Pingback: كم عدد سنوات كلية الصيدلة
Pingback: علم الأحياء الدقيقة والمناعة
Pingback: Oral biology and oral pathology department
Pingback: What is the most common method used for the detection of parasitic diseases?
Pingback: هندسة البترول
Pingback: MBA degree Cairo
Pingback: Cybersecurity
Pingback: Where did syphilis come from?
Pingback: Faculty of Computers and Information
Pingback: Comment un homme embrasse quand il est amoureux viagra naturel puissant et rapide
Pingback: Prof. Hesham Arafat
Pingback: fue
Pingback: Inhaler and meditation: The benefits for your lungs and mind ventolin hfa recall
Pingback: The American Cancer Society recommends mammograms every two years for women between the ages of 55 and 74. Nolvadex Tamoxifen
Pingback: duricef 500 mg generic | How can I restore my liver health
Pingback: How do you know a girl feels for you levitra ed
Pingback: order amoxil generic | Will 111 give me antibiotics
Pingback: What over the counter drugs are suitable for relieving indigestion best over the counter sleep aid
Pingback: How do I overcome not getting hard - sildenafil 100mg uk
Pingback: How do I know my gut is healing | plaquenil 200 mg espaГ±ol
Pingback: Can too many antibiotics cause harm - stromectol for pinworms
Pingback: What is the most common inhaler for asthma - ventolin online
Pingback: Medications and Sports Performance: Unlocking Athletic Potential | over the counter anti inflammaroty drugs for dogs
Pingback: hydroxychloroquine sulfate 200mg prices
Pingback: How many rounds can a woman go
Pingback: Can a bacterial infection clear up by itself - plaquenil generic
Pingback: Are online pharmacies required to have a licensed pharmacist on staff
Pingback: ghaziabad escorts
Pingback: Can your liver heal from alcohol?
Pingback: What happens if you start an antibiotics and don't need them stromectol dosage?
Pingback: What lack of vitamin causes fatigue ivermectin tablets?
Pingback: What is the best food to eat when taking antibiotics?
Pingback: Can antibiotics be used for lobar pneumonia ivermectin?
Pingback: How do I know my gut is healing stromectol 3mg?
Pingback: How can I protect my liver from alcohol stromectol 12 mg?
Pingback: Can antibiotics prevent infection in refugees can you buy stromectol over the counter?
Pingback: How do you get rid of nausea from antibiotics stromectol over the counter?
Pingback: Can antibiotics cause tendonitis ivermectin for dogs dosage chart?
Pingback: https://www.kooky.domains/post/exploring-the-potential-of-web3-domains-for-decentralized-applications
Pingback: https://www.kooky.domains/post/greater-autonomy-and-control-with-web3-domains
Pingback: How do I know if I have a parasitic infection ivermectin?
Pingback: Ethical technology practices
Pingback: Executive MBA program in Cairo
Pingback: Executive MBA program in Cairo
Pingback: Future University Egypt business programs
Pingback: منح ماجستير إدارة الأعمال في مصر
Pingback: What is stroke level blood pressure ivermectin stromectol?
Pingback: What is the difference between a puffer and an inhaler symbicort side effects?
Pingback: Can I drink water after using an inhaler?
Pingback: What drink is good for asthma?
Pingback: How do you open your airways without an inhaler?
Pingback: What does asthma do to your body ventolin inhaler?
Pingback: health canada controlled drugs and substances?
Pingback: study pharmacy online free?
Pingback: Attendance Regulations faculty of pharmacy
Pingback: فرص العمل لكلية الصيدلة
Pingback: Can I take turmeric while on antibiotics?
Pingback: Get in Touch with Faculty of Oral and Dental Medicine
Pingback: Dental clinics
Pingback: What's best to eat with antibiotics get Azithromycin over counter?
Pingback: Can bacterial diseases be transmitted through animal bites Azithromycin cost?
Pingback: What are the 3 pillars of quality??
Pingback: Minister of Petroleum and Mineral Resources
Pingback: fue
Pingback: best university in egypt
Pingback: fue
Pingback: MBA
Pingback: What makes a woman more wet in bed??
Pingback: What happens to your brain when you see your ex??
Pingback: How do I make my boyfriend feel worth it??
Pingback: Which position helps to last longer Buy cialis online canada??
Pingback: What are the effects of chronic use of inhalants on erectile function in young men??
Pingback: How do you make your ex miss you over text??
Pingback: Can impotent give birth??
Pingback: However, it is important to use these products as directed and talk to a healthcare provider before use to ensure they are safe and effective.?
Pingback: The starting dose for Priligy is typically 30 mg, which can be increased to 60 mg if necessary.?
Pingback: Maillot de football
Pingback: Maillot de football
Pingback: Maillot de football
Pingback: Maillot de football
Pingback: Maillot de football
Pingback: Maillot de football
Pingback: Can antibiotics be used for fungal nail infections??
Pingback: Maillot de football
Pingback: Maillot de football
Pingback: Maillot de football
Pingback: Maillot de football
Pingback: Maillot de football
Pingback: Maillot de football
Pingback: Maillot de football
Pingback: Maillot de football
Pingback: Can antibiotics be used to treat viral infections??
Pingback: SEOSolutionVIP Fiverr
Pingback: SEOSolutionVIP Fiverr
Pingback: SEOSolutionVIP Fiverr
Pingback: SEOSolutionVIP Fiverr
Pingback: strisce led corridoio
Pingback: binario luci led
Pingback: lampadari sospensione
Pingback: challenge sportif
Pingback: taijutsu
Pingback: bodytones
Pingback: glucofort
Pingback: lean biome
Pingback: prostadine
Pingback: metanail serum pro
Pingback: Fiverr Earn
Pingback: Fiverr Earn
Pingback: Fiverr Earn
Pingback: Fiverr Earn
Pingback: Fiverr Earn
Pingback: Fiverr Earn
Pingback: Fiverr Earn
Pingback: Fiverr Earn
Pingback: Fiverr Earn
Pingback: Fiverr Earn
Pingback: 5 anni di garanzia profilo led soffitto
Pingback: fiverrearn.com
Pingback: fiverrearn.com
Pingback: fiverrearn.com
Pingback: fiverrearn.com
Pingback: fiverrearn.com
Pingback: fiverrearn.com
Pingback: Advance-Esthetic LLC
Pingback: Advance-Esthetic LLC
Pingback: fiverrearn.com
Pingback: fiverrearn.com
Pingback: syarat daftar syarikat sdn bhd ssm
Pingback: fiverrearn.com
Pingback: ikaria lean belly juice mediprime
Pingback: prostadine
Pingback: 3pl Broker
Pingback: frenchies in houston
Pingback: fabricante de ropa
Pingback: What is the link between erectile dysfunction and depression buy Cenforce 50mg sale??
Pingback: fiverrearn.com
Pingback: french bulldog puppies
Pingback: Unlocking the Potential of Regenerative Medicine through Innovative Drugs fildena 50mg over the counter.
Pingback: fiverrearn.com
Pingback: fiverrearn.com
Pingback: fiverrearn.com
Pingback: french bulldog puppies for sale sacramento
Pingback: Gynecologic Cancers - Early Detection and Treatment ivermectin 12mg
Pingback: is coconut oil good for french bulldogs
Pingback: goldendoodle kennel club
Pingback: texas heeler vs blue heeler
Pingback: aussiechon puppies
Pingback: bernedoodle
Pingback: Where are babies inside a woman Cenforce 100mg usa?
Pingback: seo in United States
Pingback: SEO in Jordan
Pingback: ooohd3.ru
Pingback: Can guys last for an hour cost of vardenafil?
Pingback: Digital Marketing
Pingback: sitemap
Pingback: Affordable Piano Movers
Pingback: Short-term Piano Storage
Pingback: Top university in Egypt
Pingback: Top university in Egypt
Pingback: Top university in Egypt
Pingback: Private universities in Egypt
Pingback: Private universities in Egypt
Pingback: isla mujeres rental
Pingback: french bulldog
Pingback: french bulldog puppy for sale
Pingback: lilac sable french bulldog
Pingback: crypto news
Pingback: vietnam visa requirements for us citizens
Pingback: frenchie jewelry
Pingback: Medications - Addressing Mental Health Stigma Head-On vidalista 40mg?
Pingback: i.8ua.ru
Pingback: miniature frenchie for sale
Pingback: Google Rezensionen löschen lassen
Pingback: Google Bewertungen löschen lassen
Pingback: Medications and Lifestyle Changes - The Key to Optimal Health prix priligy 60 mg?
Pingback: clima hoy new york
Pingback: clima birmingham
Pingback: mini french bulldog for sale
Pingback: #file_links[C:\spam\yahoo\TXTmeds.txt,1,N] #file_links[C:\spam\yahoo\ventolin.txt,1,N?
Pingback: french bulldog for sale texas
Pingback: Advances in Proton Therapy for Cancer Treatment stromectol in uk?
Pingback: Children jewellery
Pingback: Medications and Women's Hormonal Health - Balancing Cycles, Empowering Lives Cenforce 50mg without prescription?
Pingback: future university
Pingback: future university
Pingback: future university
Pingback: Medications - Empowering Patients to Take Control of Their Health order lasix 40mg without prescription?
Pingback: LORDFILM
Pingback: renting golf cart isla mujeres
Pingback: houston French bulldog
Pingback: multisbo link alternatif
Pingback: rent golf cart isla mujeres
Pingback: Can two mothers have a baby what is Cenforce 100?