BizTalk Utilities CV ,   Jobs ,   Code library  
 
Home Page
XQuery
ASP.NET Code Explaination
XQuery Validate Expressions
XQuery Expressions on Datatypes
XQuery Quantified Expressions
XQuery Conditional Expressions
XQuery Sorting Expressions
XQuery FLWR Expressions
XQuery Constructors
XQuery Logical Expressions
XQuery Comparison Expressions
XQuery Arithmetic Expressions
XQuery Sequence Expressions
Path Expressions
XQuery Primary Expressions
Programming with XQuery classes
XQuery Demo namespace
XQuery Demo
What is XQuery and ASP.NET?
What is XQuery?
Why do I need XQuery when I already have XSLT/XPath?
<< XmlSerializer
XSLT >>
 

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 :319

 

XQuery Expression Tester

In this section, we'll create a simple ASP.NET Web Application letting the user cut and paste their XML source in a textbox, and then copy and paste the xquery and run it using the MS XQuery .NET Managed class set. The input will be captured and fed into a XmlDocument. Note that the XmlDocument from the System.Xml namespace is used here, instead of XQuerydocument.

The resulting output is shown using the XML Web Control, after having it applied an XSL Stylesheet, to display the results in a more neat and readable XML format.

Creating the project

Creating the project is simple. Start VS.NET 2003 and click the New Project link on the start page. Choose Visual C# Projects, and in the right pane, choose ASP.NET Web Application. Enter its name, "XQueryTester". Click OK and wait until the classes are created.

Then, delete ‘WebForm1.aspx’ and add the page ‘XQT.aspx’ from the download material (note that if you're not using VS's Solution Explorer to do this but instead you use Windows Explorer, you also need to copy the ‘XQT.aspx.cs’ file).

Next, add a new project subdirectory called ‘xsl’, and add the file ‘xqt.xsl’. This is the XSL Stylesheet that is used to format the xquery results. Lastly, add another subdirectory called ‘xml’ and add the file ‘tut.xml’. Finally add the ‘Microsoft.Xml.XQuery.dll’ found in the download ‘bin’ directory, to your newly created directory ‘bin’.

Adding the Reference

Then, add a Reference to the project by choosing the menu "Project | Add Reference". In the .NET tab, use the Browse button, select the file named "Microsoft.Xml.XQuery.dll" which now resides in your bin directory, and click the button "Select". Finally, click OK. The reference should appear in the Solution Explorer, under the References directory. You can press [Ctrl+Alt+L] if you do not see the Solution Explorer.

Building and Running the Application

Before compiling, you'll need to choose a Start Up file before compiling and running your application. Choose "Set as Start Page" on "XQT.aspx" by right-clicking the project file in the Solution Explorer windowpane, and then finally press F5. After compiling the project, and activating the debugging environment, the following screen should turn up:

 

Fig. 4: Screenshot of XQueryTester's opening window

If you run into trouble, try re-reading the section to see if you didn't miss something. If you still do not succeed in getting the project to work, you can try to copy the whole project from the download material to your web root directory, then activate (Create) the web application using the Internet Services Manager (ISM), and run the application. Most of the time, it is sufficient to delete the .sln file, as this is the projects solution file, which contains the application path among other configuration items. In addition, the MS XQuery reference may need to be added again if the path is incorrect. VS.NET will indicate this to you also if this is the case.

OK, now you should be able to enter an XML source, and run some simple xqueries over it. The next section will guide you in doing that, and will give you a good feeling of what XQuery can do and how you can write xqueries. After having run some xqueries using some of the most important XQuery Expression types, you'll quickly get the hang of constructing your own xqueries.

After this section is completed we'll be looking more in detail at how the code behind the web form works.

The XML Source Document

The XML source file we'll use throughout this section of the tutorial is named ‘tut.xml’. Press the button “Load XML Document ‘xqt’, and it’ll show up, as shown below:

Fig. 5: XQueryTester's look when the button ‘Load XML Document “xqt”’ is pressed

The XSL Stylesheet

Note that the XSL Stylesheet used here to present the resulting XML was originally written by Jason Patterson at the SnippetCentral at TopXML.com

(http://www.topxml.com/snippetcentral/main.asp?view=viewsnippet&lang=&id=v20010305161458). All the credit of this very useful script goes to him. The script used in the XQueryTester project is an updated version he personally sent me, and is not modified by me in any way. The stylesheet can be viewed by double-clicking on the file ‘xqt.xsl’ located in the projects subdirectory ‘xsl’. IE will show up and show it gracefully, using one of its built-in stylesheets:

Fig. 6 : IE showcases the stylesheet ‘xqt.xsl’


Rate this article on a scale of 1 to 10

Your vote :  


 

Recent Jobs

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

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



reservationless conference calls
water softener
Teleconference
Host Department NOLIMIT Web Hosting
MSN
sunglasses
efax


    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