How XML to SVG Conversion Works
XML is a general format, so an xml to svg converter can only draw XML that describes a drawing. The most common case is the Android vector drawable, the XML file inside an app's res/drawable folder. This tool reads that format and writes the same drawing as a standard SVG that opens in any browser, design tool or image viewer. If your XML is already an SVG, it is validated, given the right namespace and indented.
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp" android:height="24dp"
android:viewportWidth="24" android:viewportHeight="24">
<path android:pathData="M12,2L2,7l10,5l10,-5z" android:fillColor="#4F46E5"/>
</vector>That vector drawable becomes an <svg> element with a viewBox of 0 0 24 24 and one <path> with a fill of #4F46E5.
What Is Converted
- Size: android:width and height in dp become the SVG width and height. The viewport becomes the viewBox.
- Paths: pathData is copied as the SVG d attribute, with fill, stroke, width, caps, joins, miter limit, alpha and the even-odd fill rule.
- Groups: translate, rotate, scale and pivot values become one transform that follows the same order Android uses.
- Clip paths: a clip-path element clips the shapes that follow it in the same group.
- Gradients: linear and radial gradients written with aapt:attr become SVG linearGradient and radialGradient elements. Sweep gradients are not supported by SVG.
- Whole-icon alpha: android:alpha becomes the SVG opacity.
Cleaning SVG That Is Saved as XML
Design tools often save an SVG with a long header: an XML declaration, a DOCTYPE, comments, editor metadata and tags added by Inkscape or Sodipodi. These make the file bigger and harder to read. When the XML you paste is an SVG, the tool checks it is well-formed, adds the SVG namespace if it is missing, removes that clutter if you ask it to and writes it back with indentation.
It does not redraw or optimise the shapes, so the picture stays exactly the same. To use the cleaned file as an image, send it to SVG to PNG. To go the other direction and create an Android vector drawable, use SVG to XML. If you only have a bitmap, PNG to SVG traces it into a vector first.
What Cannot Be Converted
- XML that is not a drawing, such as a sitemap, RSS feed or config file. There is nothing to draw, so the tool tells you what the file starts with.
- Android animated vectors, shape drawables and layouts. Only the <vector> format is supported.
- Trim paths and sweep gradients, which SVG cannot express the same way.