zablanc / rapturexml Goto Github PK
View Code? Open in Web Editor NEWA simple, sensible, block-based XML API for iOS and Mac development.
Home Page: http://raptureinvenice.com
License: MIT License
A simple, sensible, block-based XML API for iOS and Mac development.
Home Page: http://raptureinvenice.com
License: MIT License
I understand that a period is valid character in an XML element tag. Short of doing a replaceOccurrencesOfString on the entire XML prior to parsing, there should be support to escape a period in the xml query ie:
[resultXML child:@"SYSTEM\.DATE"]
I want to add RaptureXML to the CocoaPods package manager repo.
CocoaPods is a tool for managing dependencies for OSX and iOS Xcode projects and provides a central repository for iOS/OSX libraries. This makes adding libraries to a project and updating them extremely easy and it will help users to resolve dependencies of the libraries they use.
However, RaptureXML doesn't have any version tags. I will add the current HEAD as version 0.0.1, but a version tag will make dependency resolution much easier.
Semantic version tags (instead of plain commit hashes/revisions) allow for resolution of cross-dependencies.
In case you didn’t know this yet; you can tag the current HEAD as, for instance, version 1.0.0, like so:
$ git tag -a 1.0.0 -m "Tag release 1.0.0"
$ git push --tags
It would be awesome if you added a license file for CocoaPods which likes to be able to tell users the license of the library ahead of time. All you'd have to do is add a LICENSE*.*
file to the root of the project and add a new podspec for the new tag.
Thanks!
I get for the pod:
Undefined symbols for architecture i386:
"_xmlDocGetRootElement", referenced from:
-[RXMLElement initFromXMLString:encoding:] in libPods.a(RXMLElement.o)
-[RXMLElement initFromXMLFile:] in libPods.a(RXMLElement.o)
-[RXMLElement initFromXMLFile:fileExtension:] in libPods.a(RXMLElement.o)
-[RXMLElement initFromURL:] in libPods.a(RXMLElement.o)
-[RXMLElement initFromXMLData:] in libPods.a(RXMLElement.o)
"_xmlFree", referenced from:
-[RXMLElement text] in libPods.a(RXMLElement.o)
"_xmlFreeDoc", referenced from:
-[RXMLElement initFromXMLString:encoding:] in libPods.a(RXMLElement.o)
-[RXMLElement initFromXMLFile:] in libPods.a(RXMLElement.o)
-[RXMLElement initFromXMLFile:fileExtension:] in libPods.a(RXMLElement.o)
-[RXMLElement initFromURL:] in libPods.a(RXMLElement.o)
-[RXMLElement initFromXMLData:] in libPods.a(RXMLElement.o)
-[RXMLElement dealloc] in libPods.a(RXMLElement.o)
Do you know how to fix it?
Hi all,
I'm parsing an RSS feed that looks like this for the items :
<item>
<id>29</id>
<ns:zone lang="fr">Centre</ns:zone>
<ns:zone lang="de">Zentrum</ns:zone>
</item>
if I make this :
NSArray* items = [[rss child:@"channel"] children:@"item"];
for (RXMLElement *e in items) {
}
I only get the first item with attribute lang ="fr".
What should I do to have the value of the lang="de" ?
Any idea ? (PS : I'm not the owner of the RSS, i can't change it)
Thanks a lot !
Arnaud
How convert this rootXML.tag --> @"team" in swift ??
tks
If I use use_frameworks!
with Cocoapods and include the RaptureXML pod, it fails to compile. See CocoaPods/CocoaPods#3654 (comment)
This can be recreated by setting up a new single view project and adding the RaptureXML pod with use_frameworks!
set in the pod.
On that linked issue, while we wait for Apple to provide the module map, they suggest defining your own for libxml in your Cocoapod like this:
https://github.com/neonichu/SQLite.swift/blob/master/SQLite.swift.podspec#L25-L33
Off the box XCode compilation enforces static analysis, that triggers issues in TBXML source files ("Dereference of null pointer" and "The left operand of '&' is a garbage value").
I have 22 errors and it looks like they are all due to ARC being on. Is there a way to change all of the "return [[[RXMLElement alloc] initFromXMLData:data] autorelease];" like returns to arc friendly returns?
How to work with tags itunes:summarytext</itunes:summary>?
These following codes does not work:
episode.summary = [item child:@"summary" inNamespace:@"itunes"].text;
or
episode.summary = [item child:@"summary:itunes"].text;
RaptureXML works flawlessly Mac, but it's listed in CocoaPods as iOS only.
Please add the necessary metadata for Mac support in Cocoapods.
Given the following XML (not escaped - edit issue to see the XML):
<xml_api_reply version="1">
<forecast_information>
<postal_code data="paris"/>
<latitude_e6 data=""/>
<longitude_e6 data=""/>
<forecast_date data="2012-07-12"/>
<current_date_time data="2012-07-12 13:56:00 +0000"/>
<unit_system data="US"/>
</forecast_information>
</xml_api_reply>
Rapture is returning null for the city with this code (category on RaptureXML):
(PFWeatherReport*) asWeatherReport {
if (![self.tag isEqualToString:@"weather"]) {
[NSException raise:NSInvalidArgumentException format:@"Element is not 'weather'."];
}
NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd"];
//CITY IS COMING BACK AS NULL!!!!!
NSString* city = [[self child:@"forecast_information.city"] attribute:@"data"];
NSDate* forecastDate =
[dateFormatter dateFromString:[[self child:@"forecast_information.forecast_date"] attribute:@"data"]];
PFCurrentConditions* currentConditions = [[self child:@"current_conditions"] asCurrentConditions];
NSMutableArray* forecast = [NSMutableArray arrayWithCapacity:5];
for (RXMLElement* e in [self children:@"forecast_conditions"]) {
[forecast addObject:[e asForecastConditions]];
}
return [PFWeatherReport reportWithCity:city date:forecastDate currentConditions:currentConditions
forecast:forecast];
}
Hello,
I really enjoy using RaptureXML. Thank you.
Is there a way to iterate without using block?
I would like to do iteration inside subclass of NSOperation for concurrency.
However, if I use block, I will not be able to cancel iteration process.
Thanks for any pointers you can provide.
RaptureXML doesn't parse property when the tag has colon in it, such as itunes:duration.
It would be really useful for me if RXMLElements had some knowledge of their index/order within a parent element.
Hi,
I have ported rapture xml to Java on top of the java TBXML.
Mind if I upload to my github.
hi i have a 50 mb xml file
im the ios simulator it work ok
but in a real ipad it crash
how much big a xml could be? or what could i dp?
Hi
I am trying to include RaptureXML through Cocoapods. My Podfile look like:
pod 'RaptureXML', '~> 1.0.1'
My project is a "Static Library" project. I get following error:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: -dynamic not specified the following flags are invalid: -ObjC
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: can't locate file for: -lxml2
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: -lxml2 is not an object file (not allowed in a library)
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: can't locate file for: -lz
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: -lz is not an object file (not allowed in a library)
There is following added to "Pods.debug.xcconfig":
OTHER_LDFLAGS = -l"xml2" -l"z"
If I remove above two libraries from "OTHER_LDFLAGS", it compiles fine. But these two are specified in "RaptureXML" Podspec.
Any help is appreciated.
Thanks
Gaurav Agarwal
I have an iOS app that uses RaptureXML, which works flawlessly in Debug mode. However, when I target compilation for Release, I run into issues.
My app interfaces with an XML API, so I wrote a "call" function that uses RaptureXML to retrieve an RXMLElement
, which is returned by the function. Here is this function used in the view controller:
...
RXMLElement* add_test = [api call:@"accountAdd" withParams:add_params];
NSLog(@"add_test result: %@", add_test);
...
In Release mode, that NSLog() shows that add_test is blank. I put in a breakpoint to examine, and I see that add_test
does not have a memory address:
Ok, so there must be something with the call
function. However, here is the code in the call function:
- (RXMLElement*) call:(NSString*) api_name withParams:(NSString*) params withResult:(BOOL) result{
...
RXMLElement* result_base = [base child:@"Result"];
if([api_name isEqualToString:@"accountAdd"]){
NSLog(@"add_test result from call: %@", result_base);
}
return result_base;
}
Above, I NSLog() result_base
before it is returned- and when this happens, I see the XML text of the object!
So the RXMLElement*
does exist before it is returned, but when I try to use it after the function has been called, it is deallocated. I can only guess that for some compiler optimization for Release mode, the object is being destroyed.
My question is, (1) Is there some way to copy RXMLElement*
objects so they are not destroyed when the parent "document" goes out of scope, or (2) is there some other way I can keep the object from being destroyed?
Thank you very much for creating such a great library.
how can i get parent node
I have the following XML:
'
'
How can I iterate through the array of mapped items and get pertaining values for name and location?
Maybe I'm missing something, but is it possible to filter by attribute without using xpath? I want to be able to retrieve an element, then retrieve children of that element that have a particular attribute value. I can almost do it with xpath, but since all the queries seem to be from the document root I can't narrow my search to a particular element.
I'm envisioning something like [element children:@"otherElement[attributeName='attributeValue']"]
If it's possible to scope xpath queries to a particular parent node that would solve my problem too.
I'm using the head of RaptureXML through CocoaPods and I'm seeing odd behaviors with the SAFE_ARC_AUTORELEASE
macro. My project uses ARC, but somehow my RXMLElement objects keep getting prematuraly released.
Issue is fixed if I remove SAFE_ARC_AUTORELEASE
completely.
I noticed that the podspec doesn't have requires_arc
property so I'm thinking this might be the source of the problem. That being said I'm not sure what the right fix is. Perhaps ARC has been out long enough that the master branch can be ARC only?
Alternatively, anyone who's not using ARC in their project can add an ARC-only lib by adding the -fobjc-arc
compiler flags to the .m files.
It would be nice if there was a CocoaPods (http://cocoapods.org/) spec for RaptureXML.
Hi!
I love RaptureXML, but I am having massive problems with leaks and I dont understand why they are happening.
I posted this to StackOverflow today:
http://stackoverflow.com/questions/10487030/leaks-when-using-rapturexml-with-xpath
Might be interesting for this board as well.
Badly formed XML should throw?
Steps to Reproduce:
RXMLElement* element = [RXMLElement elementFromXMLString:@"</xml"]; //Missing closing tag.
Result:
EXEC_BAD_ACCESS
Expected:
Throws RXMLBadlyFormedException
Hi All,
I have an XML file represented like this, that I would like to parse recursively, because the indentation level is quite unlimited :
https://gist.github.com/axelline/865345b3eeadefad0e09
Any idea on how to achieve this with RaptureXML ?
Thanks a lot for your help !
some places i think should add the word autorelease
Would you care to add your code to Ray Wenderlich's XML Parser comparison? It would be amazing to see real numbers – especially because you claim libxml2 to be faster than TBXML, which is not what the performance shootout on Ray's site claims.
Thanks for your project!
Is there any solutions to wait for the ITERATE methods to finish?
I have something like this:
[element iterate:@"*" usingBlock:^(RXMLElement * blk) {
if ([blk.tag isEqualToString:STATUS_TAGNAME]) {
[subelements addObject:blk];
}
}];
if (subelements && ([subelements count] > 0)) {
RXMLElement *subElement = (RXMLElement*)[subelements objectAtIndex:0];
status = subElement.textAsInt;
}
And I need to the ARRAY subelements to be completed.
Any sugestions?
Many thanks!
What is the license that you have on this. I don't see on anywhere on your site or in the project.
PS you're the man.
The 'xml' property on the RXMLElement class is available on master, but was added after the last tag in the podspec.
In order to use the 'xml' property, this repo will need an updated tag (say, 1.0.2) and the podspec will also need to be updated to reference that tag.
Until then, it is not possible to integrate with the latest version of RaptureXML using CocoaPods.
I will fork the repo to update the podspec on my end and will submit a pull request. However, this will update the podspec and not the tags on the repo. (I don't believe there's a way to generate a pull request that says "apply this tag to the master branch".)
Feel free to reach out to me directly for more info on this issue.
And thanks for all your work on RaptureXML. It's been a great resource for us!
Calling -[RXMLElement text] on any child node in my parsed XML properly returns whatever text was contained in the tag. But when I call -[RXMLElement text] on a non-child node in my XML, I get a null string. I was expecting to get all contained XML.
For example, with the following XML:
<topLevel>
<secondLevel>
<thirdLevel>
Here is some text
</thirdLevel>
</secondLevel>
</topLevel>
[thirdLevelElement text] returns "Here is some text", while [secondLevelElement text] and [topLevelElement text] return null. Am I wrong to expect XML to be returned through this method? Or is this a bug?
Finally, the important question: Is there a way to retrieve the XML contained within a given tag?
Thanks.
Very small thing, but made me a lose a bit of time, so I figured i'd report it so it wouldn't happen to other noobs:
[rootXML iterateWithRootXPath:@"//player[number='5']" usingBlock: ^(RXMLElement *player) {
NSLog(@"Player #5: %@", [player child:@"name"]);
}];
where it reads [number='5'], it should read [@Number='5']. It's missing the "@".
Great work though. Loving RaptureXML!
Great work with this project, it is very useful. I do have a question:
In your example, you show how I can get all players in the tag:
NSArray *rxmlIndividualPlayers = [rxmlPlayers children:@"player"];
My question would be, how do I get all players and the coach from the tag?
I tried using a wildcard, but it didn't work:
NSArray rxmlIndividualPlayers = [rxmlPlayers children:@""];
Thanks,
Sorry, don't know how to post html tag here.
I need some help here, I want to parse the xml inside one xml and get the text of the node, but I cannot get it working, my xml looks like below:
2 <title type="text">Marina</title> Marina/d:Area 1.2911/d:Latitude 103.8575/d:Longitude 0/d:Distance /m:propertiesPlease tell me how to get the text of m:Area by using RaptureXML? really appreciate your help, thanks.
Thanks for the creating and sharing this library. This is a very minor issue, but thought you might like to know...
If you look at the first code sample in the README (under "Why do we need another XML library?"):
[rootXML iterate:@"players.player" usingBlock: ^(RXMLElement *e) {
NSLog(@"Player #%@: %@ (%@)", [e attribute:@"number"], [e child:@"name"].text);
}];
The NSLog command has three %@
placeholders, but you are only providing two additional arguments. I'm guessing that you accidentally left out [e child:@"position"].text
?
Kudos for creating an awesome, super easy to use XML library!
One minor feature request:
Could you add a "stop" variable to the -[iterate:with:] method?
Like
[rootXML iterate:@"players.player" with: ^(RXMLElement *e, *stop) {
NSLog(@"Player #%@: %@ (%@)", [e attribute:@"number"], [e child:@"name"].text);
*stop = YES; // Similar to "break" in for loops
}];
Thanks for this great XML-Library, looks awesome. What would be even more awesome would be XPath-support for querying, possibly with the use of libxml. I might be willing to help, if you want to add this feature.
Really enjoying using Rapture so far.
Any way to iterate over the attributes of a node though? I'm looking for a way to get all attribute names and values of a node without having to know the names of the attributes ahead of time.
test case(Google weather API):
http://www.google.com/ig/api?hl=zh-cn&output=rss&weather=,,,30670000,104019996
/**
* Update xml node values that matching specified XPath with feeded new value list.
* Note that the new value list can contain only one item which will be used to
* replace all matching nodes in xml, or contain just enough values to replace all matching nodes.
*
* @param xpath
* @param nodeValue New value list, must have at least one item
*
* @return
*/
- (BOOL) updateXpath:(NSString*)xpath withNewNodeValues:(NSArray *)nodeValue {
xmlDocPtr doc = [self.xmlDoc doc];
xmlXPathContextPtr xpathCtx;
xmlXPathObjectPtr xpathObj;
/* Create xpath evaluation context */
xpathCtx = xmlXPathNewContext(doc);
if (NULL == xpathCtx) {
return NO;
}
/* Evaluate xpath expression */
xpathObj = xmlXPathEvalExpression((xmlChar *)[xpath cStringUsingEncoding:NSUTF8StringEncoding], xpathCtx);
if (NULL == xpathObj) {
xmlXPathFreeContext(xpathCtx);
return NO;
}
// Update
xmlNodeSetPtr nodes = xpathObj->nodesetval;
int size, i;
size = (nodes) ? nodes->nodeNr : 0;
if (size > 0 && size != [nodeValue count]) {
return NO;
}
/*
* NOTE: the nodes are processed in reverse order, i.e. reverse document
* order because xmlNodeSetContent can actually free up descendant
* of the node and such nodes may have been selected too ! Handling
* in reverse order ensure that descendant are accessed first, before
* they get removed. Mixing XPath and modifications on a tree must be
* done carefully !
*/
for(i = size - 1; i >= 0; i--) {
assert(nodes->nodeTab[i]);
xmlNodeSetContent(nodes->nodeTab[i], (xmlChar *)[nodeValue[i] cStringUsingEncoding:NSUTF8StringEncoding]);
/*
* All the elements returned by an XPath query are pointers to
* elements from the tree *except* namespace nodes where the XPath
* semantic is different from the implementation in libxml2 tree.
* As a result when a returned node set is freed when
* xmlXPathFreeObject() is called, that routine must check the
* element type. But node from the returned set may have been removed
* by xmlNodeSetContent() resulting in access to freed data.
* This can be exercised by running
* valgrind xpath2 test3.xml '//discarded' discarded
* There is 2 ways around it:
* - make a copy of the pointers to the nodes from the result set
* then call xmlXPathFreeObject() and then modify the nodes
* or
* - remove the reference to the modified nodes from the node set
* as they are processed, if they are not namespace nodes.
*/
if (nodes->nodeTab[i]->type != XML_NAMESPACE_DECL)
nodes->nodeTab[i] = NULL;
}
xmlXPathFreeContext(xpathCtx);
return YES;
}
xmlDocPtr doc = xmlReadMemory([data bytes], (int)[data length], "", nil, XML_PARSE_PEDANTIC);
Passing nil instead of the encoding in. . . .
When am trying to parse the remote XML file and get the images from it and view it as UIImageView. When i tried to call my remote XML file i got a warning and two errors as below,
'elementFromURL:' is deprecated
"_OBJC_CLASS_$_RXMLElement", referenced from:objc-class-ref in MyViewController.o ld: symbol(s) not found for architecture i386 clang: error: linker command failed with exit code 1 (use -v to see invocation)
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I am getting "Multiple methods named 'tag' found with mismatched result, parameter type or attributes" error in Xcode.
I am using tag property from IB and passing this in an IBAction using:
and this is probably getting confused with RXMLElement's own tag property:
@Property (nonatomic, readonly) NSString *tag;
Hey,
Nice work! It's proven to be a nice alternative to some of the other xml readers out there.
I'm having an issue with RaptureXML not parsing XPath selectors correctly on my XML. This issue doesn't occur when manually traversing with child and children selectors. My issue is the exact same as the one here: http://stackoverflow.com/questions/14331087/xpath-with-rapturexml-not-matching-nodes
I think the issue might have something to do with namespaces but I'm not sure how to fix that.
Any suggestions?
Thanks!
When I try to use some method with RXMLElement I have this error : [RXMLElement isEqualToString:]: unrecognized selector sent to instance 0x746ef20]
[RXMLElement intValue:]: unrecognized selector sent to instance 0x746ef20]
How can I fix it??
Thanks in advance
RXMLElement *rootXML = [RXMLElement elementFromURL:[NSURL URLWithString:my_url]];
Which params need to add ?
I'm using PocketSVG to load an SVG. It's powered by RaptureXML.
See the details of this problem here:
I can verify that the version of RaptureXML I'm using is 1.0.1.
If only some elements have namespace (I've replaced <> with _ here, since the editor will not try to interpret them):
ttl>15_/ttl_
atom:link href="http://feeds.bbci.co.uk/news/rss.xml" rel="self" type="application/rss+xml"/
item
title_Deadly Texas blast 'like tornado'/title_
and you are trying to use child:@"link" inNamespace:@"atom"
you will get crash at this piece of the code:
if (cur->type == XML_ELEMENT_NODE && !xmlStrcmp(cur->name, tagC) && !xmlStrcmp(cur->ns->href, namespaceC)) {
Because cur->ns for the most elements from the example above will be nil, and dereferencing it is an error.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.