Skip to content

incendium.dataset.to_xml

César Román edited this page Feb 25, 2021 · 18 revisions

Description

Returns a string XML representation of the Dataset.

Syntax

to_xml(dataset[, root, element])

Args:

  • dataset (Dataset): The input dataset.
  • root (str): The value of the root. If not provided, it defaults to "root". Optional.
  • element (str): The value of the row. If not provided, it defaults to "row". Optional.

Returns:

  • str: The string XML representation of the dataset.

Recommendations

None.

Code Examples

# Imports.
import incendium.dataset

def get_dataset():
    # Generate the Rows
    rows = []
    for x in range(10):
        row = ['row {}'.format(x), x + 15]
        rows.append(row)

    # Generate the DataSet
    headers = ['row_id', 'value']
    return system.dataset.toDataSet(headers, rows)

# Get the Dataset
ds = get_dataset()

print incendium.dataset.to_xml(ds)

Output:

<root>
    <row>
        <row_id>row 0</row_id>
        <value>15</value>
    </row>
    <row>
        <row_id>row 1</row_id>
        <value>16</value>
    </row>
    <row>
        <row_id>row 2</row_id>
        <value>17</value>
    </row>
    <row>
        <row_id>row 3</row_id>
        <value>18</value>
    </row>
    <row>
        <row_id>row 4</row_id>
        <value>19</value>
    </row>
    <row>
        <row_id>row 5</row_id>
        <value>20</value>
    </row>
    <row>
        <row_id>row 6</row_id>
        <value>21</value>
    </row>
    <row>
        <row_id>row 7</row_id>
        <value>22</value>
    </row>
    <row>
        <row_id>row 8</row_id>
        <value>23</value>
    </row>
    <row>
        <row_id>row 9</row_id>
        <value>24</value>
    </row>
</root>
Clone this wiki locally