# XML Format Example

Shows the use of the OpenLayers XML format class

OpenLayers has a very simple XML format class (OpenLayers.Format.XML) that can be used to read/write XML docs. The methods available on the XML format (or parser if you like) allow for reading and writing of the various XML flavors used by the library - in particular the vector data formats. It is by no means intended to be a full-fledged XML toolset. Additional methods will be added only as needed elsewhere in the library.

This page loads an XML document and demonstrates a few of the methods available in the parser.

Status: XML document loading...

After the XML document loads, see the result of a few of the methods below. Assume that you start with the following code:
var format = new OpenLayers.Format.XML();

Sample methods

- format.write() - write the XML doc as text
- format.getElementsByTagNameNS() - get all gml:MultiPolygon
- format.hasAttributeNS() - test to see schemaLocation attribute exists in the http://www.w3.org/2001/XMLSchema-instance namespace
- format.getAttributeNodeNS() - get schemaLocation attribute in the http://www.w3.org/2001/XMLSchema-instance namespace
- format.getAttributeNS() - get schemaLocation attribute value in the http://www.w3.org/2001/XMLSchema-instance namespace
- format.createElementNS() - create a foo:TestNode element (and append it to the doc)
- format.createTextNode() - create a text node (and append it to the doc)

Output: