Simple and quick way to parse an XML file in iOS7 - ios

I have a simple XML file like this
<?xml version="1.0"?>
<catalog>
<timezone>
<name>UTC-11:00</name>
<place>
<value>American Samoa</value>
<value>Samoa</value>
</place>
</timezone>
<timezone>
<name>UTC-10:00</name>
<place>
<value>Honolulu</value>
<value>Tahiti</value>
</place>
</timezone>
</catalog>
What is the canonical/standard way to parse this in iOS? I want to save "names" and "places" for each name.

NSXMLParser is already built in. You should look at this article for a more thorough comparison.
http://www.raywenderlich.com/553/xml-tutorial-for-ios-how-to-choose-the-best-xml-parser-for-your-iphone-project

It is NSXMLParser. Official documentation

Related

SAXParseException when using restassured

I am trying to verify a XML response with rest-assured like this:
.then().body("some.xml.path", is("abc"));
However, what I get is a SAXParseException:
DOCTYPE is disallowed when the feature "http://apache.org/xml/features/disallow-doctype-decl" set to true.]
Response starts like this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE cXML SYSTEM "http://xml.cXML.org/schemas/cXML/1.2.021/cXML.dtd">
<cXML ...
Why am I getting this exception? What should I change?
I am using version 3.2.0 of rest-assured.
A similar question has been answered here. In short, the answer describes to use disableLoadingOfExternalDtd() to have RestAssured ignore the Document Type Definition in your XML.
Normally, the DTD would describe (using the external definition) the structural layout of the element defined as cXML.

Standard File Format for Sharing Location Data

I am wanting to add support to my iOS application to share location data, basically names and latlong coordinates, via a file format that can be emailed, save to dropbox, and can be opened by my application.
Is there a standard file format to share this information? I have done some research, and there doesn't seem to be much, a gpx file seems like overkill. I'd prefer to not make up my own format if one already exists.
I suggest you to use vcard format.
There is a GEO value type for this. vCards are easy machine- and human-readable.
Example:
BEGIN:VCARD
VERSION:3.0
TITLE:My Geo Point
GEO:37.386013;-122.082932
END:VCARD
Alternatively you can use apple vcard format:
BEGIN:VCARD
VERSION:3.0
PRODID:-//Apple Inc.//iOS 8.1//EN
N:;Current geo;;;
FN:Current geo
item1.URL;type=pref:http://maps.apple.com/?ll=55.369117\,39.079991
item1.X-ABLabel:map url
END:VCARD
This vcard may be opened via maps or messages both mac and ios.
Use GPX file format , as below xml format -
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<gpx
xmlns="http://www.topografix.com/GPX/1/1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd"
version="1.1"
creator="gpx-poi.com">
<wpt lat="53.140450168" lon="-1.55674562972">
<time>2014-11-28T09:41:05Z</time>
</wpt>
</gpx>

How to read xml attribute value on apache ant?

I have an xml like below.
<Students college="SGS">
<Student id="001" name="ABC"/>
<Student id="002" name="XYZ"/>
<Students/>
<Students college="SPM">
<Student id="001" name="PQR"/>
<Student id="002" name="LMN"/>
<Students/>
and I want name of the student of the SGS college whose id is 001 using apache ant.
So how can I get this without using extra jar like xmltask.jar etc
The simplest solution is to use XPath to get this information. In Ant there is no built-in task to fetch XML data using XPath expressions. You would need to use tasks provided in external libraries:
https://code.google.com/p/ant-xpath-task/wiki/Introduction
http://ant.apache.org/external.html

Sufficient way to get Wikipedia's POTD

In this page: http://en.wikipedia.org/wiki/Wikipedia:Picture_of_the_day you can see Wikipedia:POTD and (below) Commons:POTD.
I've found this: Wikipedia API: Cannot query Picture of the Day URL but it is for Commons:POTD.
Is there anything similar for Wikipedia:POTD ?
No, I didn't see anything like that. On enwiki you can get POTD from proper template, e.g.:
<?xml version="1.0"?>
<api>
<expandtemplates xml:space="preserve">[[:Template:Potd/2013-12-29]]</expandtemplates>
</api>

Is it possible to generate plain-old XML using Haml?

I've been working on a piece of software where I need to generate a custom XML file to send back to a client application. The current solutions on Ruby/Rails world for generating XML files are slow, at best. Using builder or event Nokogiri, while have a nice syntax and are maintainable solutions, they consume too much time and processing.
I definetly could go to ERB, which provides a good speed at the expense of building the whole XML by hand.
HAML is a great tool, have a nice and straight-forward syntax and is fairly fast. But I'm struggling to build pure XML files using it. Which makes me wonder, is it possible at all?
Does any one have some pointers to some code or docs showing how to do this, build a full, valid XML from HAML?
Doing XML in HAML is easy, just start off your template with:
!!! XML
which produces
<?xml version='1.0' encoding='utf-8' ?>
Then as #beanish said earlier, you "make up your own tags":
%test
%test2 hello
%item{:name => "blah"}
to get
<test>
<test2>hello</test2>
<item name='blah'></item>
</test>
More:
http://haml.info/docs/yardoc/file.REFERENCE.html#doctype_
%test
%test2 hello
%item{:name => "blah"}
run it through haml
haml hamltest.haml test.xml
open the file in a browser
<test>
<test2>hello</test2>
<item name='blah'></item>
</test>
The HAML reference talks about html tags and gives some examples.
HAML reference
This demonstrates some things that could use useful for xml documents:
!!! XML
%root{'xmlns:foo' => 'http://myns'}
-# Note: :dashed-attr is invalid syntax
%dashed-tag{'dashed-attr' => 'value'} Text
%underscore_tag Text
- ['apple', 'orange', 'pear'].each do |fruit|
- haml_tag(fruit, "Yummy #{fruit.capitalize}!", 'fruit-code' => fruit.upcase)
%foo:nstag{'foo:nsattr' => 'value'}
Output:
<?xml version='1.0' encoding='utf-8' ?>
<root xmlns:foo='http://myns'>
<dashed-tag dashed-attr='value'>Text</dashed-tag>
<underscore_tag>Text</underscore_tag>
<apple fruit-code='APPLE'>Yummy Apple!</apple>
<orange fruit-code='ORANGE'>Yummy Orange!</orange>
<pear fruit-code='PEAR'>Yummy Pear!</pear>
<foo:nstag foo:nsattr='value'></foo:nstag>
</root>
Look at the Haml::Helpers link on the haml reference for more methods like haml_tag.
If you want to use double-quotes for attributes,
See: https://stackoverflow.com/a/967065/498594
Or outside of rails use:
>> Haml::Engine.new("%tag{:name => 'value'}", :attr_wrapper => '"').to_html
=> "<tag name=\"value\"></tag>\n"
Haml can produce XML just as easily as HTML (I've used it for FBML and XHTML). What problems are you having?
I've not used HAML, but if you can't make it work another option is Builder.
what about creating the xml header, e.g. <?xml version="1.0" encoding="UTF-8"?>
?
It should be possible. After all you can create plain old XML with Notepad.

Resources