Comments (15)
I was using Xcode 6.1 GM2 (6A1046a), and there's new option "failable initializers" (https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Initialization.html#//apple_ref/doc/uid/TP40014097-CH18-XID_339)
so NSXMLParser(data: xmlData) returns optional, therefore it can be used in a conditional binding.
So, it should work in the next release of Xcode without any modification.
from aexml.
I am using Xcode 6.1 (6A1052C) which is the most recent released two days ago.
Apple link in devcenter is broken, though this release can be found at this link:
https://developer.apple.com/downloads/index.action
So, it appears it will not work in the release after the one you used to test.
Brian.
On Oct 19, 2014, at 4:20 PM, Marko Tadić [email protected] wrote:
I was using Xcode 6.1 GM2 (6A1046a), and there's new option "failable initializers" (https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Initialization.html#//apple_ref/doc/uid/TP40014097-CH18-XID_339 https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Initialization.html#//apple_ref/doc/uid/TP40014097-CH18-XID_339)
so NSXMLParser(data: xmlData) returns optional, therefore it can be used in a conditional binding.
So, it should work in the next release of Xcode without any modification.—
Reply to this email directly or view it on GitHub #1 (comment).
from aexml.
Oh, then I'm not up to date... :)
I'll take a look at it and fix it tomorrow, thanks for notice.
Marko
from aexml.
I just removed conditional binding because NSXMLParser initWithData: is no longer failable initializer.
It now works on Xcode 6.1 (6A1052C).
from aexml.
Thanks
On Oct 20, 2014, at 11:45 AM, Marko Tadić [email protected] wrote:
I just removed conditional binding because NSXMLParser initWithData: is no longer failable initializer.
It now works on Xcode 6.1 (6A1052C).—
Reply to this email directly or view it on GitHub.
from aexml.
To make debug easier for users, I suggest using something the following. Here I create a datastring, then dump the contents in the debug window using NSLog. I use this instead of println, as println() does not appear to process \n as does NSLog. This allows display of the XML prior to sending to your parser to easily validate what is there.
May want to place this in tryRemoteXML as well.
Thanks.
brian.
@IBAction func readXML(sender: UIBarButtonItem) {
resetTextField()
if let xmlPath = NSBundle.mainBundle().pathForResource("plant_catalog", ofType: "xml") {
let xmlData = NSData(contentsOfFile: xmlPath)
var datastring: String? = NSString(data:xmlData!, encoding:NSUTF8StringEncoding)
NSLog("%@", datastring!)
var error: NSError?
if let doc = AEXMLDocument(data: xmlData, error: &error) {
var parsedText = String()
// parse known structure
for plant in doc["CATALOG"]["PLANT"].all {
parsedText += plant["COMMON"].value + "\n"
}
textView.text = parsedText
} else {
let err = "description: \(error?.localizedDescription)\ninfo: \(error?.userInfo)"
textView.text = err
}
}
}
On Oct 20, 2014, at 11:45 AM, Marko Tadić [email protected] wrote:
—
Reply to this email directly or view it on GitHub #1 (comment).
from aexml.
How can I obtain the count of a specific XML item, e.g. in your example what is the best/quickest way to get the count of items:
doc["CATALOG"]["PLANT”]
I can do this:
let count = 0
for plant in doc["CATALOG"]["PLANT"].all {
count += 1
}
I tried this, though does not work:
let count = doc["CATALOG”].count
suggestions?
brian.
On Oct 20, 2014, at 11:45 AM, Marko Tadić [email protected] wrote:
I just removed conditional binding because NSXMLParser initWithData: is no longer failable initializer.
It now works on Xcode 6.1 (6A1052C).—
Reply to this email directly or view it on GitHub #1 (comment).
from aexml.
this works:
let count = (tours["index"]["tour"].all).count
May want to include an example of this in your example file.
brian.
On Oct 31, 2014, at 9:36 AM, Balthazor Brian [email protected] wrote:
How can I obtain the count of a specific XML item, e.g. in your example what is the best/quickest way to get the count of items:
doc["CATALOG"]["PLANT”]
I can do this:
let count = 0
for plant in doc["CATALOG"]["PLANT"].all {
count += 1
}I tried this, though does not work:
let count = doc["CATALOG”].count
suggestions?
brian.
On Oct 20, 2014, at 11:45 AM, Marko Tadić <[email protected] mailto:[email protected]> wrote:
I just removed conditional binding because NSXMLParser initWithData: is no longer failable initializer.
It now works on Xcode 6.1 (6A1052C).—
Reply to this email directly or view it on GitHub #1 (comment).
from aexml.
Hi Brian,
properties 'children' and 'all' on AEXMLElement are of type Array, so it's logical that you can use 'count' on these.
You could also do it like this:
let count = tours["index"].children.count
or if "index" is your root element, like this:
let count = tours.rootElement.children.count
On the other side, I could write some documentation of all public properties and functions and add it to readme, so you don't have to look for that in source code.
Marko
from aexml.
Ok, thanks. I will try each of these, as they are cleaner.
On Nov 1, 2014, at 2:25 PM, Marko Tadić [email protected] wrote:
Hi Brian,
properties 'children' and 'all' on AEXMLElement are of type Array, so it's logical that you can use 'count' on these.
You could also do it like this:
let count = tours["index"].children.count
or if "index" is your root element, like this:
let count = tours.rootElement.children.count
On the other side, I could write some documentation of all public properties and functions and add it to readme, so you don't have to look for that in source code.
Marko
—
Reply to this email directly or view it on GitHub #1 (comment).
from aexml.
marko,
First, swap the following into plant_catalog.xml in your project
brian [email protected] Tourx http://www.appsird.com/testand in readXML after setting doc have:
let count = (doc["index"]["tour"].all).count
which returns the value of 1, which is correct. Though, if you then make the plant_catalog.xml file
brian [email protected]so, there are no tour tags in this case. now, when running this:
let count = (doc["index"]["tour"].all).count
The value 1 is also returned (though there are no tour tags). You will see the value. and if you have:
for plant in doc["index"]["tour"].all {
let y = plant.name
let x = plant["name"].value
println("tour: \(x)")
}
The value of x is “element not found". and value of plant.name is “error"
I cannot find an elegant way to determine if a tag exists. for now, I will check that plant.value == “error” to determine no tours exist.
So, it appears your structure works well if all tags are there, though generates an error when not. And .count does not appear to produce proper results for myself.
Brian.
On Nov 2, 2014, at 8:39 AM, Balthazor Brian [email protected] wrote:
Ok, thanks. I will try each of these, as they are cleaner.
On Nov 1, 2014, at 2:25 PM, Marko Tadić <[email protected] mailto:[email protected]> wrote:
Hi Brian,
properties 'children' and 'all' on AEXMLElement are of type Array, so it's logical that you can use 'count' on these.
You could also do it like this:
let count = tours["index"].children.count
or if "index" is your root element, like this:
let count = tours.rootElement.children.count
On the other side, I could write some documentation of all public properties and functions and add it to readme, so you don't have to look for that in source code.
Marko
—
Reply to this email directly or view it on GitHub #1 (comment).
from aexml.
Hey Brian,
sorry for late answer, but I hope you'll find it worth of waiting.
In this new version there is now count
property on AEXMLElement,
so in your example you can now do let count = doc["index"]["tour"].count
and get the right data (0 if no tags are present).
In addition to that, there are now functions like countWithAttributes
,
and allWithAttributes
which can be usefull too.
Thanks for the feedback,
// T
from aexml.
Appears you having a missing close right paren in your example. Are the parens required - or not...
Will this version return 0 if no occurrences of a tag exist?
Thanks,
Brian
On Nov 12, 2014, at 3:53 PM, Marko Tadić [email protected] wrote:
Hey Brian,
sorry for late answer, but I hope you'll find it worth of waiting.
In this new version there is now count property on AEXMLElement,
so in your example you can now do let count = (doc["index"]["tour"].count and get the right data.In addition to that, there are now functions like countWithAttributes,
and allWithAttributes which can be usefull too.Thanks for the feedback,
// T—
Reply to this email directly or view it on GitHub.
from aexml.
I confirmed this latest revision now returns the proper value 0 when no tags are present.
Thanks,
Brian.
On Nov 12, 2014, at 3:53 PM, Marko Tadić [email protected] wrote:
Hey Brian,
sorry for late answer, but I hope you'll find it worth of waiting.
In this new version there is now count property on AEXMLElement,
so in your example you can now do let count = (doc["index"]["tour"].count and get the right data.In addition to that, there are now functions like countWithAttributes,
and allWithAttributes which can be usefull too.Thanks for the feedback,
// T—
Reply to this email directly or view it on GitHub #1 (comment).
from aexml.
Nice, I fixed my previous comment also... :)
from aexml.
Related Issues (20)
- symbol(s) not found for architecture arm64
- How to remove <?xml version="1.0" encoding="utf-8"?> from the xml string HOT 1
- module compiled with Swift 5.0 cannot be imported by the Swift 5.1 compiler. HOT 3
- could not find module 'AEXML' for target 'arm64-apple-ios'; found: x86_64 HOT 1
- AEXMLDocument Retain Cycle
- XML incomplete parsing
- module compiled with Swift 5.1 cannot be imported by the Swift 5.1.2 compiler HOT 6
- module compiled with Swift 5.1 cannot be imported by the Swift 5.1.2 compiler HOT 4
- Add child with end tag HOT 1
- Support for DTDs? HOT 4
- Parser doesn't handle "0" or "1" for Booleans HOT 1
- Sorted attributes
- Build Target out of date HOT 3
- AEXML.modulemap not found on iOS 14 HOT 4
- Xcode 12 build warning - 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0 HOT 1
- Question
- Ability to exclude standalone attribute from document header HOT 3
- When <ruby> elements are used in html, other texts are vanished. HOT 1
- Error while parsing large files on linux
- Apple Silicon support HOT 4
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 aexml.