Home > 2010 Winter BTI420 > (bonus) Additional XML technologies discussion

(bonus) Additional XML technologies discussion


For those who are interested in enhancing their knowledge of XML technologies in ASP.NET Web Forms apps, this post has coverage and links to examples.

These topics enhance your BTI420 Week 12 coverage.

.

XML documents – hierarchical and table-oriented

XML documents can contain hierarchical or table-oriented data. A hierarchical document can even have table-oriented parts to it, like a master-detail record.

.

Table-oriented data – using DataTable read/write XML methods

DataSets and DataTables are able to ReadXML and WriteXML. These methods make it very convenient to work with table-oriented data.

See today’s “…Read Into GridView” and “…Create From DAL” code examples. Both examples use very little code to do their jobs.

.

Add new data to an XML document

Today’s “…Add New Nodes” example shows us two different ways to add data to an XML document. See the code and the reference material for complete details.

.

Hierarchical data – using a TreeView control

A modern web browser (IE, Firefox, Safari) conveniently displays well-formed XML to us. What if we want a similar capability in a program?

The TreeView web server control uses an XML data source to generate a hierarchical tree. You may have used one in your programming project.

Today’s “…Read As Trees” example shows a Word 2007 document component, and a weather forecast (from Yahoo!). Note that data binding only (no code) makes them appear.

.

Navigating an XML document hierarchy using XPath

XPath is a syntax for working with – navigating – the contents of an XML document in a structured way. An XML document contains a hierarchy of information, and XPath allows you to navigate the hierarchy as though it was a “tree” structure with “nodes”. There are several kinds of “nodes”:

  • Element
  • Attribute (part of an element, right?)
  • Text (contents of an element)
  • Namespace

As you know now, elements can repeat. For example, an “employees” XML document may have an “employee” element for each employee listed in the file. XPath uses an indexing scheme (with square brackets [ ] ) to reference an element by position, and the indexer syntax includes relative positioners.

From the W3Schools documentation: “XPath uses path expressions to select nodes in an XML document. The node is selected by following a path. The most useful path expressions are listed below:”

nodename – Selects all child nodes of the nodename

/rootnode – Designates (selects) the root node

//nodename – Designates (selects) all matching nodes in the document (relative positioning)

. (single dot) – Selects the current node

. . (two dots) – Selects the parent of the current node

@ (at sign) – Selects the attributes of a node

There is additional syntax for storing, querying, manipulating, and operating on paths. See the reference material for more information.

The .NET Framework has classes that implement XPath, which (in our situation today) allow us to get information from an XML document.

.

Working with a Yahoo! weather forecast

The “…Read As Trees With Code” example digs into the weather forecast document. You begin to learn about the .NET Framework’s XML classes that enable you to navigate and extract data from a document.

.


Advertisements
Categories: 2010 Winter BTI420
  1. Edgardo Arvelaez
    May 9, 2010 at 7:23 pm

    I have been practicing with XML and Ajax by making a service that “serves” Xml (roughly, it serves source code, and brushes and themes to highlight it).

    It is very interesting that Firefox divides text nodes into 4K pieces. It took me forever to figure out. So if an Xml element contains a value node (text) of more than 46 characters, firefox will fragment it into pieces of 4K.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: