T4 to rescue and save you time

by Vahid 11. June 2010 05:56

till yesterday i had never used T4 for a real problem solving. i knew what it is but i did not know how great and easy it is.

in my current scenario i have a database table which contains options available for each property of 30 available properties of items to be added to the system. the table has almost 500 records.  in the item registration page i had to create a structure like this for each property:

<div id="div1" runat="server" class="row">
<asp:Label ID="SmartLabel13" runat="server" AssociatedControlID="" Text="Title of the property"></asp:Label>
<asp:DropDown ID="SmartDropDown1" runat="server">
<asp:ListItem Selected="True" Text="-----------" Value="">
<asp:ListItem Selected="True" Text="option 1" Value="option 1 value">
<asp:ListItem Selected="True" Text="option 2" Value="option 2 value">
.
.
.
.
<asp:ListItem Selected="True" Text="option n" Value="option n value">
</asp:ListItem>
</asp:DropDown>
</div>

creating 50 of these snippet and adding almost 12 list item for each of them along with setting the control names and property title and also AssociatedControlID of each would have taken me at least a day. i thought i could benefit from T4(Text Template Transformation Toolkit which is used for code generation) to save myself some time. so i started creating a T4 file to do this and vala… 15 minutes later i had it done. i have to say that, it was the first time that i actually was using T4. i cannot believe how easy it is to use it. the following few lines of code saved me at least a day by generating around 1000 lines of code:

<#@ template language="C#" debug="True" #>
<#@ output extension="txt" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="System.Data" #>
<#@ import namespace="System" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Diagnostics" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Collections" #>
<#@ import namespace="System.Collections.Generic" #> 
<#@ import namespace="System.Data.SqlClient" #>
<#
string catName=string.Empty;
int i=50;
System.Data.SqlClient.SqlConnection cn=new  System.Data.SqlClient.SqlConnection("data source=.\\sqlexpress;integrated security=true;database=Irizzle");
SqlCommand cmd=new SqlCommand("select * from IRZ.Lookupvalues order by Category",cn);
cn.Open();
SqlDataReader dr=cmd.ExecuteReader();
while(dr.Read())
{    
if(catName==dr["Category"].ToString())
{#>
<asp:ListItem Text="<#= dr["Name"].ToString()#>" Value="<#= dr["Code"].ToString()#>" />
<#}
else
{
if(catName!=string.Empty){#>
</Irizzle:SmartDropDown>
</div>
<#}#>
<div id="div<#= dr["Category"].ToString()#>" runat="server" class="row">
<label for="drp<#= dr["Category"].ToString()#>"><#= dr["Title"].ToString()#></label>
<Irizzle:SmartDropDown ID="drp<#= dr["Category"].ToString()#>" runat="server">
<asp:ListItem Selected="True" Text="-----------" Value=""/>
<asp:ListItem Text="<#= dr["Name"].ToString()#>" Value="<#= dr["Code"].ToString()#>" />
<#}
catName=dr["Category"].ToString();
#>        
<#    i++;}
dr.Close();
cn.Close();
#>
</Irizzle:SmartDropDown>
</div>

i am sure T4 can save you and your companies hell lot of time. what i am wondering about is why not so many people talk about this great feature.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

.Net | Technical

Have you heard about .LESS which Improves CSS

by Vahid 21. April 2010 08:57

 

If you are also involved in web development as part of your day to day job(sure most of us are), you know that dealing with css is inevitable. css is so important that everybody has to consider it; from the application architects to graphic designers.

Recently in the following blog post i read about .LESS library which was totally new but interesting for me. 

".LESS is a free, open-source port of Ruby's LESS library. LESS (and .LESS, by extension) is a parser that allows web developers to create style sheets using new and improved language features, including variables, operations, mixins, and nested rules. Behind the scenes, .LESS converts the enhanced CSS rules into standard CSS rules. This conversion can happen automatically and on-demand through the use of an HTTP Handler, or done manually as part of the build process. Moreover, .LESS can be configured to automatically minify the resulting CSS, saving bandwidth and making the end user's experience a snappier one. "  

If you want to know about .LESS for css, you can go through the same blog post which I went through:

http://www.4guysfromrolla.com/articles/030310-1.aspx

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

Technical | Tools

Waht is new in silverlight 4.0

by Vahid 21. April 2010 05:39

i have found a perfect blog post from mr. tim heuer on new features in silverlight 4.0. it's definitely worth going through his post.

http://timheuer.com/blog/archive/2009/11/18/whats-new-in-silverlight-4-complete-guide-new-features.aspx

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

.Net | Learning resource | Technical

Differences between asp.net web Site and asp.net Web Application

by Vahid 10. December 2009 06:05
Have ever wondered what the differences between 2 types of asp.net web projects in visual studio 2005 (asp.net web site project and asp.net web application project) are?Well personally I had some idea here and there about the differences but when I found the following tables from MSDN which describe the differences in an organized way, I thought of sharing them with you.Just one important thing is missing and this is:In asp.net web application project we can assign a static port number for your internal web server whereas in asp.net web site project we are restricted to use the dynamically assigned port number. Static port number assignment functionality comes handy in many situation starting from an automated testing.The following table lists Web project options or tasks and indicates which project model best implements those options.

Option or Task

Web Application Projects Web Site Projects
Need to migrate large Visual Studio .NET 2003 applications X  
Prefer single-page code model to code-behind model   X
Prefer dynamic compilation and working on pages without building entire site on each page view (that is, save file and then simply refresh the page in the browser).   X
Need to control names of output assemblies X  
Need to generate one assembly for each page   X
Need stand-alone classes to reference page and user control classes X  
Need to build a Web application using multiple Web projects X  
Need to add pre-build and post-build steps during compilation X  
Want to open and edit any directory as a Web project without creating a project file   X
The following table helps you select a project type by describing some of the key differences between Web application projects and Web site projects.

Scenario

Web Application Project Web Site Project
Project definition Similar to Visual Studio .NET 2003. Only files that are referenced in the project file are part of the project, are displayed in Solution Explorer, and are compiled during a build. Because there is a project file, some scenarios are more easily enabled: You can subdivide one ASP.NET application into multiple Visual Studio projects.You can easily exclude files from the project and from source code-control. Web site projects use the folder structure to define the contents of the project. There is no project file and all files in the folder are part of the project. This project type is desirable if you have an existing folder structure representing an ASP.NET application that you want to edit in Visual Studio without having to explicitly create a project file.
Compilation and build outputs The compilation model for Web application projects is very similar to that in Visual Studio .NET 2003. All code-behind class files and stand-alone class files in the project are compiled into a single assembly, which is placed in the Bin folder. Because this is a single assembly, you can specify attributes such as assembly name and version, as well as the location of the output assembly.Certain other applications scenarios are better enabled, such as the Model-View-Controller (MVC) pattern, because they allow stand-alone classes in the project to reference page and user control classes. The Build command compiles Web site projects only to test them. To run Web site projects, you deploy source files and rely on ASP.NET dynamic compilation to compile pages and classes in the application. Alternatively, you can precompile the site for performance, which uses the same compilation semantics as ASP.NET dynamic compilation. The ASP.NET dynamic compilation system has two modes—batch mode (the default) and fixed-names mode. In batch mode, many assemblies (typically one per folder) are produced when precompiling the site. In fixed mode, one assembly is produced for each page or user control in the Web site.
Iterative development To run and debug pages, you must build the entire Web project. Building the entire Web application project is usually fast, because Visual Studio employs an incremental build model that builds only the files that have changed. You can configure build options Visual Studio 2005 for when you run the site: build the site, an individual page, or nothing at all. In the last case, when you run a Web site, Visual Studio simply launches the browser and passes to it the current or start page. The request then invokes ASP.NET dynamic compilation. Because pages are compiled dynamically and compiled into different assemblies as needed, it is not required that the entire project compile successfully in order to run and debug a page.By default, Visual Studio completely compiles Web site projects whenever you run or debug any page. This is done to identify compile-time errors anywhere in the site. However, a complete site build can significantly slow down the iterative development process, so it is generally recommended that you change the build project option to compile only the current page on run or debug.
Deployment Because all class files are compiled into a single assembly, only that assembly needs to be deployed, along with the .aspx and .ascx files and other static content files. In this model, .aspx files are not compiled until they are run in the browser. However, when used with Web Deployment Projects (a downloadable add-in to Visual Studio 2005), the .aspx files can also be compiled and included in a single assembly for deployment.Each time you deploy the single assembly produced in this model, you replace the code for all pages in the project. Both .aspx files and code-behind files can be compiled into assemblies using the Publish Website command in Visual Studio. (Note that the Build command does not create a deployable set of assemblies.) The updateable publish option supports compiling only code-behind files while leaving .aspx files unchanged for deployment. The default mode for precompiling produces several assemblies in the Bin folder, typically one per folder. The fixed-names option produces one assembly per page or user control and can be used to create deployable versions of individual pages. However, the fixed-names option increases the number of assemblies and can result in increased memory usage.
Upgrade from Visual Studio .NET 2003 Because the Web application project model is the same as in the Visual Studio .NET 2003, upgrade is generally simple and will usually not require any restructuring of the application. The compilation option for Web site projects is significantly different than Visual Studio .NET 2003. A conversion wizard is available to upgrade existing Visual Studio .NET 2003 Web projects to Web site projects. For any reasonably complex Visual Studio .NET 2003 projects, manual fix-up is usually required after the conversion. For most scenarios, it is preferable to upgrade existing Visual Studio .NET 2003 projects to Web application projects in Visual Studio 2005.
 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

.Net | Learning resource | Technical

Maximum Capacity Specifications for SQL Serve 2008

by Vahid 1. December 2009 09:18

 it has been always a question for me that  what the maximum number of table in a sql server database is. searching for an answer to this question, i came across the following table in msdn. i found it very usefull and thought of sharing it with you.

SQL Server Database Engine object

Maximum sizes/numbers SQL Server (32-bit) Maximum sizes/numbers SQL Server (64-bit)
Batch size1 65,536 * Network Packet Size 65,536 * Network Packet Size
Bytes per short string column 8,000 8,000
Bytes per GROUP BY, ORDER BY 8,060 8,060
Bytes per index key2 900 900
Bytes per foreign key 900 900
Bytes per primary key 900 900
Bytes per row8 8,060 8,060
Bytes in source text of a stored procedure Lesser of batch size or 250 MB Lesser of batch size or 250 MB
Bytes per varchar(max), varbinary(max), xml, text, or image column 2^31-1 2^31-1
Characters per ntext or nvarchar(max) column 2^30-1 2^30-1
Clustered indexes per table 1 1
Columns in GROUP BY, ORDER BY Limited only by number of bytes Limited only by number of bytes
Columns or expressions in a GROUP BY WITH CUBE or WITH ROLLUP statement 10 10
Columns per index key7 16 16
Columns per foreign key 16 16
Columns per primary key 16 16
Columns per nonwide table 1,024 1,024
Columns per wide table 30,000 30,000
Columns per SELECT statement 4,096 4,096
Columns per INSERT statement 4096 4096
Connections per client Maximum value of configured connections Maximum value of configured connections
Database size 524,272 terabytes 524,272 terabytes
Databases per instance of SQL Server 32,767 32,767
Filegroups per database 32,767 32,767
Files per database 32,767 32,767
File size (data) 16 terabytes 16 terabytes
File size (log) 2 terabytes 2 terabytes
Foreign key table references per table4 253 253
Identifier length (in characters) 128 128
Instances per computer 50 instances on a stand-alone server for all SQL Server editions except for Workgroup. Workgroup supports a maximum of 16 instances per computer.SQL Server supports 25 instances on a failover cluster. 50 instances on a stand-alone server.25 instances on a failover cluster.
Length of a string containing SQL statements (batch size)1 65,536 * Network packet size 65,536 * Network packet size
Locks per connection Maximum locks per server Maximum locks per server
Locks per instance of SQL Server5 Up to 2,147,483,647 Limited only by memory
Nested stored procedure levels6 32 32
Nested subqueries 32 32
Nested trigger levels 32 32
Nonclustered indexes per table 999 999
Number of distinct expressions in the GROUP BY clause when any of the following are present: CUBE, ROLLUP, GROUPING SETS, WITH CUBE, WITH ROLLUP 32 32
Number of grouping sets generated by operators in the GROUP BY clause 4,096 4,096
Parameters per stored procedure 2,100 2,100
Parameters per user-defined function 2,100 2,100
REFERENCES per table 253 253
Rows per table Limited by available storage Limited by available storage
Tables per database3 Limited by number of objects in a database Limited by number of objects in a database
Partitions per partitioned table or index 1,000 1,000
Statistics on non-indexed columns 30,000 30,000
Tables per SELECT statement Limited only by available resources Limited only by available resources
Triggers per table3 Limited by number of objects in a database Limited by number of objects in a database
Columns per UPDATE statement (Wide Tables) 4096 4096
User connections 32,767 32,767
XML indexes 249 249

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Learning resource | SQL | Technical

Export to PDF, Excel and Image in asp.net

by Vahid 18. July 2009 19:48

recently in our project we had a requirement to export html to PDF in asp.net. there are so many components around which we can use to do this but the restriction for us was that we had to do it without spending money means we had to go for an open source component. doing so much I&D on this, we came to know about itextSharp which is a powerful open source component to create PDF files in .net. first it seemed good to us but spending sometimes on it we came to know it was not what we were looking for. two reason for that:

  1. it requires a big learning curve
  2. it’s not at all easy to work with

then the idea of using crystal report came to our mind. we could build the report in crystal report, load it through code without showing anything to user and through it’s API calling the export to pdf function. but it did not work since we had to run some setup components on the live server which we are not allowed to do.

meantime i just remembered we have rdlc reports in .net framework and also Microsoft report viewer. since these are .net component we don't have to install anything on the production server and Xcopy of the required assemblies will work for us. normally you can deploy the .net report files (.rdlc) using xcopy but in order to be able to use the reports you need to install Microsoft report viewer redistributable package which is freely available to download and distribute. this is fine when you have the rights to install components on the server. anyways spending sometime on this technology i found the files required to make the functionality up and running. if you don't want to install report viewer component you need to put these four dll in your bin folder:

Microsoft.ReportViewer.Common.dll
Microsoft.ReportViewer.ProcessingObjectModel.dll
Microsoft.ReportViewer.WebForms.dll
Microsoft.ReportViewer.WinForms.dll


you can download the files from here:
http://cid-c1dc0bf06aa2e3a6.skydrive.live.com/self.aspx/BlogFiles/ReportViewerFiles.zip

you need to create a report file by click on add new item in your project and selecting Report. then you need to design your report in visual studio as desired. you can use report parameters as placeholder for the values to be passed to to report.

then you need the following lines of code to export:

string[] streamids;
string mimeType;
string encoding;
string extension;
string fileFormat = "PDF";//can also be "Excel" or "Image";
Microsoft.Reporting.WebForms.LocalReport localReport = 
new Microsoft.Reporting.WebForms.LocalReport();
localReport.ReportPath = Server.MapPath("Report1.rdlc");
Microsoft.Reporting.WebForms.Warning[] warnings;
byte[] bytes = localReport.Render(
fileFormat, null, out mimeType, out encoding,
out extension,
out streamids, out warnings);
System.IO.FileStream fs = 
new System.IO.FileStream(Server.MapPath("output.pdf"),
System.IO.FileMode.Create);
fs.Write(bytes, 0, bytes.Length);
fs.Close();
Response.Redirect("output.pdf");

remember you can export to PDF, Excel and Image

you can use this method both for asp.net applications and windows application.

hope this comes handy for you.

Currently rated 4.8 by 6 people

  • Currently 4.833333/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

.Net | Technical

Oracle Connection String Without tnsnames.ora file for .net

by Vahid 12. July 2009 04:51

ever wanted to connect to an oracle database in your .net application (asp.net, windows client ect) but tnsnames.ora file was missing? ok,i just found a solution for this in connectionstrings.com. you can use the following connection strings to connect to an oracle database using both microsoft .net provider for oracle database and odp.net:

.NET Data Provider for Oracle

SERVER=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=yourHost)(PORT=yourPort))(CONNECT_DATA=(SERVICE_NAME=yourOracleSID)));uid=yourUsername;pwd=yourPassword;

Oracle Data Provider for .NET / ODP.NET

Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=MyHost)(PORT=MyPort)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=MyOracleSID)));User Id=myUsername;Password=myPassword;

Currently rated 1.4 by 7 people

  • Currently 1.428571/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

.Net | Technical

Managing Multiple Configuration File For Different Application Life cycles In .Net Applications

by Vahid 25. May 2009 16:50

All of us have already dealt with the problem of promoting configuration files in different application life cycles. this problem can be as simple as managing different connection strings for different databases in each environment to managing the other complicated settings in each environment.

so many times it happens that we forget to update the configuration file (web.config or app.config) before promotes. what we had already done was to keep one configuration file for each environment (development, testing, staging …) and after promote before build overwrite the the existing configuration file. but even in this case we used to miss to update the configuration file with the latest information. anyway i came across the very good solution in Scott Hanselman's blog. ok here is the solution.

  1. In your project Click the configuration management dropdown and select "Configuration Manager."image

You'll probably have Debug and Release configurations, but you can also make custom ones and base them on existing configuration. In this dialog I've made a new "Deploy" and I'll base it on the "Release" configuration.

WindowClipping (8)

Make sure to create a Solution Configuration AND a Project Configuration, as they are different. Here I've made one called Deploy for the Project also. If you get an error message, be aware of the "Create new project configurations" checkbox. You might get a warning if you are making a new configuration and the dialog tries to make another configuration with the same name; uncheck the checkbox if that happens. Of course, you can have as many Configurations as you'd like.

deploy

2. Add some custom configuration stuff in web.config, like connectionStrings:

	   1: <connectionStrings>
	
	   2:     <add name="Foo"
	
	   3:          connectionString="Data Source=localhost;Initial Catalog=DatabaseName;
	
	   4:                            User Id=sa;Password=debug;"
	
	   5:          providerName="System.Data.SqlClient" />
	
	   6: </connectionStrings>
	

See now I've made the password in my nonsense connectionString = "debug"? Now, create three new web.config's by CTRL-dragging the web.config on top of the project. Name them web.config.debug, web.config.deploy, and web.config.release. Make the password equal to "deploy" and "release" respectively.

WindowClipping (10)

3. Ok,  now we've got different configuration and different configuration files. Let's create a batch file called "copyifnewer.bat" and here's the contents:

	   1: @echo off
	
	   2: echo Comparing two files: %1 with %2
	
	   3:  
	
	   4: if not exist %1 goto File1NotFound
	
	   5: if not exist %2 goto File2NotFound
	
	   6:  
	
	   7: fc %1 %2 
	
	   8: if %ERRORLEVEL%==0 GOTO NoCopy
	
	   9:  
	
	  10: echo Files are not the same.  Copying %1 over %2
	
	  11: copy %1 %2 /y & goto END
	
	  12:  
	
	  13: :NoCopy
	
	  14: echo Files are the same.  Did nothing
	
	  15: goto END
	
	  16:  
	
	  17: :File1NotFound
	
	  18: echo %1 not found.
	
	  19: goto END
	
	  20:  
	
	  21: :File2NotFound
	
	  22: copy %1 %2 /y
	
	  23: goto END
	
	  24:  
	
	  25: :END
	
	  26: echo Done.
	

Basically this batch file will copy a file over another if the files don't match. It's not strictly "copyifnewer" (like, not at all) but it does the job.

Why bother with a batch file to check for changes and not just copy over the file every time? Well, each time you copy over a web.config it restarts all the designers and running AppDomains that are watching that file. No need to copy over a file if it hasn't changed...everything will churn less.

Put this copyifnewer.bat file in the root of your project.

WindowClipping (10)

4. Create a Pre-build Event. Right-click on your Project and select Properties. Click Build Events and in the "Pre-build event command line" and enter this value:

	"$(ProjectDir)copyifnewer.bat" "$(ProjectDir)web.config.$(ConfigurationName)" "$(ProjectDir)web.config"
	

Notice the magic dust, the $(ConfigurationName) project variable, that contains "Debug" or "Release" or "Deploy."

WindowClipping (9)

5. Build. Now if you build, you'll see in the Build Output the batch file being run and the files being copied. Because it's a Pre-Build Event it'll be seen in both the Build Output in Visual Studio .NET.

When you build within Visual Studio the currently selected item in the drop-down list is the current configuration.  now you have different configuration file for each build

there is catch here and that is we have to remember that we've got to keep web.config's in sync if there's lots of settings, but we could totally break it apart via "include files."

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

.Net | Technical

Differences between XML and JSON

by Vahid 24. May 2009 05:29

Here are some key differences between JavaScript Object Notation (or JSON), an open and text-based data exchange format, that provides a standardized data exchange format better suited for Ajax-style web applications and XML.

Although Both JSON and XML can be used to represent native, in-memory objects in a text-based, human-readable, data exchange format, but the two data exchange formats are isomorphic—given text in one format, an equivalent one is conceivable in the other.

following tables is a high level comparision between JSON and XML.

Key Characteristic Differences between XML and JSON

CharacteristicXMLJSON
Data types Does not provide any notion of data types. One must rely on XML Schema for adding type information. Provides scalar data types and the ability to express structured data through arrays and objects.
Support for arrays Arrays have to be expressed by conventions, for example through the use of an outer placeholder element that models the arrays contents as inner elements. Typically, the outer element uses the plural form of the name used for inner elements. Native array support.
Support for objects Objects have to be expressed by conventions, often through a mixed use of attributes and elements. Native object support.
Null support Requires use of xsi:nil on elements in an XML instance document plus an import of the corresponding namespace. Natively recognizes the null value.
Comments Native support and usually available through APIs. Not supported.
Namespaces Supports namespaces, which eliminates the risk of name collisions when combining documents. Namespaces also allow existing XML-based standards to be safely extended. No concept of namespaces. Naming collisions are usually avoided by nesting objects or using a prefix in an object member name (the former is preferred in practice).
Formatting decisions Complex. Requires a greater effort to decide how to map application types to XML elements and attributes. Can create heated debates whether an element-centric or attribute-centric approach is better. Simple. Provides a much more direct mapping for application data. The only exception may be the absence of date/time literal.
Size Documents tend to be lengthy in size, especially when an element-centric approach to formatting is used. Syntax is very terse and yields formatted text where most of the space is consumed (rightly so) by the represented data.
Parsing in JavaScript Requires an XML DOM implementation and additional application code to map text back into JavaScript objects. No additional application code required to parse text; can use JavaScript's eval function.
Learning curve Generally tends to require use of several technologies in concert: XPath, XML Schema, XSLT, XML Namespaces, the DOM, and so on. Very simple technology stack that is already familiar to developers with a background in JavaScript or other dynamic programming languages.

JSON is a relatively new data exchange format and does not have the years of adoption or vendor support that XML enjoys today (although JSON is catching up quickly). The following table highlights the current state of affairs in the XML and JSON spaces.

Support Differences between XML and JSON

SupportXMLJSON
Tools Enjoys a mature set of tools widely available from many industry vendors. Rich tool support—such as editors and formatters—is scarce.
Microsoft .NET Framework Very good and mature support since version 1.0 of the .NET Framework. XML support is available as part of the Base Class Library (BCL). For unmanaged environments, there is MSXML. None so far, except an initial implementation as part of ASP.NET AJAX.
Platform and language Parsers and formatters are widely available on many platforms and languages (commercial and open source implementations). Parsers and formatters are available already on many platforms and in many languages. Consult json.org for a good set of references. Most implementations for now tend to be open source projects.
Integrated language Industry vendors are currently experimenting with support literally within languages. See Microsoft's LINQ project for more information. Is natively supported in JavaScript/ECMAScript only.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

Learning resource | Technical

XPath expressions quick reference:

by Vahid 7. May 2009 07:00

  if you work with XML and xpath for sure the reference seems to be a trivial one for you. but if you stop working with xml and xpath for a while you’ll find the reference pretty handy. i personally keep it with me always. hope it also helps you.

the reference xpath expression is for this xml content:

   1: <?xml version="1.0" encoding="utf-8" ?>
   2: <Albums>
   3:   <Album country="USA">
   4:     <title>Empire Burlesque</title>
   5:     <artist>Bob Dylan</artist>
   6:     <price>10.90</price>
   7:   </Album>
   8:   <Album country="UK">
   9:     <title>Hide your heart</title>
  10:     <artist>Bonnie Tyler</artist>
  11:     <price>10.0</price>
  12:   </Album>
  13:   <Album country="USA">
  14:     <title>Greatest Hits</title>
  15:     <artist>Dolly Parton</artist>
  16:     <price>9.90</price>
  17:   </Album>
  18: </Albums>

and here is the quick reference

/Albums

selects the root element

/Albums/Album

selects all the Album elements of the Albums element

/Albums/Album/price

selects all the price elements of all the Album elements of the Albums element

/Albums/Album[price>10.0]

selects all the Album elements with price greater than 10.0

starts with a slash(/)

represents an absolute path to an element

starts with two slashes(//)

selects all elements that satisfy the criteria

//Album

selects all Album elements in the document

/Albums/Album/title | /Albums/Album/artist

selects all the title and artist elements of the Album elements of Albums

//title | //artist

selects all the title and artist elements in the document

/Albums/Album/*

selects all the child elements of all Album elements of the Albums element

/Albums/*/price

selects all the price elements that are grandchildren of Albums

/*/*/price

selects all price elements which have two ancestors

//*

selects all elements in the document

/Albums/Album[1]

selects the first Album child of Albums

/Albums/Album[last()]

selects the last Album child of Albums

/Albums/Album[price]

selects all the Album elements that have price

/Albums/Album[price=10.90]

selects Album elements with the price of 10.90

/Albums/Album[price=10.90]/price

selects all price elements with the price of 10.90

//@country

selects all "country" attributes

//Album[@country]

selects Album elements which have a "country" attribute

//Album[@*]

selects Album elements which have any attribute

//Album[@country='UK']

selects Album elements with "country" attribute equal to 'UK'

 

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

Technical

Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen