Sales and Marketing TechnologiesFor Orlando web design services Call 407.682.2222
Search
Do you want Breakthrough Results? Let us help you.Click to boost online marketing results
Click to boost online marketing results! Click to sign up for our FREE e-Newsletter
Web Development Custom Web Development E-commerce Solutions Web Consulting Web Maintenance Web Hosting CMS Solutions
Internet Marketing Internet Marketing Consulting Local Search Marketing Pay Per Click Management Reputation Management SEO Services Social Networking Video SEO (VSEO)
Case Studies Miami Children's Hospital Reflectx Services Dinnerware Depot Aschacher Family Dentistry
About SMT Altamonte Springs Office
Internet Marketing Blog Contact Us Refer a Client Employment
Blog

Parsing data in C#

4/16/2009
Bookmark and Share
Parsing data in C# is a simple process, and can be done using some basic language syntax. Sub Strings provide this functionality, and when used properly can make data collection, or simple parsing operations a much easier task.

First when parsing data from sources such as a web page, it is important to first remove all data at the beginning of the document which is unnecessary, in order to prevent the parsing utility from finding the wrong information.

<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
   <title>website design search results</title>
   <link>http://randomexamplesiteurl.com/</link>
   <language>en</language>
   <pubDate>Wed, 15 Apr 2009 18:31:33 GMT</pubDate>
   <lastBuildDate>Wed, 15 Apr 2009 18:31:33 GMT</lastBuildDate>
   <image>
      <title>website design - sample feed</title>
      <url>http://randomexamplesiteurl.com/testimage1.gif</url>
      <link>http://randomexamplesiteurl.com/</link>
   </image>
   <item>
      <title>Small Businesses Receive Web Design Financing from Wildfire</title>
      <link>http://randomexamplesiteurl.com/testlink1.html</link>
      <pubDate>Wed, 15 Apr 2009 07:15:30 GMT</pubDate>
      <description>This is a sample description I am using for testing purposes</description>
   </item>
   <item>
      <title>Effective website design for successful ecommerce</title>
      <link>http://randomexamplesiteurl.com/testlink2.html</link>
      <pubDate>Wed, 15 Apr 2009 11:23:38 GMT</pubDate>
      <description>This is a sample description I am using for testing purposes</description>
   </item>
   <description>website design - XML Sample</description>
</channel>
</rss>

Finding unique tags to mark the beginning of the data to be parsed is the key to building an efficient parsing utility. In the above sample, all of the text prior to "" is irrelevant if you are only attempting to gather the item data, and will not be needed to complete the parsing process. To remove this from your text use the following code: (code assumes data is loaded in a string variable named strData)

int intStartPos = strData.IndexOf("<item>");
strWorkingRSS = strData.Substring(intStartPos);

Once the irrelevant data has been removed, you can then focus on parsing the remainder of the string, with the following code this can be done by using any unique string at the beginning and the end of the data you would like to capture. The following code will always stop at the first instance of search string so if you continue to trim the text as you work using the above sample, you can easily write a loop to pull out each of the items until the data has all been parsed successfully. The below sample will result in assigning the variable strTitle with the text in between the "<title>" and "</title>" tags.

string strOpenString = "<title>";
intStartPos = strData.IndexOf(strOpenString ) + strOpenString .Length;
int intEndPos = strData.IndexOf("</title>");
int intLength = intEndPos - intStartPos;
string strTitle = strData.Substring(intStartPos, intLength);

This should be enough information to get any parsing project started. The data that I used for my sample may have been XML, but the real value in this type of parsing utility, is in cases where data from an HTML site, or group of HTML pages needs to be moved to a dynamic location such as a database. Many times the only viable option for data transfer is to use a "screen scraping" application, and this code provides a general outline for how to build one for most any circumstances.
Levi 4/16/2009

Add your comments:

Items in bold indicate required information.

Name :
 
Email :
 
Comments :
 
 
Latest Posts

Categories
Blogging (2)
Google (3)
Local (2)
Website Design (4)
Website Functionality (5)
Internet Marketing (90)
Company News (6)
Email Marketing (7)
General Marketing (11)
Google Android (2)
Local Search (12)
Mobile Search (2)
Offline Marketing (2)
PPC (13)
RSS (5)
Search Engine Optimization (36)
Social Media (9)
Social Networking (18)
General Programming (2)
SQL Programming (2)
Video Search Engine Optimization (3)

Archives

Blogroll
Melbourne Web Design
Orlando Search Marketing
Lakeland Web Design
ASP.NET CMS

Feeds



Newsletter Signup
Enter your email address below and receive special offers.
From Our Customers
"Since SMT was hired to bring our website up to standards, it has garnered continuous growth in its, page views and has consistently been recognized in the eHealthcare awards. We are very pleased with SMT’s work and customer service. We would gladly recommend them to others."

Marcia Diaz de Villegas – Miami Children’s Hospital Director of Marketing & Public Relations
Our Work    |    Web Development    |    Internet Marketing    |    Case Studies    |    FAQ    |    About SMT    |    Press Room
Employment    |    Refer a Client    |    Contact Us    |    Internet Marketing Blog    |    Privacy Policy    |    Site Map

Sales & Marketing Technologies
Altamonte Springs: 220 E. Central Parkway, Suite 1010 • Altamonte Springs, FL 32701407-682-2222

© 2011, Sales & Marketing Technologies, Ltd. All rights reserved.
Website Design FL & Search Engine Optimization Services