[GIS] How to convert Polygon to LinearRing Geometry

geometryopenlayers-2polygon

How can one convert a Polygon to LinearRing geometry using OpenLayers? I'm thinking that I can do this by getting bounds of the polygon, then use this to construct a Points array. Finally, use OpenLayers.Geometry.LinearRing(Points_Array) constructor to create the LinearRing. My attempts so far have flopped. Any code samples on how to achieve this will be highly appreciated.

UPDATE:
I've accepted @drnexgis' answer for what it taught me on converting geometry to GML format. It only partially answered the question, but it was helpful.

Best Answer

For example:

feature = map.layers[1].features[0];
gml = new OpenLayers.Format.GML();
gml.write(feature);

UPDATE

There is no API method for convering geometry to gml format, but you can use internal OpenLayers.Format.GML.buildGeometry.polygon function:

gml = new OpenLayers.Format.GML();    
gml.buildGeometry.polygon.apply(gml,[map.layers[1].features[0].geometry])

Live demo here.