O'Reilly logo

HTML5 Data and Services Cookbook by Mite Mitreski, Gorgi Kosev

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Serialization of XML document at the client side

JSON is extremely simple to use than JavaScript; there are lot of REST services already out there that use XML. In this recipe we are going to create a simple form that will construct an XML document using the DOM API for XML.

How to do it...

Let's start:

  1. First we create a simple HTML document:
    <!doctype html>
    <html>
      <head>
        <meta charset="utf-8">
        <title>Create XML from JavaScript objects</title>
      </head>
      <body>
        <output id="log"> </output>
  2. After this we are going to include a KML document inside the text, in a real life application this will probably get loaded by AJAX, but for simplicity we will add the data directly:
     <kml id="test" xmlns="http://www.opengis.net/kml/2.2"> <Document> <name>Red Pyramid</name> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required