Notepad++ is a free source code editor and Notepad replacement that supports several formats. In its basic edition it can already do some nice things like:
If you download the XML Tools Plugin you can also pretty print XML documents without witespaces. Just select it from the plugins menu or use the keyboard shortcut "Ctrl"+"Alt"+"Shift"+"B". Check out also the other features provided with the plugin.
The challenge was to get a public transport route, by sending time, date, start and destination address. The problem was solved by using the "Wiener Linien API" (http://akirk.github.com/Wiener-Linien-API/). The PHP-Code sends a XML-request with all details of the appointment and get a XML-respond with the transport connection.
For building a request the PHP-function "buildRequest()" can be used.
The following example illustrates a query from "Seckendorfstrasse 4" to "Wiedner Hauptstr. 8":
$params = array();
$params["outputCoords"] = "WGS84";
$params["from"] = "Seckendorfstrasse 4";
$params["to"] = "Wiedner Hauptstr. 8";
$params["year"] = "2011";
$params["month"] = "12";
$params["day"] = "14";
$params["hour"] = "17";
$params["minute"] = "00";
$params["deparr"] = "arr";
$params["modality"] = "pt";
$params["sourceFrom"] = "gps";
$params["sourceTo"] = "stoplist";
$req = buildRequest("api_get_route", $params);
Afterwards, the XML-request must be sent to the following webservice: http://webservice.qando.at/2.0/webservice.ft.
$response = httpPost("http://webservice.qando.at/2.0/webservice.ft", $req);
Finally, the XML-response must be load into a Document Object Model (DOM). A DOM presents an XML document as a tree-structure, which makes it easy to interpret and evaluate the local public transport route.
$dom = new DOMDocument();
$dom->formatOutput = true;
$dom->preserveWhiteSpace = false;
$dom->loadXML($response);
The complete DOMDocument manual is available on the website: http://php.net/manual/de/class.domdocument.php.
To print out the XML-response of the public transport route, use the following PHP-code:
echo "Response: " .$dom->saveXML(). "";
There are several tested solutions available on the Internet already: JAVASCRIPT Solution approach: It provides
Download Skript: http://www.thomasfrank.se/downloadableJS/xml2json.js Usage as documented on this site: <head><script type="text/javascript" src="xml2json.js"></script>...</head>Then it can be called in these different variants:
V1 ("compact") can be used for output without linebreaks or tabbing. V2 for normal output with linebreaks ant tabbing. V3 for HTML representation.JAVA solution approach (which is solution I have already tested and which is provided by Json.org): The Source files are available at http://json.org/java/ for many JSON issues in Java. The relevant class is called XML and is viewable at:
It provides
Naturally, the XML has to be well-formed and valid to produce a JSON object. The JSON objcect istself has to be valid again. It can be assumed that always correct outputs for valid inputs are retrieved according its high adoption in real world usage.