The following are  useful tips we gathered during the development of our mobile apps.

How to Parse the XML-RPC response

  • Before starting the parsing process we should “clean” the document by removing any characters outside the UTF-8 charset.
  • Before starting the parsing process, we should “clean” the document removing the BOM bytes if present, and removing any junk character before the first ‘<’. It’s easy just remove everything before  the first ‘<’.
  • Remove contents outside tags.
  • Do not use a strict XML parser (in iOS the parser is strict, but if the parsing process fails, we clean the document using htmlTidy and restart the parsing process by using the “tidyed” document). In BB the parser is not strict.

How to add new blogs

A) try to guess the XML-RPC URL by adding “/xmlrpc.php”, to the URL inserted by the user. Also remove the string “/wp-admin/” if present.

B) If the previous fails, try to get the value from the pingback element:

<link rel="pingback" href="http://padpressed.wordpress.com/xmlrpc.php" />

  • Validate the endpoint of the blog (see later)

C) If the previous fails, download the content of the page at the URL inserted by the user, and find the following link element with rel=’EditURI’

<link rel="EditURI" type="application/rsd+xml" title="RSD" href="http://padpressed.wordpress.com/xmlrpc.php?rsd" />

  • Get the href attribute and download the RSD Document
  • Parse the RSD document and get the apiLink for WordPress


<api name="WordPress" blogID="1" preferred="true" apiLink="https://padpressed.wordpress.com/xmlrpc.php"/>

the apiLink value is the XML-RPC URL endpoint of the blog.

  • Validate the endpoint of  the blog (see later)

Validate the XML-RPC Endpoint

  • Before starting any XML-RPC calls we should test the endpoint calling system.listMethods and checking that all required XML-RPC methods are available on the blog.

Entities Issues

The WordPress server could reply with double encoded entities. We should clean every double encoded entities within the server response.
(the BB app scans the response document and clean all double encoded entities by using a detection class. The iOS app does the same for some entities see NSString+XMLExtensions.h)

  • Double encoding of ampersands in blog titles details
  • Apostrophe in blog name appears as html entity ‘ details

Blog Icons

  • We need to check if blavatar is available for the blog.

http://blackberry.trac.wordpress.org/browser/trunk/src/com/wordpress/xmlrpc/BlogUpdateConn.java#L177

  • If blavatar is not available for the blog we can use the blog favicon or the blog apple-touch-icon

<link rel="apple-touch-icon" href="http://1.gravatar.com/blavatar/1207b2513324faa232e908259981d01f?s=158" />

Media Uploading

When uploading fails we should check the error message and prompt a useful error message:

  • if the error type is an XML Parser Error ->There was an error processing your file. Please check the configuration of your blog.
  • if the error message contains “Invalid file type” && file is a Video file -> To upload videos you need to have VideoPress installed. Would you like to learn more about VideoPress now?
  • Generic Error – Sorry, upload failed

Preview

  • preview for freshly created or modified post should be done using a local HTML template
  • preview for published post/page is easy if the blog is not private, just load permaLink URL within a webView.

Various

  • store passwords using the device native encryption capabilities
  • right after an upload of a post/page/comment to the blog, we should do a get for the blog element you have uploaded and refreshing the local copy. (There are tons of plugins that modifies the request, for example adding categories, or modifying the content). You should also get the permaLink field to enable the preview.
  • The get in not necessary when moderating comments