BizTalk Utilities CV ,   Jobs ,   Code library  
 
Home Page
SQL XML
SQLXML - Mapping Relationships To XML
SQLXML - Mapping .NET Schemas
.NET & OPENXML
.NET Parameterized Templates
SQLXML - Raw mode
SQLXML - FOR XML mode
Automate saving options from ADO into an XML format
Microsoft's dataselect functionality in the XML DSO
VB/ADO to DataIsland
Inserting nodes: String Load or Dom Load?
WebDAVExplorer
XML-based Internet RPC (XIR)
XDO
Translating an ADO recordset's XML to another XML vocab
How to find distinct values from XML (Muenchian Technique)
Converting to DateTime format in SQL
Filtering unique values
Passing stored procedure a list of complete zipcodes to validate
Convert a flat text file into xml
XML IMDB Concepts.
<< SEO
System.XML >>

By :Mark Wilson
I am the creator of TopXML. I am available for international and local (Australia) contracts. I am a Solution Architect/Business Analyst. I have worked in IT in several countries (NZ, Australia, South Africa, UK) building and training teams for government and very large non-governmental organizations. I am ex-Microsoft Consulting Services. I wrote the first book on Microsoft XML published in 2000 called XML Programming with VB and ASP. Most recently I have been building tools for the SEO industry. Ask me for a 37 point SEO health-checkup for your website.
First posted :03/24/2008
Times viewed :460

 

.NET XPath Queries

With SQL Server and SQLXML we can query data with XPath queries to navigate around XML documents. Together with the query we have to specify a mapping schema to define how the format of the query maps to the database schema. SQLXML first inspects the mapping schema and transforms the XPath expression into a SELECT … FOR XML EXPLICIT statement. It will then send the FOR XML EXPLICIT query to SQL Server to retrieve the data in the XML format defined in the mapping schema.


 There are several advantages to define your DB-to-XML mappings using annotated schemas when we need to retrieve data from the database and convert it to a fixed format. First of all, they relieve us from writing any code to convert data returned from the database into the XML format. We simply point SQLXML to the mapping schema and the conversion happens behind the scenes. Furthermore, all the information about how your XML maps to your database resides in one place outside of the compiled code. This helps to further reduce development time as you can quickly propagate changes to the mapping during development or if you find any bugs after you deployed your application to your production environment. Also, querying object hierarchies with XPath expressions is much simpler and more readable than using SQL statements joining several tables. Don’t you agree that querying the database for an XML structure of Orders with nested OrderItem elements like this

<OrderHeader>

      <OrderID />

      <OrderDate />

      <OrderItem>

            <ProductID>1<ProductID>

            <Quantity>10</Quantity>

      </OrderItem>

</OrderHeader>

with the XPath expression

/OrderHeader/OrderLine[ProductID=1]

is much easier to read than:

SELECT     OrderLine.*, OrderHeader.*

FROM       OrderHeader INNER JOIN

           OrderLine ON OrderHeader.OrderID = OrderLine.OrderID

WHERE      OrderLine.ProductID = 1

Finally, I prefer XPath queries over SQL statements, especially when it comes to writing re-usable components, because the fields returned by the query are defined by the type definition of the type you are retrieving, not by the query itself. So much for retrieving XML from the database, now let’s see how we can modify a SQL Server database when have an XML document and a mapping schema.

WARNING: SQLXML 3.0 does not support the XPath functions and operators: xmlns, descendant-or-self, preceding-sibling, preceding, namespace, following-sibling, followingdescendant, ancestor-or-self, ancestor, ceiling(), mod, concat(), floor(),  count(), contains(), id(), translate(), sum(), substring-before(), substring-after(), substring(), string-length(), starts-with(), round(), normalize-space(), namespace-uri(), name(), local-name(),  position(), last(), lang() as well as node tests with the * wildcard.


Rate this article on a scale of 1 to 10

Your vote :  


 

Recent Jobs

Software Developers Needed in Charl
Sr. Software Engineer - Analytics
Immediate Mainframe openings for Ch
Immediate TANDEM-TAL openings for C
Immediate ASP.NET/C# Openings for C

View all Jobs (Add yours)
View all CV (Add yours)



conference calling
swimming pool builder
spfxmasks
water softener
Teleconference
Host Department NOLIMIT Web Hosting
MSN
sunglasses


    Email TopXML  

Front Page Daily Stuff TopXML Forum XML blogs XML Newsgroups BizTalk Biztalk Utilities Biztalk Utilities Tutorial B2B SAP XML Microsoft .NET Dotnet System XML Soapformatter SQLXML XMLserializer XQuery PHP PHP SimpleXML PHP XML Dom PHP XML RPC PHP XSLT Java Java Java XML Xalan Microsoft ASP ASP Schemas XML SQL Server XML XMLDom XSL XSL Tutorial XSLT Stylesheets General Javascript CSS XHTML WAP