YUI Library Home

Site Search (YDN & YUIBlog):

# YUI Library Examples: DataTable Control: XML Data with XPath

# DataTable Control: XML Data with XPath

This DataTable is populated with XML data where the schema is defined using XPath-syntax locators. Please note that namespace support is not implemented at this time.

View example in new window.

When working with XML data, use the DataSource's `useXPath` property to enable XPath syntax in your locator strings.

## Sample Code for this Example

Data:

<myroot rootatt='5'> <top>topvalue</top> <second nested='nestedsecond' /> <allitems> <livehere> <item type='foo'> <name type='nametype0'>Abc</name> <rank>0</rank> <subitem> <name type='subnametype0'>subABC</name> <age>10</age> </subitem> </item> <item type='bar'> <name type='nametype1'>Def</name> <rank>1</rank> <subitem> <name type='subnametype1'>subDEF</name> <age>11</age> </subitem> </item> <item type='bat'> <name type='nametype2'>Ghi</name> <rank>2</rank> <subitem> <name type='subnametype2'>subGHI</name> <age>12</age> </subitem> </item> </livehere> </allitems> </myroot>

CSS:

/* No custom CSS. */

Markup:

<div id="xpath"></div>

JavaScript:

YAHOO.util.Event.addListener(window, "load", function() { YAHOO.example.XPath = function() { var myColumnDefs = [ {key:"type"}, {key:"rank"}, {key:"subnameatt"}, {key:"age"}, {key:"name"} ]; var myDataSource = new YAHOO.util.DataSource("assets/php/xml_proxy.php"); myDataSource.responseType = YAHOO.util.DataSource.TYPE_XML; myDataSource.useXPath = true; myDataSource.responseSchema = { metaFields: {rootatt:"/myroot/@rootatt", topnode:"//top", nestedatt:"//second/@nested"}, resultNode: "item", fields: [{key:"type", locator:"@type"}, {key:"rank", parser:"number"}, "name", {key:"subnameatt", locator:"subitem/name/@type"}, {key:"age", locator:"subitem/age", parser:"number"}] }; var myDataTable = new YAHOO.widget.DataTable("xpath", myColumnDefs, myDataSource); return { oDS: myDataSource, oDT: myDataTable }; }(); });

## Configuration for This Example

You can load the necessary JavaScript and CSS for this example from Yahoo's servers. Click here to load the YUI Dependency Configurator with all of this example's dependencies preconfigured.

### YUI Logger Output:

Note: Logging and debugging is currently turned off for this example.

Reload with logging
and debugging enabled.

### DataTable Control Examples:

- Basic Example
- Progressive Enhancement
- Custom Cell Formatting
- Conditional row coloring
- Nested Headers
- JSON Data Over XHR
- XML Data Over XHR With POST
- XML Data with XPath
- Textual Data Over XHR
- Polling the DataSource
- Adding, Updating, and Deleting Rows
- Client-side Pagination
- Client-side Sorting
- Server-side Pagination and Sorting for Dynamic Data
- Integrating Browser History Manager with Server-side Pagination and Sorting
- XY-scrolling, Y-scrolling, and X-scrolling
- Row Selection
- Cell Selection
- Inline Cell Editing
- Showing, Hiding, and Reordering Columns.
- Highlighting Cells, Rows, or Columns
- Reorder Rows with Drag and Drop
- Row Expansion
- Context Menu Integration
- Configuring the Paginator (included with examples for Paginator)
- TabView Integration
- Complex Example of Multiple Features
- Client-side Filtering of Local Data
- Filtering of Dynamic Data
- Datatable with Autocomplete
- Skinning Model
- Ratings (included with examples for ProgressBar Control)
- YQLDataSource (included with examples for DataSource Utility)
- Complex Application (included with examples for Layout Manager)

### More DataTable Control Resources:

- User's Guide (external)
- API Documentation
- Cheat Sheet PDF (external)

Copyright © 2010 Yahoo! Inc. All rights reserved.

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