16.1.5. XDTO-based XML serialization
The values of 1C:Enterprise configuration types can be serialized directly into(from) XML file based on the XDTO.
To do this, the XDTOSerializer object is used that can be retrieved using the wizard and based on the existing XDTO factory. XDTOSerializer object operation is the as with global procedures and XML functions.
For example, serialization of the link to Products catalog into XML file can be performed using the program code.
Example:
// Retrieve the link to a Products catalog item CatalogItemRef = Catalogs.Products.FindByCode("0000001"); // Create XDTO serializer for a global XDTO factory NewXDTOSerializer = New XDTOSerializer(XDTOFactory); // Create an XML writing object and open a file NewXMLWriter = New XMLWriter; NewXMLWriter.OpenFile("D:/Exchange.xml"); // ... // Serialize the link into XML NewXDTOSerializer.WriteXML(NewXMLWriter, CatalogItemRef, XMLTypeAssignment.Explicit);
Below is the example of serialization of Products catalog item link from XML file.
Example:
// Create XDTO serializer for a global XDTO factory NewXDTOSerializer = New XDTOSerializer(XDTOFactory); // Read an XDTO object data from the XML file NewXMLReader = New XMLReader; NewXMLReader.OpenFile("D:/Exchange.xml"); … // Serialize the link from XML NewRefToCatalog = NewXDTOSerializer.ReadXML(NewXMLReader);
With XDTO serializer, you can serialize both a single data value (in the example above, it is an item of the Products catalog) and all available objects of any metadata kind. For example, to perform XDTO serialization for the entire Products catalog, you can use the following code:
XMLWriter.WriteStartElement("root"); XDTOSerializer.WriteXML(XMLWriter, Metadata.Catalogs.Products, XMLTypeAssignment.Explicit); WriteXML.WriteEndElement();