Comments (7)
Perhaps check out http://leaks.wanari.com/2016/08/24/xml-parsing-swift/ ?
from swift-toolkit.
this shows some comparison to several XML Parsers https://swift.libhunt.com/categories/675-xml
from swift-toolkit.
It will be hard to find a full featured XML parser on iOS, especially in Swift. For what I know a lot of dev tend to use NSXMLParser provided by Apple. It does the job, but it doesn't provide a very high-level API. Most of the libs out there are wrapper around NSXMLParser. Except Fuzi which is based on libxml2 (XML parser written in C from the Gnome Project). Maybe we should give it a try.
I think r2-testapp-swift/#7 should be a good place to try a new XML parser. We can replace AEXML usage in NavigationDocumentParser class without any side effects.
from swift-toolkit.
libxml2 works very well, therefore Fuzi could be a win if it's sufficiently well written.
Looking at it, it implements namespaces, which is required, and xpath methods, which can be of great use (I can show you how to use it efficiently if needed). Apart from that, few doc available. It seems to implement a DOM API only.
-> Maybe NSXMLParser is not more complex to handle for our needs...
-> what do we do with the XML parser, apart feeding objects properties with XML content?
from swift-toolkit.
I didn't find any other use of AEXML in our code. So yes, we only use it to feed objects properties.
However, NSXMLParser only provides a SAX API. It could be at first a little more complex to implement and use. My understanding is SAX is better when parsing big files, because not all the document is loaded in memory. But, do we really need this feature? Did someone already noticed performance issue?
from swift-toolkit.
You're right about SAX, this is optimized for big files and the callback-style programming is not easy to grasp: a DOM parser with XPath support would be better (or with an xml-to-object mapping, but namespace compatible).
from swift-toolkit.
For your information: the TypeScript/NodeJS implementation uses declarative XML-Object mapping based on XPath. There is no imperative/procedural parsing of XML structures in the application code, the data model is simply annotated with XPath expressions relative to their parent context (or with JSON property expressions, in the case of webpub-manifest.json, media-overlay.json etc.). This is also how the Go implementation works, by the way.
Under the hood, an external library takes care of loading DOMs and resolving XPath expressions in order to dynamically create the in-memory equivalent data model (e.g. for package.opf, chapters.smil, navdoc.html, nav.ncx, encryption.xml, etc.)
There is obviously a runtime cost when loading large XML data sets, such as many large SMIL (Media Overlays) files, or large NavDocs (TOC). I stress-tested my implementation using a massive EPUB (Math content), which allowed me to identify a significant performance issue with the Xpath processor. I fixed this problem by coding a simple processor for a custom subset of Xpath, perfectly adequate for our use-case (i.e. XML-Object mapping, basic element and attribute matching). With this optimization, the performance gain was enormous! (in terms of both CPU and memory costs, which is important with NodeJS due to the pressure on the garbage collector).
Note that the current TypeScript/NodeJS implementation does not support XML serialisation, as there is no use-case for it. There is however full support for bi-directional JSON (de)serialisation, as JSON is both an input and output data format in the marshalling logic (e.g. read license.lcpl, write webpub-manifest.json)
from swift-toolkit.
Related Issues (20)
- Name collision caused by GCDWebServer dependency HOT 5
- Error"Error initializing db." HOT 13
- Nondeterministic loading issue with `EPUBNavigatorViewController` HOT 2
- [Feature] Add support for new LCP Profiles
- Logic behind the selected text information for remote server HOT 2
- Pagination after increasing the font size HOT 4
- [Bug] EditingActions like Define Lookup are not shown. HOT 1
- [develop] Locator href for exploded archive audiobook incorrectly starts with leading slash HOT 2
- [develop] Opening exploded archive audiobook inside App Group fails with `Publication.OpeningError.unsupportedFormat` in (Designed for iPad) Mac app HOT 9
- [Bug] Search Result Chapter Title HOT 6
- lcpl file which is pub format can't be open by publication.metadata.identifier is nil HOT 6
- `Navigator.go` results in misaligned view HOT 9
- [Bug] iOS Reader Search crashed with 4-5 character HOT 1
- [Bug] Expression is 'async' but is not marked with 'await' HOT 1
- iOS Text to Speech feature crashing HOT 1
- [Documentation] Locator -> Location -> progression and totalProgression properties calculation
- PDF in landscape mode HOT 1
- [Bug] iOS 17: Unable to add any `EditingAction`s to the selection menu HOT 3
- Does readium provide CFI of epub HOT 1
- [Bug] Text alignment setting doesn't work on some epubs. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swift-toolkit.