|
0
|
1 |
|
|
|
2 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> |
|
|
3 |
<html> |
|
|
4 |
<head> |
|
|
5 |
<title>YUI Library Examples: DataSchema Utility: DataSchema.Text</title> |
|
|
6 |
<meta http-equiv="content-type" content="text/html; charset=utf-8"> |
|
|
7 |
<link rel="stylesheet" type="text/css" href="../../assets/yui.css" > |
|
|
8 |
|
|
|
9 |
<style> |
|
|
10 |
/*Supplemental CSS for the YUI distribution*/ |
|
|
11 |
#custom-doc { width: 95%; min-width: 950px; } |
|
|
12 |
#pagetitle {background-image: url(../../assets/bg_hd.gif);} |
|
|
13 |
/* #pagetitle h1 {background-image: url(../../assets/title_h_bg.gif);}*/ |
|
|
14 |
</style> |
|
|
15 |
|
|
|
16 |
<link rel="stylesheet" type="text/css" href="../../assets/dpSyntaxHighlighter.css"> |
|
|
17 |
<link type="text/css" rel="stylesheet" href="../../build/cssfonts/fonts-min.css" /> |
|
|
18 |
<script type="text/javascript" src="../../build/yui/yui-min.js"></script> |
|
|
19 |
<style type="text/css"> |
|
|
20 |
/* custom styles for this example */ |
|
|
21 |
#demo .output {margin-bottom:1em; padding:10px; border:1px solid #D9D9D9;} |
|
|
22 |
</style> |
|
|
23 |
|
|
|
24 |
</head> |
|
|
25 |
<body id="yahoo-com" class=" yui-skin-sam"> |
|
|
26 |
<div id="custom-doc" class="yui-t2"> |
|
|
27 |
<div id="hd"> |
|
|
28 |
<div id="ygunav"> |
|
|
29 |
<p> |
|
|
30 |
<em> |
|
|
31 |
<a href="http://developer.yahoo.com/yui/3/">YUI 3.x Home</a> <i> - </i> |
|
|
32 |
</em> |
|
|
33 |
</p> |
|
|
34 |
<form action="http://search.yahoo.com/search" id="sitesearchform"> |
|
|
35 |
<input name="vs" type="hidden" value="developer.yahoo.com"> |
|
|
36 |
<input name="vs" type="hidden" value="yuiblog.com"> |
|
|
37 |
<div id="sitesearch"> |
|
|
38 |
<label for="searchinput">Site Search (YDN & YUIBlog): </label> |
|
|
39 |
<input type="text" id="searchinput" name="p"> |
|
|
40 |
<input type="submit" value="Search" id="searchsubmit" class="ygbt"> |
|
|
41 |
</div> |
|
|
42 |
</form> |
|
|
43 |
</div> |
|
|
44 |
<div id="ygma"><a href="../../"><img src="../../assets/logo.gif" border="0" width="200" height="93"></a></div> |
|
|
45 |
<div id="pagetitle"><h1>YUI Library Examples: DataSchema Utility: DataSchema.Text</h1></div> |
|
|
46 |
</div> |
|
|
47 |
<div id="bd"> |
|
|
48 |
|
|
|
49 |
|
|
|
50 |
<div id="yui-main"> |
|
|
51 |
<div class="yui-b"> |
|
|
52 |
<div class="yui-ge"> |
|
|
53 |
<div class="yui-u first example" id="main"> |
|
|
54 |
|
|
|
55 |
<h2>DataSchema Utility: DataSchema.Text</h2> |
|
|
56 |
|
|
|
57 |
<div id="example" class="promo"> |
|
|
58 |
<div class="example-intro"> |
|
|
59 |
DataSource.Text normalizes delimited text data against a given schema into an object with known properties. |
|
|
60 |
</div> |
|
|
61 |
|
|
|
62 |
<div class="module example-container "> |
|
|
63 |
<div class="hd exampleHd"> |
|
|
64 |
<p class="newWindowButton yui-skin-sam"> |
|
|
65 |
<a href="dataschema_text_clean.html" target="_blank">View example in new window.</a> |
|
|
66 |
</p> |
|
|
67 |
</div> <div id="example-canvas" class="bd"> |
|
|
68 |
|
|
|
69 |
|
|
|
70 |
<!--BEGIN SOURCE CODE FOR EXAMPLE =============================== --> |
|
|
71 |
|
|
|
72 |
<form id="demo"> |
|
|
73 |
<h6>Data</h6> |
|
|
74 |
<pre> |
|
|
75 |
notebooks, 100, spiral-bound |
|
|
76 |
pencils, 300, #2 with erasers |
|
|
77 |
pens, 500, blue ink |
|
|
78 |
</pre> |
|
|
79 |
|
|
|
80 |
<h6>Schema</h6> |
|
|
81 |
<pre> |
|
|
82 |
{ |
|
|
83 |
resultDelimiter: "\n", |
|
|
84 |
fieldDelimiter: ",", |
|
|
85 |
resultFields: [{key:"product"}, {key:"quantity"}, {key:"detail"}] |
|
|
86 |
} |
|
|
87 |
</pre> |
|
|
88 |
|
|
|
89 |
<h6>Normalized data</h6> |
|
|
90 |
<input type="button" id="demo_apply" value="Apply schema =>"> |
|
|
91 |
<div id="demo_output" class="output"></div> |
|
|
92 |
</form> |
|
|
93 |
|
|
|
94 |
<script type="text/javascript"> |
|
|
95 |
YUI({base:"../../build/", timeout: 10000}).use("dump", "node", "dataschema-text", function (Y) { |
|
|
96 |
Y.on("click", function(e){ |
|
|
97 |
var data_in = "notebooks, 100, spiral-bound\npencils, 300, #2 with erasers\npens, 500, blue ink\n", |
|
|
98 |
schema = { |
|
|
99 |
resultDelimiter: "\n", |
|
|
100 |
fieldDelimiter: ",", |
|
|
101 |
resultFields: [{key:"product"}, {key:"quantity"}, {key:"detail"}] // Or simply: ["product", "quantity", "detail"] |
|
|
102 |
}; |
|
|
103 |
Y.get("#demo_output").setContent(Y.dump(Y.DataSchema.Text.apply(schema, data_in))); |
|
|
104 |
}, "#demo_apply"); |
|
|
105 |
}); |
|
|
106 |
</script> |
|
|
107 |
|
|
|
108 |
<!--END SOURCE CODE FOR EXAMPLE =============================== --> |
|
|
109 |
|
|
|
110 |
|
|
|
111 |
</div> |
|
|
112 |
</div> |
|
|
113 |
</div> |
|
|
114 |
|
|
|
115 |
<p>In order to use DataSchema.Text, input data must be delimited text. Define as your schema's <code>resultDelimiter</code> property the string that separates each result, and define as your schema's <code>fieldDelimiter</code> property the string that separates each field of each result.</p> |
|
|
116 |
|
|
|
117 |
<div id="syntax1" class="yui-syntax-highlight"><div class="numbers"><pre class="javascript" style="font-family:monospace;"><ol><li class="li1"><div class="de1">YUI<span class="br0">(</span><span class="br0">)</span>.<span class="kw2">use</span><span class="br0">(</span><span class="st0">"dataschema-text"</span><span class="sy0">,</span> <span class="kw2">function</span><span class="br0">(</span>Y<span class="br0">)</span> <span class="br0">{</span></div></li><li class="li1"><div class="de1"> <span class="kw2">var</span> data_in <span class="sy0">=</span> <span class="st0">"notebooks, 100, spiral-bound<span class="es0">\n</span>pencils, 300, #2 with erasers<span class="es0">\n</span>pens, 500, blue ink"</span><span class="sy0">,</span></div></li><li class="li1"><div class="de1"> schema <span class="sy0">=</span> <span class="br0">{</span></div></li><li class="li1"><div class="de1"> resultDelimiter<span class="sy0">:</span> <span class="st0">"<span class="es0">\n</span>"</span><span class="sy0">,</span></div></li><li class="li2"><div class="de2"> fieldDelimiter<span class="sy0">:</span> <span class="st0">","</span><span class="sy0">,</span></div></li><li class="li1"><div class="de1"> <span class="co1">// Or simply: ["product", "quantity", "detail"]</span></div></li><li class="li1"><div class="de1"> resultFields<span class="sy0">:</span> <span class="br0">[</span><span class="br0">{</span>key<span class="sy0">:</span><span class="st0">"product"</span><span class="br0">}</span><span class="sy0">,</span> <span class="br0">{</span>key<span class="sy0">:</span><span class="st0">"quantity"</span><span class="br0">}</span><span class="sy0">,</span> <span class="br0">{</span>key<span class="sy0">:</span><span class="st0">"detail"</span><span class="br0">}</span><span class="br0">]</span></div></li><li class="li1"><div class="de1"> <span class="br0">}</span><span class="sy0">,</span></div></li><li class="li1"><div class="de1"> data_out <span class="sy0">=</span> Y.<span class="me1">DataSchema</span>.<span class="me1">Text</span>.<span class="me1">apply</span><span class="br0">(</span>schema<span class="sy0">,</span> data_in<span class="br0">)</span><span class="br0">)</span><span class="sy0">;</span></div></li><li class="li2"><div class="de2"> </div></li><li class="li1"><div class="de1"> <span class="kw3">alert</span><span class="br0">(</span>data_out<span class="br0">)</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1"><span class="br0">}</span><span class="br0">)</span><span class="sy0">;</span></div></li></ol></pre></div><div class="nonumbers"><pre class="javascript" style="font-family:monospace;">YUI<span class="br0">(</span><span class="br0">)</span>.<span class="kw2">use</span><span class="br0">(</span><span class="st0">"dataschema-text"</span><span class="sy0">,</span> <span class="kw2">function</span><span class="br0">(</span>Y<span class="br0">)</span> <span class="br0">{</span> |
|
|
118 |
<span class="kw2">var</span> data_in <span class="sy0">=</span> <span class="st0">"notebooks, 100, spiral-bound<span class="es0">\n</span>pencils, 300, #2 with erasers<span class="es0">\n</span>pens, 500, blue ink"</span><span class="sy0">,</span> |
|
|
119 |
schema <span class="sy0">=</span> <span class="br0">{</span> |
|
|
120 |
resultDelimiter<span class="sy0">:</span> <span class="st0">"<span class="es0">\n</span>"</span><span class="sy0">,</span> |
|
|
121 |
fieldDelimiter<span class="sy0">:</span> <span class="st0">","</span><span class="sy0">,</span> |
|
|
122 |
<span class="co1">// Or simply: ["product", "quantity", "detail"]</span> |
|
|
123 |
resultFields<span class="sy0">:</span> <span class="br0">[</span><span class="br0">{</span>key<span class="sy0">:</span><span class="st0">"product"</span><span class="br0">}</span><span class="sy0">,</span> <span class="br0">{</span>key<span class="sy0">:</span><span class="st0">"quantity"</span><span class="br0">}</span><span class="sy0">,</span> <span class="br0">{</span>key<span class="sy0">:</span><span class="st0">"detail"</span><span class="br0">}</span><span class="br0">]</span> |
|
|
124 |
<span class="br0">}</span><span class="sy0">,</span> |
|
|
125 |
data_out <span class="sy0">=</span> Y.<span class="me1">DataSchema</span>.<span class="me1">Text</span>.<span class="me1">apply</span><span class="br0">(</span>schema<span class="sy0">,</span> data_in<span class="br0">)</span><span class="br0">)</span><span class="sy0">;</span> |
|
|
126 |
|
|
|
127 |
<span class="kw3">alert</span><span class="br0">(</span>data_out<span class="br0">)</span><span class="sy0">;</span> |
|
|
128 |
<span class="br0">}</span><span class="br0">)</span><span class="sy0">;</span></pre></div><textarea id="syntax1-plain">YUI().use("dataschema-text", function(Y) { |
|
|
129 |
var data_in = "notebooks, 100, spiral-bound\npencils, 300, #2 with erasers\npens, 500, blue ink", |
|
|
130 |
schema = { |
|
|
131 |
resultDelimiter: "\n", |
|
|
132 |
fieldDelimiter: ",", |
|
|
133 |
// Or simply: ["product", "quantity", "detail"] |
|
|
134 |
resultFields: [{key:"product"}, {key:"quantity"}, {key:"detail"}] |
|
|
135 |
}, |
|
|
136 |
data_out = Y.DataSchema.Text.apply(schema, data_in)); |
|
|
137 |
|
|
|
138 |
alert(data_out); |
|
|
139 |
});</textarea></div> </div> |
|
|
140 |
<div class="yui-u sidebar"> |
|
|
141 |
|
|
|
142 |
|
|
|
143 |
<div id="examples" class="mod box4"> |
|
|
144 |
<div class="hd"> |
|
|
145 |
<h4> |
|
|
146 |
DataSchema Utility Examples:</h4> |
|
|
147 |
</div> |
|
|
148 |
<div class="bd"> |
|
|
149 |
<ul> |
|
|
150 |
<li><a href='../dataschema/dataschema_array.html'>DataSchema.Array</a></li><li><a href='../dataschema/dataschema_json.html'>DataSchema.JSON</a></li><li><a href='../dataschema/dataschema_table.html'>DataSchema.XML for HTML Tables</a></li><li><a href='../dataschema/dataschema_xml.html'>DataSchema.XML for XML Data</a></li><li class='selected'><a href='../dataschema/dataschema_text.html'>DataSchema.Text</a></li><li><a href='../dataschema/dataschema_parsing.html'>Enforcing DataTypes</a></li><li><a href='../datasource/datasource_caching.html'>DataSource with Caching (included with examples for DataSource Utility)</a></li><li><a href='../datasource/datasource_function.html'>DataSource.Function (included with examples for DataSource Utility)</a></li><li><a href='../datasource/datasource_get.html'>DataSource.Get (included with examples for DataSource Utility)</a></li><li><a href='../datasource/datasource_io.html'>DataSource.IO (included with examples for DataSource Utility)</a></li><li><a href='../datasource/datasource_local.html'>DataSource.Local (included with examples for DataSource Utility)</a></li> </ul> |
|
|
151 |
</div> |
|
|
152 |
</div> |
|
|
153 |
|
|
|
154 |
<div class="mod box4"> |
|
|
155 |
<div class="hd"> |
|
|
156 |
<h4>More DataSchema Utility Resources:</h4> |
|
|
157 |
</div> |
|
|
158 |
<div class="bd"> |
|
|
159 |
<ul> |
|
|
160 |
<!-- <li><a href="http://developer.yahoo.com/yui/dataschema/">User's Guide</a> (external)</li> --> |
|
|
161 |
<li><a href="../../api/module_dataschema.html">API Documentation</a></li></ul> |
|
|
162 |
</div> |
|
|
163 |
</div> |
|
|
164 |
</div> |
|
|
165 |
</div> |
|
|
166 |
|
|
|
167 |
</div> |
|
|
168 |
</div> |
|
|
169 |
|
|
|
170 |
|
|
|
171 |
<div class="yui-b toc3" id="tocWrapper"> |
|
|
172 |
<!-- TABLE OF CONTENTS --> |
|
|
173 |
<div id="toc"> |
|
|
174 |
|
|
|
175 |
<ul> |
|
|
176 |
<li class="sect first">YUI 3 Resources</li><li class="item"><a title="YUI 3 -- Yahoo! User Interface (YUI) Library" href="http://developer.yahoo.com/yui/3/">YUI 3 Web Site</a></li><li class="item"><a title="Examples of every YUI utility and control in action" href="../../examples/">YUI 3 Examples</a></li><li class="item"><a title="Instantly searchable API documentation for the entire YUI library." href="../../api/">YUI 3 API Docs</a></li><li class="item"><a title="YUI 3 Dependency Configurator -- configure your custom YUI implementation" href="http://developer.yahoo.com/yui/3/configurator">YUI 3 Dependency Configurator</a></li><li class="item"><a title="The YUI 3 Forum on YUILibrary.com" href="http://yuilibrary.com/forum/viewforum.php?f=15">YUI 3 Forums (external)</a></li><li class="item"><a title="Found a bug or a missing feature? Let us know on YUILibrary.com." href="http://developer.yahoo.com/yui/articles/reportingbugs/">Bug Reports/Feature Requests</a></li><li class="item"><a title="YUI is free and open, offered under a BSD license." href="http://developer.yahoo.com/yui/license.html">YUI License</a></li><li class="item"><a title="Download and fork the YUI project on GitHub" href="http://github.com/yui">YUI on Github</a></li><li class="item"><a title="The Yahoo! User Interface Blog" href="http://yuiblog.com">YUI Blog (external)</a></li><li class="sect">YUI 3 Core - Examples</li><li class="item"><a title="YUI Global Object - Functional Examples" href="../../examples/yui/index.html">YUI Global Object</a></li><li class="item"><a title="Event - Functional Examples" href="../../examples/event/index.html">Event</a></li><li class="item"><a title="Node - Functional Examples" href="../../examples/node/index.html">Node</a></li><li class="sect">YUI 3 Component Infrastructure - Examples</li><li class="item"><a title="Attribute - Functional Examples" href="../../examples/attribute/index.html">Attribute</a></li><li class="item"><a title="Plugin - Functional Examples" href="../../examples/plugin/index.html">Plugin <img src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="Widget - Functional Examples" href="../../examples/widget/index.html">Widget <img src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="sect">YUI 3 Utilities - Examples</li><li class="item"><a title="Animation - Functional Examples" href="../../examples/anim/index.html">Animation</a></li><li class="item"><a title="AsyncQueue - Functional Examples" href="../../examples/async-queue/index.html">AsyncQueue</a></li><li class="item"><a title="Browser History - Functional Examples" href="../../examples/history/index.html">Browser History</a></li><li class="item"><a title="Cache - Functional Examples" href="../../examples/cache/index.html">Cache</a></li><li class="item"><a title="Cookie - Functional Examples" href="../../examples/cookie/index.html">Cookie</a></li><li class="selected "><a title="DataSchema - Functional Examples" href="../../examples/dataschema/index.html">DataSchema <img src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="DataSource - Functional Examples" href="../../examples/datasource/index.html">DataSource <img src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="DataType - Functional Examples" href="../../examples/datatype/index.html">DataType <img src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="Drag & Drop - Functional Examples" href="../../examples/dd/index.html">Drag & Drop</a></li><li class="item"><a title="Get - Functional Examples" href="../../examples/get/index.html">Get</a></li><li class="item"><a title="ImageLoader - Functional Examples" href="../../examples/imageloader/index.html">ImageLoader</a></li><li class="item"><a title="IO - Functional Examples" href="../../examples/io/index.html">IO</a></li><li class="item"><a title="JSON (JavaScript Object Notation) - Functional Examples" href="../../examples/json/index.html">JSON</a></li><li class="item"><a title="Stylesheet - Functional Examples" href="../../examples/stylesheet/index.html">Stylesheet</a></li><li class="sect">YUI 3 Widgets - Examples</li><li class="item"><a title="Overlay - Functional Examples" href="../../examples/overlay/index.html">Overlay <img src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="Slider - Functional Examples" href="../../examples/slider/index.html">Slider <img src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="sect">YUI 3 Node Plugins - Examples</li><li class="item"><a title="FocusManager Node Plugin - Functional Examples" href="../../examples/node-focusmanager/index.html">FocusManager Node Plugin <img src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="MenuNav Node Plugin - Functional Examples" href="../../examples/node-menunav/index.html">MenuNav Node Plugin <img src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="sect">YUI 3 CSS - Examples</li><li class="item"><a title="YUI CSS Reset - Functional Examples" href="../../examples/cssreset/index.html">CSS Reset</a></li><li class="item"><a title="YUI Fonts - Functional Examples" href="../../examples/cssfonts/index.html">CSS Fonts</a></li><li class="item"><a title="YUI Base - Functional Examples" href="../../examples/cssbase/index.html">CSS Base</a></li><li class="sect">YUI 3 Developer Tools - Examples</li><li class="item"><a title="Console - Functional Examples" href="../../examples/console/index.html">Console <img src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="Console Filters Plugin- Functional Examples" href="../../examples/console-filters/index.html">Plugin.ConsoleFilters <img src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="Profiler - Functional Examples" href="../../examples/profiler/index.html">Profiler</a></li><li class="item"><a title="Test - Functional Examples" href="../../examples/test/index.html">Test</a></li><li class="sect">Other Useful YUI 3 Resources</li><li class="item"><a title="Answers to Frequently Asked Questions about the YUI Library" href="http://developer.yahoo.com/yui/articles/faq/">YUI FAQ (external)</a></li><li class="item"><a title="Yahoo!'s philosophy of Graded Browser Support" href="http://developer.yahoo.com/yui/articles/gbs/">Graded Browser Support (external)</a></li><li class="item"><a title="Videos and podcasts from the YUI Team and from the Yahoo! frontend engineering community." href="http://developer.yahoo.com/yui/theater/">YUI Theater (external)</a></li></ul> |
|
|
177 |
</div> |
|
|
178 |
</div> |
|
|
179 |
</div><!--closes bd--> |
|
|
180 |
|
|
|
181 |
<div id="ft"> |
|
|
182 |
<p class="first">Copyright © 2009 Yahoo! Inc. All rights reserved.</p> |
|
|
183 |
<p><a href="http://privacy.yahoo.com/privacy/us/devel/index.html">Privacy Policy</a> - |
|
|
184 |
<a href="http://docs.yahoo.com/info/terms/">Terms of Service</a> - |
|
|
185 |
<a href="http://docs.yahoo.com/info/copyright/copyright.html">Copyright Policy</a> - |
|
|
186 |
<a href="http://careers.yahoo.com/">Job Openings</a></p> |
|
|
187 |
</div> |
|
|
188 |
</div> |
|
|
189 |
<script language="javascript"> |
|
|
190 |
var yuiConfig = {base:"../../build/", timeout: 10000}; |
|
|
191 |
</script> |
|
|
192 |
<script src="../../assets/syntax.js"></script> |
|
|
193 |
<script src="../../assets/dpSyntaxHighlighter.js"></script> |
|
|
194 |
<script language="javascript"> |
|
|
195 |
dp.SyntaxHighlighter.HighlightAll('code'); |
|
|
196 |
</script> |
|
|
197 |
</body> |
|
|
198 |
</html> |