I would like to know some libraries in objective-C for xml parsing. I think it is a very common need, but I found limited resources for handling this task:
Google Code projects: TouchCode (TouchXML)
NSXMLParser
What is your best solution to work with XML in objective-C language? Please advice.
What is the solution that you have used for your product?
NSXMLParser is a stream-oriented class; you set it up and get delegate callbacks when it detects something. Usually this is not what you want to do, but can be much faster and lower memory.
TouchXML will parse the XML itself using libxml, and create an object tree for the entire XML structure. This allows you to easily access the contents of the XML tree, using manual traversal methods or basic XPaths (more sophisticated XPath support is planned).
It serves a narrow purpose, but if your goal is to parse untidy HTML, you might want to try a static library I started called TagScraper. It doesn't handle many/most XML/HTML entities correctly, but it could be pretty easily patched to. URL: http://github.com/searls/TagScraper
Its value is that it provides a simple XPath mechanism that hides the tidying/querying/assembling for you, and then it provides the parsed elements & attributes in a tree-like data structure of Tag.h nodes.
Related
Is there a way to get the raw XML text which another plugin has contributed to an extension point?
The normal way to access data that is contributed to an extension point is to use IConfigurationElement objects:
IConfigurationElement[] configElems = Platform.getExtensionRegistry()
.getConfigurationElementsFor(LANGUAGES_EXTENTION_POINT_ID);
But I already have JAXB parser for the kind of data that is contributed to this extension point. I'd like to use that one instead of Eclipse's classes.
EDIT 1: An alternative would be to use some kind of Eclipse-configuratoin-to-JAXB bridge library. But I don't find any.
EDIT 2: It's probably possible to find the plugin.xml of the contributing plug-in and read that manually... Probably not a good idea.
EDIT 3: I think I will do this: Instead of contributing the data directly clients get to give a file name. I then read that file using my old parser.
No, I don't see anything that would give you the XML.
getConfigurationElementsFor gives you information extracted from many different plugin.xml files so it is not clear what XML could be returned anyway.
org.eclipse.core.internal.registry.ExtensionRegistry is the extension registry implementation, but a lot of the information that uses comes from org.eclipse.core.internal.registry.RegistryObjectManager.
I am trying to parse a xml document in my resource folder in my project. The project is a cocos2D project and i am trying to create some type of method to parse the xml file to load levels for my game.
What would be the best way to parse the document? And an example would be great.
You can use any Objective-c XML parser in cocos2d
I suggest you to use TBXML
But instead of having data in your xml, you should save it into plist and use it directly.
If
1) the speed of parsing and
2) the convenience of retrieving the data from xml file is important
3) you do not mind C++ interface
then the best parser for you is open source:
http://code.google.com/p/pugixml/
pugixml is a light-weight C++ XML processing library. It features:
• DOM-like interface with rich traversal/modification capabilities
• Extremely fast non-validating XML parser which constructs the DOM tree from an XML file/buffer
• XPath 1.0 implementation for complex data-driven tree queries
• Full Unicode support with Unicode interface variants and automatic encoding conversions
The library is extremely portable and easy to integrate and use.
I have tested both speed and memory usage against other parsers and use it for last 5 years.
Documentation is here: http://pugixml.googlecode.com/svn/tags/latest/docs/quickstart.html
Even the post is old, I write the solution here to help other people like me in future. Solution is simple:
- Step 1: Read file content by using FileUtils
- Step 2: Parse file content to tinyxml2 (supported
I have tried and success on loading and reading XML file in cocos2d 3.8
#include "tinyxml2/tinyxml2.h"
auto s = FileUtils::getInstance()->getStringFromFile("data.xml");
tinyxml2::XMLDocument *pDoc = new tinyxml2::XMLDocument();
tinyxml2::XMLError errorId = pDoc->Parse(s.c_str(), s.size());
if (errorId == 0) {
// Write your code here
}
data.xml is placed in Resource folder.
Please read http://www.cocos2d-x.org/docs/manual/framework/native/v3/xml-parse/zhparse/zh to know how to iterate tinyxml2 XMLDocument.
Note that you can not use the tutorial in this link to load from file. It always return ERROR_FILE_NOT_FOUND.
I have two options in front of me for parsing really fat XML file,
TouchXML
GDataXML
It's lot of work to do because XML file is very huge. I thought of asking people who have already worked with these parsers.
Which one is better for fat XML files?
I found a blog post which says that TouchXML does not edit/save XML files whereas GDataXML has that feature. What exactly do they mean by edit/save XML file feature?
Lets see if I can answer your questions:
Which one is better for fat XML files? The answer is neither. Both are DOM parsers, which actually load the entire document into memory to make queries faster. If you're parsing a large file, you're better off going with a SAX parser, such as the built-in NSXMLParser, or even the SAX-based version of libxml2.
What exactly do they mean by edit/save XML file feature? Well, suppose you have a XML file that has your app's settings in it. If you open up that file and make changes, you're going to want to save them, right? That's where the writing comes in. The parsers that allow writing let you save the representation of the xml file in the memory into an actual file that can be written to disk.
I'm working on a project for the iPad, I need to read and write to an xml file, which is also used by the counter part of the application in windows.
The problem that I have is that I've been looking around but I haven't found a way to modify an element or attribute in an xml, without having to build the whole xml again.
I saw this other post, which is basically the same problem that I have, and I also end it up in the same point as the person asking the question, NSXMLParser and TouchXML are read only and do not allowed me to modify my xml.
Any other suggestion about what can I use?
Thanks!
We've got a large codebase of Java (with a smattering of Groovy mixed in) that, by and large, has no javadocs written for it.
However, much of the code is reasonably well documented in "old-school" comments scattered throughout the body.
We're now on something of a push to try and get things documented a little better - Javadocs are now being generated on a regular basis, for example. As a stopgap measure, it would be really nice if javadoc would "scrape" the body of the class (or function, or whatever) and toss all the comments within into a "stub" javadoc.
Is there a way to do that?
Sounds like a bad idea, given that javadocs typically describe purpose and usage of elements, and code body comments are (or should be) about the details of implementation.
But if you must, you clearly need to write your own custom doclet that works in concert with a java source file parser (either 3rd party or your own). For each processed class, you would first run the parser on the source file for that given java class and harvest the internal comments, and then augment the (standard) html produced by the (standard) doclet to add the code comments.
A possible strategy that would help make the resultant javadocs sensible would be to include a given method's internal comments for the javadoc for that method. Just use a 'pre' closure and append the parsed comments of the method at the end of the generic javadoc html.