### Home Classes Methods

### In Files

- lib/dbi/utils/xmlformatter.rb

### Methods

- ::extended_row
- ::row
- ::table

### Files

- README

### Class/Module Index

Quicksearch

- DBI
- DBI::BaseDatabase
- DBI::BaseDriver
- DBI::BaseStatement
- DBI::Binary
- DBI::ColumnInfo
- DBI::DataError
- DBI::DatabaseError
- DBI::DatabaseHandle
- DBI::Date
- DBI::DriverHandle
- DBI::Error
- DBI::Handle
- DBI::HandleTracer
- DBI::IntegrityError
- DBI::InterfaceError
- DBI::InternalError
- DBI::NotImplementedError
- DBI::NotSupportedError
- DBI::OperationalError
- DBI::ProgrammingError
- DBI::Row
- DBI::SQL
- DBI::SQL::PreparedStatement
- DBI::StatementHandle
- DBI::Time
- DBI::Timestamp
- DBI::Type
- DBI::Type::Boolean
- DBI::Type::Decimal
- DBI::Type::Float
- DBI::Type::Integer
- DBI::Type::Null
- DBI::Type::Timestamp
- DBI::Type::Varchar
- DBI::TypeUtil
- DBI::Utils
- DBI::Utils::ConvParam
- DBI::Utils::TableFormatter
- DBI::Utils::XMLFormatter
- DBI::Warning
- Class

No matching classes.

# DBI::Utils::XMLFormatter

Formats results in XML.

### Public Class Methods

extended_row(dbrow, rowtag="row", cols_in_row_tag=[], cols_as_tag=nil, add_row_tag_attrs={}, output=STDOUT) click to toggle source

good lord, what a mess.

nil in cols_as_tag, means "all columns expect those listed in cols_in_row_tag" add_row_tag_attrs are additional attributes which are inserted into the row-tag

    # File lib/dbi/utils/xmlformatter.rb, line 24
    def self.extended_row(dbrow, rowtag="row", cols_in_row_tag=[], cols_as_tag=nil, add_row_tag_attrs={}, output=STDOUT)
        if cols_as_tag.nil?
            cols_as_tag = dbrow.column_names - cols_in_row_tag
        end

        output << "<#{rowtag}"
        add_row_tag_attrs.each do |key, val|
            # TODO: use textconv ? " substitution?
            output << %{ #{key}="#{textconv(val)}"}
        end
        cols_in_row_tag.each do |key|
            # TODO: use textconv ? " substitution?
            output << %{ #{key}="#{dbrow[key]}"}
        end
        output << ">\n"

        cols_as_tag.each do |key|
            output << "  <#{key}>" + textconv(dbrow[key]) + "</#{key}>\n"
        end
        output << "</#{rowtag}>\n"
    end

row(dbrow, rowtag="row", output=STDOUT) click to toggle source

Generate XML for a row. The column names will surround the the values as tags.

- `dbrow`: the array of the result row.

- `rowtag`: the name of the tag that encapsulates a row.

- `output`: Object that responds to `<<`.

    # File lib/dbi/utils/xmlformatter.rb, line 11
    def self.row(dbrow, rowtag="row", output=STDOUT)
        #XMLFormatter.extended_row(dbrow, "row", [],
        output << "<#{rowtag}>\n"
        dbrow.each_with_name do |val, name|
            output << "  <#{name}>" + textconv(val) + "</#{name}>\n"
        end
        output << "</#{rowtag}>\n"
    end

table(rows, roottag = "rows", rowtag = "row", output=STDOUT) click to toggle source

generate a full XML representation of the table.

Arguments and output are similar to row, with the exception of `roottag`, which is a container for the individual row tags.

    # File lib/dbi/utils/xmlformatter.rb, line 51
    def self.table(rows, roottag = "rows", rowtag = "row", output=STDOUT)
        output << '<?xml version="1.0" encoding="UTF-8" ?>'
        output << "\n<#{roottag}>\n"
        rows.each do |row|
            row(row, rowtag, output)
        end
        output << "</#{roottag}>\n"
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.