Module: AssOle::Snippets::Shared::XMLSerializer

Defined in:
lib/ass_ole/snippets/shared.rb

Overview

Note:

In external runtime it will be cause of a fail in InfoBase#rm! ‘… /1Cv8.1CD (Errno::EBUSY)’ because external connection realy keep alive

Snippet for serialize and deserilize 1C objects to xml

Instance Method Summary collapse

Instance Method Details

#from_xml(xml) ⇒ WIN32OLE

Deserialize 1C object from XML srtring

Parameters:

  • xml (String)

    xml string

Returns:

  • (WIN32OLE)

    1C object



42
43
44
45
46
# File 'lib/ass_ole/snippets/shared.rb', line 42

def from_xml(xml)
  zxml = newObject 'XMLReader'
  zxml.SetString xml
  xDTOSerializer.ReadXml zxml
end

#from_xml_file(xml_file) ⇒ WIN32OLE

Deserialize 1C object from XML file

Parameters:

  • xml_file (#path String)

    path to xml file

Returns:

  • (WIN32OLE)

    1C object



51
52
53
54
55
56
57
58
59
# File 'lib/ass_ole/snippets/shared.rb', line 51

def from_xml_file(xml_file)
  zxml = newObject 'XMLReader'
  path_ = xml_file.respond_to?(:path) ? xml_file.path : xml_file
  zxml.openFile(real_win_path(path_))
  obj = xDTOSerializer.ReadXml zxml
  obj
ensure
  zxml.close
end

#to_xml(obj) ⇒ String

Serialize 1C oject to XML string

Parameters:

  • obj (WIN32OLE)

    1C object

Returns:

  • (String)


18
19
20
21
22
23
# File 'lib/ass_ole/snippets/shared.rb', line 18

def to_xml(obj)
  zxml = newObject 'XMLWriter'
  zxml.SetString
  xDTOSerializer.WriteXML zxml, obj
  zxml.close
end

#to_xml_file(obj, xml_file) ⇒ Object

Serialize 1C oject to XML file

Parameters:

  • obj (WIN32OLE)

    1C object

  • xml_file (#path String)

    target file path

Returns:

  • xml_file



29
30
31
32
33
34
35
36
37
# File 'lib/ass_ole/snippets/shared.rb', line 29

def to_xml_file(obj, xml_file)
  zxml = newObject 'XMLWriter'
  path_ = xml_file.respond_to?(:path) ? xml_file.path : xml_file
  zxml.openFile(real_win_path(path_))
  xDTOSerializer.WriteXML zxml, obj
  xml_file
ensure
  zxml.close
end