# Build-in class to serialize a dataset to XML?

**URL:** <https://forum.inductiveautomation.com/t/build-in-class-to-serialize-a-dataset-to-xml/33426>\
**Category:** Module Development\
**Tags:** ignition80\
**Created:** [March 26, 2020, 9:57am UTC](https://forum.inductiveautomation.com/t/build-in-class-to-serialize-a-dataset-to-xml/33426 "2020-03-26T09:57:26Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![mazeyrat](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mazeyrat/32/10955_2.png) [@mazeyrat](https://forum.inductiveautomation.com/u/mazeyrat)\
**Post date:** [March 26, 2020, 9:57am UTC](https://forum.inductiveautomation.com/t/build-in-class-to-serialize-a-dataset-to-xml/33426/1 "2020-03-26T09:57:26Z")

</div>

I’m looking for a class in SDK to serialize a dataset to XML in order to create the Dataset part of this file:

```auto
<Tags>
   <Tag name="test" path="" type="Client">
      <Property name="Value">
         <Dataset>
            <columns>
               <col name="Value" datatype="Int4"/>
               <col name="Label" datatype="String"/>
            </columns>
            <rows>
               <row>
                  <cell>5</cell>
                  <cell>Coeur Réseau</cell>
               </row>
               <row>
                  <cell>1</cell>
                  <cell>Value1</cell>
               </row>
               <row>
                  <cell>2</cell>
                  <cell>Value2</cell>
               </row>
            </rows>
         </Dataset>
      </Property>
      <Property name="DataType">9</Property>
      <Property name="PollRate" mode="2">0</Property>
   </Tag>
</Tags> 

```

I have tried with no success:

```auto
from com.inductiveautomation.ignition.common.xmlserialization.serialization import XMLSerializer

rows = []
headers = ["paramName","designation"]
rows.append(["1","2"])

data = system.dataset.toDataSet(headers, rows)

print data
xml = XMLSerializer
xml.addObject(data)

print xml.serializeXML()

```

return:

```auto
Jython 2.7.1 (default:0df7adb1b397, Jun 30 2017, 19:02:43) 
[OpenJDK 64-Bit Server VM (Azul Systems, Inc.)] on java11.0.6

Dataset [1R ⅹ 2C]
Traceback (most recent call last):
  File "<input>", line 11, in <module>
TypeError: addObject(): expected 2 args; got 1
>>> 

```

---

<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:** [March 26, 2020, 11:20am UTC](https://forum.inductiveautomation.com/t/build-in-class-to-serialize-a-dataset-to-xml/33426/2 "2020-03-26T11:20:03Z")

</div>

> [@mazeyrat](#):
>
> xml = XMLSerializer

You need an instance. `XMLSerializer()`.

---

<div class="post-metadata">

**Author:** ![mazeyrat](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mazeyrat/32/10955_2.png) [@mazeyrat](https://forum.inductiveautomation.com/u/mazeyrat)\
**Post date:** [March 26, 2020, 11:55am UTC](https://forum.inductiveautomation.com/t/build-in-class-to-serialize-a-dataset-to-xml/33426/3 "2020-03-26T11:55:08Z")

</div>

Thanks phil !

but XMLSerializer it not the right class … to obtain dataset’s value as requested in an xml tag’s file import.

XMLSerializer return:

```auto
<?xml version="1.0" encoding="UTF-8"?>
<objects>
	<o cls="com.inductiveautomation.ignition.common.BasicDataset">
		<o-ctor s="4;java.util.List;java.util.List;[[java.lang.Object;[[com.inductiveautomation.ignition.common.model.values.QualityCode">
			<o cls="java.util.ArrayList">
				<o-c m="add" s="1;java.lang.Object"><str>paramName</str></o-c>
				<o-c m="add" s="1;java.lang.Object"><str>designation</str></o-c>
			</o>
			<o cls="java.util.ArrayList">
				<o-c m="add" s="1;java.lang.Object"><class>java.lang.String</class></o-c>
				<o-c m="add" s="1;java.lang.Object"><class>java.lang.String</class></o-c>
			</o>
			<array cls="[java.lang.Object" len="2">
				<array cls="java.lang.Object" len="1"><str>1</str></array>
				<array cls="java.lang.Object" len="1"><str>2</str></array>
			</array>
			<null/>
		</o-ctor>
	</o>
</objects>

```

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [March 26, 2020, 11:58am UTC](https://forum.inductiveautomation.com/t/build-in-class-to-serialize-a-dataset-to-xml/33426/4 "2020-03-26T11:58:33Z")

</div>

~~Use `com.inductiveautomation.ignition.common.TypeUtilities#datasetToJSON`.~~

Ergh, thought this was JSON even though it says XML everywhere in the title and post lol.

XML eh… sorry, looks like the class that does this dataset to XML transformation is not part of common or the gateway API.

---

<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:** [March 26, 2020, 1:06pm UTC](https://forum.inductiveautomation.com/t/build-in-class-to-serialize-a-dataset-to-xml/33426/5 "2020-03-26T13:06:29Z")

</div>

Hmm. This struck me as odd, as all scopes support system.tag.loadFromFile():

> [@Kevin.Herron](#):
>
> is not part of common

Sounds like a challenge. And here it is: _Protected_ method `writeDataset(ds)` of `com.inductiveautomation.ignition.common.sqltags.importexport.TagXMLExporter`.

Bleh.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [March 26, 2020, 1:13pm UTC](https://forum.inductiveautomation.com/t/build-in-class-to-serialize-a-dataset-to-xml/33426/6 "2020-03-26T13:13:38Z")

</div>

That’s the legacy import/export. Anything under the `sqltags` package is from old tag world.

The XML export currently used is at `com.inductiveautomation.ignition.gateway.tags.importexport.XmlExporter`, which is part of the gateway proper, not gateway-api or common.

---

<div class="post-metadata">

**Author:** ![mazeyrat](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mazeyrat/32/10955_2.png) [@mazeyrat](https://forum.inductiveautomation.com/u/mazeyrat)\
**Post date:** [March 26, 2020, 1:18pm UTC](https://forum.inductiveautomation.com/t/build-in-class-to-serialize-a-dataset-to-xml/33426/7 "2020-03-26T13:18:54Z")

</div>

In 8.0.10, client tag import/export still use the old xml format...

> [@\[bug-16241\]Ignition 8 - system.tag.importTags to create vision client tags?](http://forum.inductiveautomation.com/t/bug-16241-ignition-8-system-tag-importtags-to-create-vision-client-tags/33405):
>
> Can we use this function system.tag.importTags to create vision client tags ? collisionPolicy = "a" filePath = "d:/test.xml" basePath = "[client]" system.tag.importTags(filePath, basePath, collisionPolicy) return java.lang.NullPointerException (Ignition 8.0.10) Is there any way to create a cision client tag by scripting in Ignition 8 ? system.tag.configure only support gateway tags but not vision clients tag ?

but from the designer/client scope:

```auto
from com.inductiveautomation.ignition.common.sqltags.importexport.TagXMLImporter import TagXMLReader

```

return

```auto
Traceback (most recent call last):
  File "<input>", line 1, in <module>
ImportError: cannot import name TagXMLReader

```

---

<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:** [March 26, 2020, 1:21pm UTC](https://forum.inductiveautomation.com/t/build-in-class-to-serialize-a-dataset-to-xml/33426/8 "2020-03-26T13:21:29Z")

</div>

Ok, I see it. I was looking at v7.9 jars.

writeDataset() is protected there, too. Same “Bleh”. It has a no-arg constructor, so presumably subclassable.

A client or designer would need to use sendRequest() and have the gateway handler do the work.

Unsupported, of course.
