YUI 3.x Home -

Site Search (YDN & YUIBlog):

# YUI Library Examples: DataSchema Utility: DataSchema.Text

Note: This is YUI 3.x. Looking for YUI 2.x?

## DataSchema Utility: DataSchema.Text

DataSource.Text normalizes delimited text data against a given schema into an object with known properties.

View example in new window.

###### Data

    notebooks, 100, spiral-bound
    pencils, 300, #2 with erasers
    pens, 500, blue ink

###### Schema

    {
        resultDelimiter: "\n",
        fieldDelimiter: ",",
        resultFields: [{key:"product"}, {key:"quantity"}, {key:"detail"}]
    }

###### Normalized data

In order to use DataSchema.Text, input data must be delimited text. Define as your schema's `resultDelimiter` property the string that separates each result, and define as your schema's `fieldDelimiter` property the string that separates each field of each result.

YUI().use("dataschema-text", function(Y) { var data_in = "notebooks, 100, spiral-bound\npencils, 300, #2 with erasers\npens, 500, blue ink", schema = { resultDelimiter: "\n", fieldDelimiter: ",", resultFields: [{key:"product"}, {key:"quantity"}, {key:"detail"}] // Or simply: ["product", "quantity", "detail"] }, data_out = Y.DataSchema.Text.apply(schema, data_in)); alert(data_out); });

Copyright © 2009 Yahoo! Inc. All rights reserved.

Privacy Policy - Terms of Service - Copyright Policy - Job Openings