Module: Xml2Json::Xml

Defined in:
lib/xml2json.rb

Defined Under Namespace

Modules: Encoding, Version

Class Method Summary collapse

Class Method Details

.build(json_s, opts: nil) ⇒ String

Note:

Default values are provided by xml2json-rs

Note:

It's not enough for the Ruby indent_char string to be UTF-8 encoded, not sure if that's a bug or a feature of Magnus

Returns XML string.

Parameters:

  • json_s (String, #to_str) —

    JSON string

  • opts (Hash<Symbol, Object>) (defaults to: nil) —

    config params

Options Hash (opts:):

  • root_name (String, #to_str) — default: "root" —

    Root key name to contain produced JSON object

  • attrkey (String, #to_str) — default: "$" —

    The value of the JSON key used to store XML attributes under

  • charkey (String, #to_str) — default: "_" —

    The value of the JSON key used to store XML character data under

  • version (nil, "1.0", "1.1", #to_s) — default: Xml2Json::Version::XML10 —

    XML Declaration 'version' field, default if nil

  • encoding (nil, "UTF-8", #to_s) — default: nil —

    XML Declaration 'encoding' field, empty if nil

  • standalone (bool, nil) — default: nil —

    XML Declaration 'standalone' field, empty if nil

  • indent (bool) — default: false —

    Output XML with line-breaks and indentations

  • indent_char (String, #to_str) — default: " " —

    Character used for indentation. This option will be ignored if indent is false

  • indent_size (Integer, #to_int) — default: 2 —

    Number of characters used for indentation. This option will be ignored if indent is false

Returns:

  • (String) —

    XML string

Raises:

  • (RuntimeError) —

    if version.to_s returns unsupported string, for now only “1.0” and “1.1” are supported

  • (RuntimeError) —

    if encoding.to_s returns unsupported string, for now only “UTF-8” is supported

  • (TypeError) —

    If indent_char is more than one character or can not be encoded as UTF-8

  • (RangeError) —

    if indent_size cannot be converted into unsigned long long

  • (RuntimeError) —

    if json_s is not valid JSON

  • (TypeError) —

    if opts contain invalid value

See Also:



36
# File 'lib/xml2json.rb', line 36

def self.build(json_s, opts: nil); end

.build_pretty(json_s, opts: nil) ⇒ Object

Note:

Check Xml2Json::Xml.build for other details, the only difference is that indent is true by default

Parameters:

  • opts (Hash) (defaults to: nil) —

    a customizable set of options

Options Hash (opts:):

  • indent (bool) — default: true

See Also:



40
# File 'lib/xml2json.rb', line 40

def self.build_pretty(json_s, opts: nil); end