dataschema-xml-source.mustache revision 8f9d94fb7812612dff92ce14a37dbcad4ff02c1c
2f1059efb713a28a3c059293b37dc274577b3344Michael Graff<style scoped>
2f1059efb713a28a3c059293b37dc274577b3344Michael Graff/* custom styles for this example */
2f1059efb713a28a3c059293b37dc274577b3344Michael Graff#demo .output {margin-bottom:1em; padding:10px; border:1px solid #D9D9D9;}
2f1059efb713a28a3c059293b37dc274577b3344Michael Graff<form id="demo">
2f1059efb713a28a3c059293b37dc274577b3344Michael Graff <h4>Basic example</h4>
2f1059efb713a28a3c059293b37dc274577b3344Michael Graff <h6>Data</h6>
2f1059efb713a28a3c059293b37dc274577b3344Michael Graff <session>34637542</session>
2f1059efb713a28a3c059293b37dc274577b3344Michael Graff <category name="music" id="5"><results>
2f1059efb713a28a3c059293b37dc274577b3344Michael Graff <song id="59672468">
2f1059efb713a28a3c059293b37dc274577b3344Michael Graff <title>I Kissed A Girl</title>
2f1059efb713a28a3c059293b37dc274577b3344Michael Graff <rank>1</rank>
2f1059efb713a28a3c059293b37dc274577b3344Michael Graff <artist id="30326214">Katy Perry</artist>
2f1059efb713a28a3c059293b37dc274577b3344Michael Graff </song>
2f1059efb713a28a3c059293b37dc274577b3344Michael Graff <song id="47973564">
2f1059efb713a28a3c059293b37dc274577b3344Michael Graff <title>Shake It</title>
6ba9a5003193570e76c857f027a614e84e881a50David Lawrence <rank>2</rank>
60a7475dd868cb0bc4796378a17f0810b606653bMichael Graff <artist id="45575683">Metro Station</artist>
2f1059efb713a28a3c059293b37dc274577b3344Michael Graff </song>
60a7475dd868cb0bc4796378a17f0810b606653bMichael Graff <song id="52207363">
2f1059efb713a28a3c059293b37dc274577b3344Michael Graff <title>Bleeding Love</title>
2f1059efb713a28a3c059293b37dc274577b3344Michael Graff <rank>3</rank>
2f1059efb713a28a3c059293b37dc274577b3344Michael Graff <artist id="37956508">Leona Lewis</artist>
016742f7d800837ef0e1654123adccdddfaa8886Michael Graff </song>
b48abf6b8539608f868a17bfe429a4b4f992116dMichael Graff </results></category>
016742f7d800837ef0e1654123adccdddfaa8886Michael Graff <h6>Schema</h6>
2f1059efb713a28a3c059293b37dc274577b3344Michael Graff resultListLocator: "song",
2f1059efb713a28a3c059293b37dc274577b3344Michael Graff resultFields: [{key:"title"}, {key:"artist"}, {key:"rank"}]
2f1059efb713a28a3c059293b37dc274577b3344Michael Graff <h6>Normalized data</h6>
b48abf6b8539608f868a17bfe429a4b4f992116dMichael Graff <input type="button" id="demo_apply_basic" value="Apply schema =>">
b48abf6b8539608f868a17bfe429a4b4f992116dMichael Graff <div id="demo_output_basic" class="output"></div>
b48abf6b8539608f868a17bfe429a4b4f992116dMichael Graff <h4>Complex example</h4>
b48abf6b8539608f868a17bfe429a4b4f992116dMichael Graff <h6>Data</h6>
2f1059efb713a28a3c059293b37dc274577b3344Michael Graff<Response>
2f1059efb713a28a3c059293b37dc274577b3344Michael Graff <Session>542235629</Session>
2f1059efb713a28a3c059293b37dc274577b3344Michael Graff <Tracks start="1" count="10" total="98" errorCount="0"
2f1059efb713a28a3c059293b37dc274577b3344Michael Graff defaultSort="popularity+" description="Top 100 Tracks"
2f1059efb713a28a3c059293b37dc274577b3344Michael Graff name="Top 100 Tracks">
2f1059efb713a28a3c059293b37dc274577b3344Michael Graff <Track id="59672468" rating="-1" title="I Kissed A Girl">
2f1059efb713a28a3c059293b37dc274577b3344Michael Graff <Artist id="30326214" rating="-1">Katy Perry</Artist>
2f1059efb713a28a3c059293b37dc274577b3344Michael Graff <ItemInfo><ChartPosition last="26" this="1"/></ItemInfo>
c498b4be95bbed82ff406454e36016d6761bc1d8Michael Graff </Track>
79fdce6aff049fde7ac8aa6c35a4fac24c4c0b06Michael Graff <Track id="47973564" rating="-1" title="Shake It">
2f1059efb713a28a3c059293b37dc274577b3344Michael Graff <Artist id="45575683" rating="-1">Metro Station</Artist>
2f1059efb713a28a3c059293b37dc274577b3344Michael Graff <ItemInfo><ChartPosition last="27" this="2"/></ItemInfo>
016742f7d800837ef0e1654123adccdddfaa8886Michael Graff </Track>
016742f7d800837ef0e1654123adccdddfaa8886Michael Graff <Track id="52207363" rating="-1" title="Bleeding Love">
2f1059efb713a28a3c059293b37dc274577b3344Michael Graff <Artist id="37956508" rating="-1">Leona Lewis</Artist>
016742f7d800837ef0e1654123adccdddfaa8886Michael Graff <ItemInfo><ChartPosition last="28" this="3"/></ItemInfo>
c498b4be95bbed82ff406454e36016d6761bc1d8Michael Graff </Track>
2f1059efb713a28a3c059293b37dc274577b3344Michael Graff </Tracks>
2f1059efb713a28a3c059293b37dc274577b3344Michael Graff</Response>
016742f7d800837ef0e1654123adccdddfaa8886Michael Graff <h6>Schema</h6>
c6e2d36708ce0caa235de426dbda5924d758f272Michael Graff metaFields: {session:"//Session", total:"//Tracks/@total"},
527bf549959ae9c8b8e240cf93d18fb60c4772dcMichael Graff resultListLocator: "//Track",
527bf549959ae9c8b8e240cf93d18fb60c4772dcMichael Graff resultFields: [{key:"song", locator:"@title"},
118332fc5c23ebdcdf43413b0be7ed13fb0aa627Michael Graff {key:"artist", locator:"Artist"},
527bf549959ae9c8b8e240cf93d18fb60c4772dcMichael Graff {key:"rank", locator:"ItemInfo/ChartPosition/@this"}]
016742f7d800837ef0e1654123adccdddfaa8886Michael Graff <h6>Normalized data</h6>
c6e2d36708ce0caa235de426dbda5924d758f272Michael Graff <input type="button" id="demo_apply_complex" value="Apply schema =>">
8422b3823f26d34a54d9d5852fccf05b19c483acMichael Graff <div id="demo_output_complex" class="output"></div>
b90f80957a972c969a98d0ce74828fb1816572baMichael Graff <h4>Nested example</h4>
8422b3823f26d34a54d9d5852fccf05b19c483acMichael Graff <h6>Data</h6>
c3581e2bccf659792bf78e0f672b23f9e42dddc5Michael Graff<desserts>
c3581e2bccf659792bf78e0f672b23f9e42dddc5Michael Graff <dessert type="treat">
016742f7d800837ef0e1654123adccdddfaa8886Michael Graff <name>cupcake</name>
016742f7d800837ef0e1654123adccdddfaa8886Michael Graff <flavors>
2f1059efb713a28a3c059293b37dc274577b3344Michael Graff <flavor name="chocolate"/>
2f1059efb713a28a3c059293b37dc274577b3344Michael Graff <flavor name="red velvet"/>
527bf549959ae9c8b8e240cf93d18fb60c4772dcMichael Graff </flavors>
527bf549959ae9c8b8e240cf93d18fb60c4772dcMichael Graff </dessert>
527bf549959ae9c8b8e240cf93d18fb60c4772dcMichael Graff <dessert type="treat">
270ad529d381a3213e1cb3789105785ae374c287Michael Graff <name>ice cream</name>
270ad529d381a3213e1cb3789105785ae374c287Michael Graff <flavors>
270ad529d381a3213e1cb3789105785ae374c287Michael Graff <flavor name="chocolate"/>
fd316ab4f9c475e62b0d32f5498dcc3c7e081e34Michael Graff <flavor name="strawberry"/>
270ad529d381a3213e1cb3789105785ae374c287Michael Graff <flavor name="vanilla"/>
e92d6ed5e7e5b5d4f1a2351eb96a4561bda3c002Michael Graff </flavors>
fd316ab4f9c475e62b0d32f5498dcc3c7e081e34Michael Graff </dessert>
fd316ab4f9c475e62b0d32f5498dcc3c7e081e34Michael Graff <dessert type="treat">
fd316ab4f9c475e62b0d32f5498dcc3c7e081e34Michael Graff <name>pie</name>
fd316ab4f9c475e62b0d32f5498dcc3c7e081e34Michael Graff <flavors>
b9672b61d80fb79a15d6e188732364207079a39aMichael Graff <flavor name="banana cream"/>
fd316ab4f9c475e62b0d32f5498dcc3c7e081e34Michael Graff <flavor name="blueberry"/>
fd316ab4f9c475e62b0d32f5498dcc3c7e081e34Michael Graff <flavor name="cherry"/>
fd316ab4f9c475e62b0d32f5498dcc3c7e081e34Michael Graff </flavors>
fd316ab4f9c475e62b0d32f5498dcc3c7e081e34Michael Graff </dessert>
fd316ab4f9c475e62b0d32f5498dcc3c7e081e34Michael Graff <dessert type="beverage">
fd316ab4f9c475e62b0d32f5498dcc3c7e081e34Michael Graff <name>hot chocolate</name>>
e92d6ed5e7e5b5d4f1a2351eb96a4561bda3c002Michael Graff </dessert>
270ad529d381a3213e1cb3789105785ae374c287Michael Graff <dessert type="beverage">
270ad529d381a3213e1cb3789105785ae374c287Michael Graff <name>port wine</name>
016742f7d800837ef0e1654123adccdddfaa8886Michael Graff </dessert>
270ad529d381a3213e1cb3789105785ae374c287Michael Graff</desserts>
270ad529d381a3213e1cb3789105785ae374c287Michael Graff <h6>Schema</h6>
60a7475dd868cb0bc4796378a17f0810b606653bMichael Graff resultListLocator: "dessert",
270ad529d381a3213e1cb3789105785ae374c287Michael Graff resultFields: [
270ad529d381a3213e1cb3789105785ae374c287Michael Graff {key:"type", locator:"@type"},
60a7475dd868cb0bc4796378a17f0810b606653bMichael Graff {key:"name", locator:"name"},
60a7475dd868cb0bc4796378a17f0810b606653bMichael Graff {key:"flavors", schema: {
fd316ab4f9c475e62b0d32f5498dcc3c7e081e34Michael Graff resultListLocator: "flavor",
270ad529d381a3213e1cb3789105785ae374c287Michael Graff resultFields: [
016742f7d800837ef0e1654123adccdddfaa8886Michael Graff {key:"flavor", locator:"@name"}
016742f7d800837ef0e1654123adccdddfaa8886Michael Graff <h6>Normalized data</h6>
016742f7d800837ef0e1654123adccdddfaa8886Michael Graff <input type="button" id="demo_apply_nested" value="Apply schema =>">
016742f7d800837ef0e1654123adccdddfaa8886Michael Graff <div id="demo_output_nested" class="output"></div>
016742f7d800837ef0e1654123adccdddfaa8886Michael GraffYUI().use("dump", "node", "datatype-xml", "dataschema-xml", function (Y) {
016742f7d800837ef0e1654123adccdddfaa8886Michael Graff Y.on("click", function(e){
016742f7d800837ef0e1654123adccdddfaa8886Michael Graff var data_in = Y.DataType.XML.parse('<root><session>34637542</session><category name="music" id="5"><results><song id="59672468"><title>I Kissed A Girl</title><rank>1</rank><artist id="30326214">Katy Perry</artist></song><song id="47973564"><title>Shake It</title><rank>2</rank><artist id="45575683">Metro Station</artist></song><song id="52207363"><title>Bleeding Love</title><rank>3</rank><artist id="37956508">Leona Lewis</artist></song></results></category></root>'),
60a7475dd868cb0bc4796378a17f0810b606653bMichael Graff resultListLocator: "song",
60a7475dd868cb0bc4796378a17f0810b606653bMichael Graff resultFields: [{key:"title"}, {key:"artist"}, {key:"rank"}] // Or simply ["title", "artist", "rank"]
79fdce6aff049fde7ac8aa6c35a4fac24c4c0b06Michael Graff Y.one("#demo_output_basic").setContent(Y.dump(Y.DataSchema.XML.apply(schema, data_in)));
79fdce6aff049fde7ac8aa6c35a4fac24c4c0b06Michael Graff }, "#demo_apply_basic");
b9672b61d80fb79a15d6e188732364207079a39aMichael Graff Y.on("click", function(e){
b9672b61d80fb79a15d6e188732364207079a39aMichael Graff var data_in = Y.DataType.XML.parse('<Response><Session>542235629</Session><Tracks start="1" count="10" total="98" errorCount="0" defaultSort="popularity+" description="Top 100 Tracks" name="Top 100 Tracks" ><Track id="59672468" rating="-1" title="I Kissed A Girl"><Artist id="30326214" rating="-1">Katy Perry</Artist><ItemInfo><ChartPosition last="26" this="1"/></ItemInfo></Track><Track id="47973564" rating="-1" title="Shake It"><Artist id="45575683" rating="-1">Metro Station</Artist><ItemInfo><ChartPosition last="27" this="2"/></ItemInfo></Track><Track id="52207363" rating="-1" title="Bleeding Love"><Artist id="37956508" rating="-1">Leona Lewis</Artist><ItemInfo><ChartPosition last="28" this="3"/></ItemInfo></Track></Tracks></Response>'),
fd316ab4f9c475e62b0d32f5498dcc3c7e081e34Michael Graff metaFields: {session:"//Session", total:"//Tracks/@total"},
fd316ab4f9c475e62b0d32f5498dcc3c7e081e34Michael Graff resultListLocator: "//Track",
fd316ab4f9c475e62b0d32f5498dcc3c7e081e34Michael Graff resultFields: [{key:"song", locator:"@title"}, {key:"artist", locator:"Artist"}, {key:"rank", locator:"ItemInfo/ChartPosition/@this"}]
fd316ab4f9c475e62b0d32f5498dcc3c7e081e34Michael Graff Y.one("#demo_output_complex").setContent(Y.dump(Y.DataSchema.XML.apply(schema, data_in)));
fd316ab4f9c475e62b0d32f5498dcc3c7e081e34Michael Graff }, "#demo_apply_complex");
fd316ab4f9c475e62b0d32f5498dcc3c7e081e34Michael Graff Y.on("click", function(e){
fd316ab4f9c475e62b0d32f5498dcc3c7e081e34Michael Graff var data_in = Y.DataType.XML.parse('<desserts><dessert type="treat"><name>cupcake</name><flavors><flavor name="chocolate"/><flavor name="red velvet"/></flavors></dessert><dessert type="treat"><name>ice cream</name><flavors><flavor name="chocolate"/><flavor name="strawberry"/><flavor name="vanilla"/></flavors></dessert><dessert type="treat"><name>pie</name><flavors><flavor name="banana cream"/><flavor name="blueberry"/><flavor name="cherry"/></flavors></dessert><dessert type="beverage"><name>hot chocolate</name></dessert><dessert type="beverage"><name>port wine</name></dessert></desserts>'),
fd316ab4f9c475e62b0d32f5498dcc3c7e081e34Michael Graff resultListLocator: "dessert",
fd316ab4f9c475e62b0d32f5498dcc3c7e081e34Michael Graff resultFields: [
fd316ab4f9c475e62b0d32f5498dcc3c7e081e34Michael Graff {key:"type", locator:"@type"},
fd316ab4f9c475e62b0d32f5498dcc3c7e081e34Michael Graff {key:"name", locator:"name"},
fd316ab4f9c475e62b0d32f5498dcc3c7e081e34Michael Graff {key:"flavors", schema: {
fd316ab4f9c475e62b0d32f5498dcc3c7e081e34Michael Graff resultListLocator: "flavor",
fd316ab4f9c475e62b0d32f5498dcc3c7e081e34Michael Graff resultFields: [
fd316ab4f9c475e62b0d32f5498dcc3c7e081e34Michael Graff {key:"flavor", locator:"@name"}
fd316ab4f9c475e62b0d32f5498dcc3c7e081e34Michael Graff Y.one("#demo_output_nested").setContent(Y.dump(Y.DataSchema.XML.apply(schema, data_in)));
fd316ab4f9c475e62b0d32f5498dcc3c7e081e34Michael Graff }, "#demo_apply_nested");