Code Monkey home page Code Monkey logo

Comments (15)

tadija avatar tadija commented on July 17, 2024

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.

appsird avatar appsird commented on July 17, 2024

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.

tadija avatar tadija commented on July 17, 2024

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.

tadija avatar tadija commented on July 17, 2024

I just removed conditional binding because NSXMLParser initWithData: is no longer failable initializer.
It now works on Xcode 6.1 (6A1052C).

from aexml.

appsird avatar appsird commented on July 17, 2024

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.

appsird avatar appsird commented on July 17, 2024

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:

Closed #1 #1.


Reply to this email directly or view it on GitHub #1 (comment).

from aexml.

appsird avatar appsird commented on July 17, 2024

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.

appsird avatar appsird commented on July 17, 2024

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.

tadija avatar tadija commented on July 17, 2024

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.

appsird avatar appsird commented on July 17, 2024

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.

appsird avatar appsird commented on July 17, 2024

marko,

First, swap the following into plant_catalog.xml in your project

brian [email protected] Tourx http://www.appsird.com/test

and 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.

tadija avatar tadija commented on July 17, 2024

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.

appsird avatar appsird commented on July 17, 2024

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.

appsird avatar appsird commented on July 17, 2024

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.

tadija avatar tadija commented on July 17, 2024

Nice, I fixed my previous comment also... :)

from aexml.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.