Build-in class to serialize a dataset to XML?

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

<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:

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:

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
>>> 

You need an instance. XMLSerializer().

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:

<?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>

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.

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

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

Bleh.

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.

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

but from the designer/client scope:

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

return

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

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.