Content by Category
.NET 1.x
.NET 2.0
.NET 3.0
.NET 3.5
.NET 4.0
.NET 4.5
.NET Assemblies
.NET Framework
.NET Getting Started
Accessibility
ADO.NET
Advertorials
Agile Development
AJAX
Amazon Web Services
Analysis Services
Android
Architecture
Arduino
ASP .NET Web API
ASP.NET
ASP.NET MVC
ASP.NET WebForms
Azure
B2B (Business Integration)
BDD
Big Data
Bing
BizTalk
Book Excerpts
Build and Deploy
Business Intelligence
C#
C++
ClickOnce
Cloud Computing
Code Contracts
CODE Framework Info - non Technical
CODE on the Road!
COM+
Community
Conferences
Continuous Integration
Crystal Reports
CSLA.NET
CSS
Data
Debugger
Design Patterns
Development Process
Display Technologies
Distributed Computing
Document Database
DotNetNuke
DSL
Dynamic Languages
Dynamic Programming
Editorials
Enterprise Services ("COM+")
Entity Framework
Events
Expression Blend
F#
Fox to Fox
Frameworks
Functional Programming
Git
Graphics
HTML 5
Internet Explorer 8.0
Interviews
IOS
iPhone
Iron Ruby
Java
Java Script
JavaScript
jQuery
JSON
Lightswitch
LINQ
Linux
LUA
Mac OS X
MDX
Messaging
Metro
Microsoft Application Blocks
Microsoft Business Rules Framework
Microsoft Dynamics
Microsoft Expression
Microsoft Office
Mobile Development
Mobile PC
Mono
MsBuild
MVVM
MySQL
Network
NHibernate
node.js
NOSQL
Nuget
Object Oriented Development
Objective C
Odata
OLAP
Open Source
Opinion
Opinions
Oracle
ORM
Other Languages
Parallel Programming
Patterns
PHP
Podcasts
Post Mortem
PowerPoint
Print/Output
Prism
Product News
Product Reviews
Project Management
Prolog
Python
Q&A
Rails
Rake
Razor
Reporting Services
REST
RIA Services
Ruby
Ruby on Rails
Scheme
Search
Security
Services
SharePoint
SignalR
Silverlight
SOA
Social Networks
Software & Law
Software Business
Source Control
Speech-Enabled Applications
SQL Server
SQL Server 2000
SQL Server 2005
SQL Server 2008
SQL Server 2012
SQL Server CE/AnyWhere/Mobile/Compact
SSIS
Subversion
Sync Framework
Tablet PC
TDD
Team System
Techniques
Testing and Quality Control
TFS
Tips
TypeScript
UI Design
UML
User Groups
VB Script
VB.NET
Version Control
VFP and .NET
VFP and SQL Server
Virtual Earth
Vista
Visual Basic
Visual Basic 6 (and older)
Visual FoxPro
Visual Studio .NET
Visual Studio 11
Visual Studio 2005
Visual Studio 2008
Visual Studio 2010
Visual Studio 2011
Visual Studio 2012
Visual Studio Tools for Office
VSX
WCF
Web Development (general)
Web Services
WebMatrix
WF
Whitepapers
Windows 7
Windows 8
Windows Azure
Windows Live
Windows Phone 7
Windows Phone SDK
Windows Server
Windows Vista
WinForms
WinRT
Workflow
WPF
XAML
Xiine Documentation
XML
XNA
XSLT



LearnNow


XAMALOT
 


SSWUG

Reader rating:
Article source: CoDe (2001 - Issue 1)


Article Pages:  1  2 3 - Next >


XPath Queries in SQL Server 2000

Imagine the potential of accessing your database without needing to know any specifics about how that data is stored.Imagine the possibility of allowing your DBA the freedom to change the database structure without affecting your software code. Impossible? Not with XPath Queries and XDR Schemas. Using these two methods, practically any developer can write a program to access data in SQL Server 2000, just by knowing the structure of the XML documents returned by the server.

In the last issue, we discussed querying XML data from SQL Server 2000 using a combination of URL Queries and Template Queries. While both types of queries allow the developer to retrieve XML data from SQL Server 2000, they do require knowledge of SQL Select statements, stored procedures, and the structure of the database. However, by using XPath Queries in conjunction with XDR Schemas, these requirements can be removed.

XML - Data Reduced (XDR) Schemas define the structure of the XML document returned from SQL Server 2000 and enable various constraints to be placed upon the data returned. Unlike a Document Type Definition (DTD), an XML Schema describes the structure of an XML document using XML syntax. Also, DTDs treat all data content as character type, whereas XML Schemas allow the specification of various data types for XML elements and attributes.

Authoring XDR Schemas

An XML - Data Reduced Schema is simply an XML Schema with specific attributes used in defining the XML elements and attributes. Every XDR Schema must include the following:

<?xml version = "1.0" ?>
<Schema
 xmlns="urn:schemas-microsoft-com:xml-data"
 xmlns:dt="urn:schemas-microsoft-com:datatypes"
 xmlns:sql="urn:schemas-microsoft-com:xml-sql">

   . . .

</Schema>

Notice that the above example is an XML document with a root node of Schema. This may or may not make sense to you. Remember that an XML Schema defines the structure and data constraints of an XML document using XML syntax.

There are 2 basic attributes and 1 basic element needed to author XDR Schemas. The attributes needed are sql:field and sql:relation, and the element is the sql:relationship element. The sql:relation attribute is used to map an element to a table in the database. This has the effect of creating one XML element for every record in the table. The sql:field attribute is used to map a particular attribute or node value to a field from the related table. The sql:relationship element is used to relate elements within the XML document to other elements. It specifies the 2 tables and defines the join condition necessary to relate them together.

Using those XDR attributes and elements, an XDR schema can be authored to return data from SQL Server 2000 in a specific XML format. The only required XDR attribute is sql:relation, which refers to a table or view in the database and can be placed on an ElementType, element, or attribute in the XDR Schema. The following is a simple example of using sql:relation in an XDR Schema to expose the Customer table from the Northwind database in XML format:

<?xml version="1.0" encoding="windows-1252" ?>
<Schema
 xmlns="urn:schemas-microsoft-com:xml-data"
 xmlns:dt="urn:schemas-microsoft-com:datatypes"
 xmlns:sql="urn:schemas-microsoft-com:xml-sql">

   <AttributeType name="CustomerID"/>
   <AttributeType name="CompanyName"/>
   <AttributeType name="ContactName"/>
   <AttributeType name="Address"/>
   <AttributeType name="City"/>
   <AttributeType name="Phone"/>

   <ElementType name="CUSTOMER"
    sql:relation="Customers">
      <attribute type="CustomerID"/>
      <attribute type="CompanyName"/>
      <attribute type="ContactName"/>
      <attribute type="Address"/>
      <attribute type="City"/>
      <attribute type="Phone"/>
   </ElementType>
</Schema>

Note that this example exposes only 6 fields from the Customer table. We first specify 6 different attribute types with the same names as the field names in the database. We then specify the customer element, which uses the 6 attributes defined above.

By specifying the sql:relation attribute on an ElementType element within our schema, the relation is inherited by all elements and attributes of that ElementType. This means that we do not need to specify the sql:relation attribute on every element or attribute within our schema to indicate that they all are populated from the Customer table. Because we defined our attribute names just as they exist in the Northwind database, we did not need to use the sql:field attribute (which would allow us to map a field to an attribute of a different name). Keep in mind that XML is case?sensitive. Therefore, the attribute names defined above must match exactly with the field names defined in the database for this XDR Schema to work. The schema returns an XML document whose structure matches the definition in the schema (see Figure 1).

Click for a larger version of this image.

Figure 1 - Internet Explorer displays a sample XML data set returned from SQL Server 2000 using just the sql:relation attribute.

&

By: Travis Vandersypen

Travis Vandersypen is a Senior Software Developer at EPS Software Corporation, located in Houston, Texas.

He concentrates on consulting on and developing COM-based, distributed applications. He is an international author and speaker, co-author of the Fox Extension Classes, co-author of the Voodoo Web Controls, and 3-time Visual FoxPro Excellence Award Nominee.

He can be reached via email at: travis@eps-software.com.

travis@dilmad.com

Fast Facts

XPath Queries in conjunction with XDR Schemas remove the need to know about SQL Select statements, stored procedures, and the structure of the database. This gives the DBA the freedom to make database structure and stored procedure changes without needing to change the software code itself.



Article Pages:  1  2 3 - Next Page: 'XPath Queries in SQL Server 2000 (con't)' >>

Page 1: XPath Queries in SQL Server 2000
Page 2: XPath Queries in SQL Server 2000 (con't)
Page 3: XPath Queries

How would you rate the quality of this article?
1 2 3 4 5
Poor      Outstanding

Tell us why you rated the content this way. (optional)

Average rating:
3.5 out of 5

2 people have rated this article.

Instantly Search Terabytes Of Text
“Lightning Fast”
– Redmond Mag
“Covers all data
sources” – eWeek
25+ fielded & full-text search options
dtSearch’s own document filters highlight hits in popular file types
Web Spider supports static & dynamic data
APIs for .NET, Java, C++, SQL, etc.
Win / Linux (64-bit & 32-bit)
www.dtSearch.com
 

      Sharepoint TechCon

 

SSWUG