# Java method behind 'Copy XML to Clipboard'

**URL:** <https://forum.inductiveautomation.com/t/java-method-behind-copy-xml-to-clipboard/48082>\
**Category:** Ignition\
**Tags:** ignition80, vision, scripting\
**Created:** [June 22, 2021, 9:09pm UTC](https://forum.inductiveautomation.com/t/java-method-behind-copy-xml-to-clipboard/48082 "2021-06-22T21:09:02Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![zacht](https://avatars.discourse-cdn.com/v4/letter/z/ea5d25/32.png) [@zacht](https://forum.inductiveautomation.com/u/zacht)\
**Post date:** [June 22, 2021, 9:09pm UTC](https://forum.inductiveautomation.com/t/java-method-behind-copy-xml-to-clipboard/48082/1 "2021-06-22T21:09:02Z")

</div>

If it’s public, what is the java class/method behind the ‘Copy XML to Clipboard’ option in the Shift + Right Click context menu on a vision window in the the Project Browser?

Context:  
When our Ignition environment was first created (and for a few years after that), the tag structure was not well planned. Tags were pulled in from processors and never used. Multiple tags were created in different folders for a single OPC path on the same device; etc. In trying to go back and fix some of this, I’ve had good success manually copying XML to a text file and using python to find tag paths that are used in the window. I’d love to be able to automate the Copy XML step if I can.

Edit:

What I’d really like to find is the class/method that returns the XML String so I can write to a file. I’m less interested in the String → Clipboard step.

---

<div class="post-metadata">

**Author:** ![zacht](https://avatars.discourse-cdn.com/v4/letter/z/ea5d25/32.png) [@zacht](https://forum.inductiveautomation.com/u/zacht)\
**Post date:** [June 24, 2021, 3:10pm UTC](https://forum.inductiveautomation.com/t/java-method-behind-copy-xml-to-clipboard/48082/2 "2021-06-24T15:10:28Z")

</div>

I posted this in the afternoon/evening (across the US). Bump to see if there’s any interest in the morning.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [June 24, 2021, 4:19pm UTC](https://forum.inductiveautomation.com/t/java-method-behind-copy-xml-to-clipboard/48082/3 "2021-06-24T16:19:14Z")

</div>

Start by obtaining a DesignerContext. (:

From that, obtain a fully-configured serializer with [.createSerializer()](https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.0/com/inductiveautomation/ignition/designer/model/DesignerContext.html#createSerializer()).

Then add the window object to the serializer, and use [.serializeXML()](https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.0/com/inductiveautomation/ignition/common/xmlserialization/serialization/XMLSerializer.html#serializeXML()) to yield your desired string. Or use one of the peer methods to serialize directly to a file or other stream.

You’ll note that there is also a `.createDeserializer()` method. Please report back when you reach the bottom of this rabbit hole… (:

Working with contexts is totally unsupported, of course.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [June 24, 2021, 4:22pm UTC](https://forum.inductiveautomation.com/t/java-method-behind-copy-xml-to-clipboard/48082/4 "2021-06-24T16:22:57Z")

</div>

Note that this is based on an open window. I’m sure there’s a way to extract the serialized form from the window resource. No idea on that.

---

<div class="post-metadata">

**Author:** ![zacht](https://avatars.discourse-cdn.com/v4/letter/z/ea5d25/32.png) [@zacht](https://forum.inductiveautomation.com/u/zacht)\
**Post date:** [June 24, 2021, 4:24pm UTC](https://forum.inductiveautomation.com/t/java-method-behind-copy-xml-to-clipboard/48082/5 "2021-06-24T16:24:27Z")

</div>

> [@pturmel](#):
>
> Working with contexts is totally unsupported, of course.

Naturally. It almost goes without saying.

Based on the number of (: in your reply I suspect the rabbit hole is probably pretty deep, but I'll report as far as I get.

> [@pturmel](#):
>
> Note that this is based on an open window. I’m sure there’s a way to extract the serialized form from the window resource. No idea on that.

Noted. Thanks for pointing me in the right direction.

---

<div class="post-metadata">

**Author:** ![zacht](https://avatars.discourse-cdn.com/v4/letter/z/ea5d25/32.png) [@zacht](https://forum.inductiveautomation.com/u/zacht)\
**Post date:** [June 24, 2021, 6:21pm UTC](https://forum.inductiveautomation.com/t/java-method-behind-copy-xml-to-clipboard/48082/6 "2021-06-24T18:21:13Z")

</div>

```auto
windowList = system.gui.getWindowNames()
for i in windowList:
	serializer = context.createSerializer()
	serializer.addObject(system.nav.openWindow(i))
	outputStream = FileOutputStream(outputDirectory+i+'.txt')
	serializer.serializeXML(outputStream, 'utf-8')
	outputStream.close()

```

I imagine there is probably a more elegant way to do this, but this script accomplishes my goal. I haven’t looked into `createDeserializer()` (yet). Alas, there’s only so long I can spend scripting my work before I have to do the work…

Thanks again @pturmel for the help and thanks to @nmudge in another thread for the code to get a gateway context.

---

<div class="post-metadata">

**Author:** ![indra.biswas](https://avatars.discourse-cdn.com/v4/letter/i/3bc359/32.png) [@indra.biswas](https://forum.inductiveautomation.com/u/indra.biswas)\
**Post date:** [February 26, 2022, 6:16am UTC](https://forum.inductiveautomation.com/t/java-method-behind-copy-xml-to-clipboard/48082/7 "2022-02-26T06:16:42Z")

</div>

@zacht  
Thanks for the above snippet, its almost exactly what I need. I cant get it to work though. I’ve added the following on the top

from com.inductiveautomation.ignition.designer.model import DesignerContext  
context = DesignerContext  
but I keep getting an error saying it expects atleast 1 arg, but not sure what to pass to it

---

<div class="post-metadata">

**Author:** ![zacht](https://avatars.discourse-cdn.com/v4/letter/z/ea5d25/32.png) [@zacht](https://forum.inductiveautomation.com/u/zacht)\
**Post date:** [February 28, 2022, 4:14pm UTC](https://forum.inductiveautomation.com/t/java-method-behind-copy-xml-to-clipboard/48082/8 "2022-02-28T16:14:10Z")

</div>

That isn't how I got the designer context. I used some code from [this forum post](https://forum.inductiveautomation.com/t/how-to-get-project-object-using-script/7472/3).

As `pturmel` noted,

> [@pturmel](#):
>
> Working with contexts is totally unsupported, of course.

so tread carefully and probably don't use this in a production setting. I used it to partially automate some mass tag renaming I was very closely supervising. I wouldn't trust it for much more than that, and I certainly wouldn't trust it across Ignition versions.

In the forum thread I linked you will also see @Robert.McKenzie warn against relying on this sort of implementation, so consider this a double warning.
