# Is there an API function to import layers from SVG string?

**URL:** <https://forums.creativeclouddeveloper.com/t/is-there-an-api-function-to-import-layers-from-svg-string/1398>\
**Category:** UXP Plugin API\
**Created:** [November 8, 2019, 10:38am UTC](https://forums.creativeclouddeveloper.com/t/is-there-an-api-function-to-import-layers-from-svg-string/1398 "2019-11-08T10:38:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dmraptis](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/dmraptis/32/655_2.png) [@dmraptis](https://forums.creativeclouddeveloper.com/u/dmraptis)\
**Post date:** [November 8, 2019, 10:38am UTC](https://forums.creativeclouddeveloper.com/t/is-there-an-api-function-to-import-layers-from-svg-string/1398/1 "2019-11-08T10:38:30Z")

</div>

Hey! I have an HTML SVG object as a string and I want to create the appropriate layers from that string. Is there a recommended way or the only solution is to parse and identify tags separately?

---

<div class="post-metadata">

**Author:** ![pklaschka](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/pklaschka/32/3162_2.png) [@pklaschka](https://forums.creativeclouddeveloper.com/u/pklaschka)\
**Post date:** [November 8, 2019, 4:08pm UTC](https://forums.creativeclouddeveloper.com/t/is-there-an-api-function-to-import-layers-from-svg-string/1398/2 "2019-11-08T16:08:48Z")

</div>

Hi @dmraptis,

according to @kerrishotts, there unfortunately currently aren’t any APIs for this, see the [feature request](http://forums.creativeclouddeveloper.com/t/adding-svg-to-the-artboard/480) for reference…

---

<div class="post-metadata">

**Author:** ![dmraptis](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/dmraptis/32/655_2.png) [@dmraptis](https://forums.creativeclouddeveloper.com/u/dmraptis)\
**Post date:** [November 8, 2019, 4:43pm UTC](https://forums.creativeclouddeveloper.com/t/is-there-an-api-function-to-import-layers-from-svg-string/1398/3 "2019-11-08T16:43:39Z")

</div>

Thanks for the reference! Are there any plans to add an API for this functionality?

One solution to walk around this issue is to manually parse the SVG elements, but it would be painful 😅

---

<div class="post-metadata">

**Author:** ![pklaschka](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/pklaschka/32/3162_2.png) [@pklaschka](https://forums.creativeclouddeveloper.com/u/pklaschka)\
**Post date:** [November 8, 2019, 5:21pm UTC](https://forums.creativeclouddeveloper.com/t/is-there-an-api-function-to-import-layers-from-svg-string/1398/4 "2019-11-08T17:21:07Z")

</div>

I agree that this would be painful. While I don’t know of any current work on such APIs (although folks from Adobe will have to answer this, there’s nothing on the [roadmap](https://trello.com/b/WFKmCVaz/xd-extensibility-roadmap)), as a fallback, the suggestion by @kerrishotts in the feature request about copying the SVG to the clipboard via `require('clipboard').copyText(svg)` might be a bit more realistic than trying to parse the SVG manually. I don’t know how complex your SVGs are, but I wouldn’t want to have to work on parsing this to XD 😄. This at least ensures not having to update an SVG parser as XD’s capabilities grow…

On the other hand (trying to encourage open-source work around the ecosystem 😉), a community-driven open-source library for this task could be a cool thing that might be useful to many. If the community were up to it (maybe, someone has already tried doing something like this and could contribute his/her code as a start), with a few people finding it useful and willing to contribute (count me in 😉), it might be feasible…
