O'Reilly logo

Sams Teach Yourself XML in 10 Minutes by Andrew H. Watt

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

Creating a New Element

The DOM provides more than one way to create an element. You will examine some options in the examples that follow.

Using the createElement() Method

In this example, you will create a new SVG element using the createElement() method of the Document interface. You also will set the values of the attributes of the newly created element.

Listing 17.1 shows the code. Apart from the circle element that you will create using the DOM, the SVG document would be blank.

Listing 17.1. CreateCircle.svg: Creating a circle Element Using the DOM
 <?xml version='1.0'?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"> <svg onload="Initialize(evt)"> <script type="text/javascript" ...

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