indexing description: "[ Objects that serialze XM_DOCUMENTs. This class is not suitable for very large documents (large means a significant proportion of available RAM), as the serializer creates an XM_XPATH_DOCUMENT tree and then serializes that using the XSLT 2.0 serializer. Serialization options can be set by calling features on `output_properties'. See http://www.gobosoft.com/eiffel/gobo/xml/xslt/xslt_serializer.html for details (ignore import precedence - just pass 0). But common option settings are available in the Setting feature clause of this class. ]" keywords: XML, serializer author: "Colin Adams" copyright: "Copyright (c) Barr Rosenberg Reasearch Center LLC 2008" license: "GNU General Public License version 3 (see gpl-3.0.txt)" class SV_XML_SERIALIZER inherit XM_XSLT_SERIALIZER export {ANY} STRING_ end XM_XSLT_CONFIGURATION_CONSTANTS export {NONE} all end create make feature {NONE} -- Initialization make is -- Initialize `Current'. do create encoder_factory create output_properties.make (0) create emitter_factory.make make_error_listener end make_error_listener is -- Create `error_listener'. do create {XM_XSLT_DEFAULT_ERROR_LISTENER} error_listener.make (Do_not_recover, create {UT_ERROR_HANDLER}.make_standard) ensure error_listener_not_void: error_listener /= Void end feature -- Access error_listener: XM_XSLT_ERROR_LISTENER -- Destination for error messages and warnings encoder_factory: XM_XSLT_ENCODER_FACTORY -- Factory for output encoders output_properties: XM_XSLT_OUTPUT_PROPERTIES -- Serialization options feature -- Setting set_method_xml is -- Set serialization method to "xml". do output_properties.set_method ("xml", 0) ensure xml_method_set: STRING_.same_string (output_properties.method, "xml") end set_method_xhtml is -- Set serialization method to "xhtml". do output_properties.set_method ("xhtml", 0) ensure xhtml_method_set: STRING_.same_string (output_properties.method, "xhtml") end set_method_html is -- Set serialization method to "html". do output_properties.set_method ("html", 0) ensure xhtml_method_set: STRING_.same_string (output_properties.method, "html") end set_version (a_version: STRING) is -- Set xml/xhtml/html version to `a_string'. require a_version_not_void: a_version /= Void version_must_be_valid_for_method: True -- currently 1.0 or 1.1 for xml or xhtml, 4.0 or 4.01 for html but this might change do output_properties.set_version (a_version, 0) ensure version_set: STRING_.same_string (output_properties.version, a_version) end set_indent (a_is_on: BOOLEAN) is -- Set indentation on (or off). do output_properties.set_indent (a_is_on, 0) ensure indent_set: output_properties.indent = a_is_on end set_omit_xml_declaration (a_is_omitted: BOOLEAN) is -- Omit (or don't omit) the XML declaration. do output_properties.set_omit_xml_declaration (a_is_omitted, 0) ensure omit_xml_declaration_set: output_properties.omit_xml_declaration = a_is_omitted end set_standalone (a_standalone_value: STRING) is -- Set standalone pseudo-attribute in xml declaration (or omit it). require valid_value: STRING_.same_string (a_standalone_value, "yes") or STRING_.same_string (a_standalone_value, "no") or STRING_.same_string (a_standalone_value, "omit") do output_properties.set_standalone (a_standalone_value, 0) ensure standalone_omiited: STRING_.same_string (a_standalone_value, "omit") implies output_properties.standalone = Void standalone_set: not STRING_.same_string (a_standalone_value, "omit") implies STRING_.same_string (a_standalone_value, output_properties.standalone) end set_encoding (a_encoding: STRING) is -- Cause output to be encoded as `a_encoding', or to "US-ASCII" if `encoder_factory' does not recognize it. require a_encoding_not_void: a_encoding /= Void do output_properties.set_encoding (a_encoding, 0) ensure encoding_set: STRING_.same_string (output_properties.encoding, a_encoding.as_upper) and output_properties.is_encoding_set end set_normalization_formm (a_form: STRING) is -- Set Unicode normalization form to `a_form'. -- This should only be done if encoding is set to a Unicode encoding (default is UTF-8 so that is ok). require a_form_not_void: a_form /= Void supported_form: STRING_.same_string (a_form, "NFC") or STRING_.same_string (a_form, "NFKC") or STRING_.same_string (a_form, "NFKC") or STRING_.same_string (a_form, "NFKD") do output_properties.set_normalization_form (a_form, 0) ensure normalization_form_set: STRING_.same_string (a_form, output_properties.normalization_form) end set_doctype_system (a_system_id: STRING) is -- Output a DOCTYPE with `a_system_id'. require a_system_id_not_void: a_system_id /= Void do output_properties.set_doctype_system (a_system_id, 0) ensure doctype_system_set: STRING_.same_string (a_system_id,output_properties. doctype_system) end set_doctype_public (a_public_id: STRING) is -- Set PUBLIC identifier on DOCTYPE to `a_public_id'. require a_public_id_not_void: a_public_id /= Void system_id_required: True -- Not effective unless `set_doctype_system' is also called. do output_properties.set_doctype_public (a_public_id, 0) ensure doctype_public_set: STRING_.same_string (a_public_id,output_properties. doctype_public) end feature -- Basic operations serialize (a_document: XM_DOCUMENT; a_destination: XM_OUTPUT) is -- Serialize `a_document' to `?' using options in `output_properties'. require a_document_not_void: a_document /= Void a_destination_not_void: a_destination /= Void local l_receiver: XM_XPATH_RECEIVER l_method, l_method_uri, l_method_local_name: STRING l_bridge: XM_XPATH_CONTENT_EMITTER l_content: XM_CONTENT_CONCATENATOR l_generator: XM_XMLNS_GENERATOR do l_method := output_properties.method if l_method.count = 0 then l_method_uri := ""; l_method_local_name := "" else l_method_uri := namespace_uri_from_expanded_name (l_method) l_method_local_name := local_name_from_expanded_name (l_method) end l_receiver := emitter_factory.new_receiver (l_method_uri, l_method_local_name, Current, a_destination, output_properties, Void) create l_bridge.make (l_receiver, create {XM_STOP_ON_ERROR_FILTER}.make_null) create l_content.set_next (l_bridge) create l_generator.set_next (l_content) a_document.process_to_events (l_generator) end feature {NONE} -- Implementation emitter_factory: XM_XSLT_EMITTER_FACTORY -- Factory for creating emitter/reciever chains invariant output_properties_not_void: output_properties /= Void emitter_factory_not_void: emitter_factory /= Void end