Showing posts with label XML. Show all posts
Showing posts with label XML. Show all posts

Wednesday, January 19, 2011

Sitemaps in XML Format and Submission

A sitemap is a way of organizing a website, identifying the URLs and the data under each section. Its intended use is to allow search engines to track URLs more efficiently.

urlset tag - Encloses the file and references the current protocol standard.

loc tag - Contains the URL of a file.

proiority tag - List the priority of this URL compared to the other URLs on your site.


Sample Sitemap - click on code to make larger





As you can see from the XML above, the parent tag goes first followed by the child tags.




Escape Codes must be used for the characters below.




Submitting a Sitemap

Google


  1. www.google.com/webmasters/sitemaps

  2. To submit a sitemap to Google, to must first create a Google email account if you have not already done so.

  3. Click the “Add a site…” button and add your url.

  4. You will be asked to verify your site by either downloading a file and putting it in your wwwroot directory or by modifying your site index page by inserting a meta tag.

  5. Once your site is verified by Google, click on the “Site configuration” link.

  6. Click the Sitemaps link.

  7. Click the “Submit a Sitemap” button, entered the name of the site map at your root directory and click the “Submit Sitemap” button.

  8. Your status will show a clock for “pending”. The next day it will show a check mark for “ok”.


This does not mean that Google has indexed your site yet, just that your sitemap has been submitted and accepted.

Bing

  1. Bing does not accept sitemaps. They expect their web crawler to find your site.



Ask

  1. Ask does not have a sitemap submission form. To let Ask to know about your sitemap, you must use their ping service.

  2. Type in http://submissions.ask.com/ping?sitemap=http://www.NameOfSite.com/NameOfSitemap.xml in your browser.



Yahoo

  1. Yahoo works much the same way that Google does. Go to https://siteexplorer.search.yahoo.com/submit/

  2. Enter your url (ex: www.wardlawclaims.com) and click the “Submit URL” button.

  3. You will be asked to create a yahoo email account if you don’t already have one.

  4. Click on the “Submit a Website or Webpage” link.

  5. As with Google you will be asked to download a file to your wwwroot directory or insert a meta tag to your index page.

  6. Once your website has been verified. Click the “Feeds” link, type the name
    of you xml sitemap file and click the “Add Feed” button.

  7. Your status will show pending until it has been submitted to Microsoft then a check mark will be (usually the next day) display when it has been processed.



Again this does not mean that Yahoo has indexed your site, just that your sitemap has been submitted and accepted.

Wednesday, September 29, 2010

Introduction to Formatting Query Results as XML in Microsoft SQL Server 2008

We can use the FOR XML clause with SELECT statements in Microsoft SQL Server to produce XML output from our queries.  We might use this feature when creating output that will be consumed by an application that understands XML.  This post will demonstrate using this feature to create XML output of a contact list.


Here is the T-SQL used to create and populate our Contacts table:

CREATE TABLE Contacts
(
ContactId INT NOT NULL IDENTITY(1,1) PRIMARY KEY,
FirstName VARCHAR(30) NOT NULL,
LastName VARCHAR(30) NOT NULL,
PhoneNumber VARCHAR(20) NOT NULL,
EmailAddress VARCHAR(50) NOT NULL
);

INSERT INTO Contacts ( FirstName, LastName, PhoneNumber, EmailAddress )
VALUES ( 'Smith', 'Jon', '254-555-1234', 'jon@example.com' );


INSERT INTO Contacts ( FirstName, LastName, PhoneNumber, EmailAddress )
VALUES ( 'Rogers', 'Amanda', '254-555-4321', 'amanda@example.com' );


INSERT INTO Contacts ( FirstName, LastName, PhoneNumber, EmailAddress )
VALUES ( 'Gomez', 'Paul', '254-555-5252', 'paul@example.com' );


INSERT INTO Contacts ( FirstName, LastName, PhoneNumber, EmailAddress )
VALUES ( 'Peterson', 'James', '254-555-9876 ext 234', 'james@example.com' );

Let us assume that we have a contact management application that we wish to export this data to and that this fictitious application can import XML that is formatted like the sample below.


<?xml version="1.0"?>
<Contact-List>
<Contact>
<First-Name>John</First-Name>
<Last-Name>Doe</Last-Name>
<Telephone>800-555-1111</Telephone>
<E-mail>doe.john@example.com</E-mail>
</Contact>
<Contact>
<First-Name>Tommy</First-Name>
<Last-Name>Atkins</Last-Name>
<Telephone>800-555-2222</Telephone>
<E-mail>atkins.tommy@example.com</E-mail>
</Contact>
</Contact-List>


As you can see in addition to formatting the output as XML we will also need to map our table's columns to the XML format's elements: "FirstName" in the table will be "First-Name" in the XML.   We can use the FOR XML clause in our SELECT statement to shape the query's result to match the required format.  Below is the T-SQL used to create the XML.


SELECT 
FirstName AS 'First-Name',
LastName AS 'Last-Name',
PhoneNumber AS Telephone,
EmailAddress AS 'E-mail'
FROM Contacts
ORDER BY LastName, FirstName
FOR XML PATH('Contact'), ROOT('Contact-List');

Here is the result of that query.

<Contact-List>
  <Contact>
    <First-Name>Rogers</First-Name>
    <Last-Name>Amanda</Last-Name>
    <Telephone>254-555-4321</Telephone>
    <E-mail>amanda@example.com</E-mail>
  </Contact>
  <Contact>
    <First-Name>Peterson</First-Name>
    <Last-Name>James</Last-Name>
    <Telephone>254-555-9876 ext 234</Telephone>
    <E-mail>james@example.com</E-mail>
  </Contact>
  <Contact>
    <First-Name>Smith</First-Name>
    <Last-Name>Jon</Last-Name>
    <Telephone>254-555-1234</Telephone>
    <E-mail>jon@example.com</E-mail>
  </Contact>
  <Contact>
    <First-Name>Gomez</First-Name>
    <Last-Name>Paul</Last-Name>
    <Telephone>254-555-5252</Telephone>
    <E-mail>paul@example.com</E-mail>
  </Contact>
</Contact-List>

The FOR XML clause instructs the server to transform the results to XML.  The PATH parameter specifies that each record should be wrapped in an element named "Contact".  The ROOT parameter specifies that the result set should be wrapped in an element names "Contact-List".  Note that since the elements contain dashes and dashes are not permitted in column names an alias is needed in our query to name the elements to match the XML elements.   Note that element names in query such as 'First-Name' can be escaped by single quotes, square brackets, or double quotes.  All of the following are equivlement: 'First-Name', "First-Name", [First-Name].

The FOR XML has additional parameters that can be used to control the format of the output.  This post is intended as a basic introduction.

References

"Basic Syntax of the FOR XML Clause" from SQL Server Books Online