Archive for category XML

Copying XML data from a SQL query

We have an older system which stores XML as a varchar in the database. Copying & pasting from this often truncates the content, and if it doesn;t you then have to paste it into visual studio or something to get the correct formatting etc etc…. it’s a pain.

A quick way round this- if you’re using SQL server 2005 or above- is to cast the output as xml- this makes the xml like a clickable hyperlink in the results panel, and clicking it opens up the full unabridged version of the xml, nicly formatted and indented as god intended.

      ,cast(replace(request,'encoding="UTF-8"','encoding="UTF-16"') as xml)
      ,cast(replace(response,'encoding="UTF-8"','encoding="UTF-16"') as xml)
  FROM [MyXMLDataLogTable]
  order by id desc

Thanks go once more to my good colleague Andrew Carmichael for this top tip.

1 Comment

Paged List of Child Nodes in Umbraco

We just started looking at Umbraco- and so I’m delving into Macro’s – these are the packaged up chunks of functionality which make your site actually do things and either take the form of XSLT files which process and spit out the contents of your database, or dot net controls.

I found an excellent example XSLT that allows you to create a paginated list of child nodes over on Tim Geyssens “nibble” blog, and I’ve modified it ever so slightly to stop the numerical index rendering if the pagecount is less than 2- so thought I would re-post it!

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [
  <!ENTITY nbsp "&amp;amp;amp;#x00A0;">
exclude-result-prefixes="msxml umbraco.library">

  <xsl:output method="xml" omit-xml-declaration="yes"/>
  <xsl:param name="currentPage"/>
  <xsl:template match="/">

    <xsl:variable name="recordsPerPage" select="/macro/recordsPerPage"/>
    <xsl:variable name="pageNumber" >
        <!-- first page -->
        <xsl:when test="umbraco.library:RequestQueryString('page') <= 0 or string(umbraco.library:RequestQueryString('page')) = '' or string(umbraco.library:RequestQueryString('page')) = 'NaN'">0</xsl:when>
        <!-- what was passed in -->
          <xsl:value-of select="umbraco.library:RequestQueryString('page')"/>

    </xsl:variable> &amp;amp;amp;nbsp;

    <xsl:variable name="numberOfRecords" select="count($currentPage/node)"/>

    <!-- The fun starts here -->
      <xsl:for-each select="$currentPage/node [string(data [@alias='umbracoNaviHide']) != '1']">
        <xsl:if test="position() > $recordsPerPage * number($pageNumber) and
position() <= number($recordsPerPage * number($pageNumber) +
$recordsPerPage )">
            <a href="{umbraco.library:NiceUrl(@id)}">
              <xsl:value-of select="@nodeName"/>


    <xsl:if test="$pageNumber > 0">
      <a href="?page={$pageNumber -1}">previous </a>

<xsl:if test="($numberOfRecords > $recordsPerPage)">
    <xsl:call-template name="for.loop">
      <xsl:with-param name="i">1</xsl:with-param>
      <xsl:with-param name="page" select="$pageNumber +1"></xsl:with-param>
      <xsl:with-param name="count" select="ceiling(count($currentPage/node)div $recordsPerPage)"></xsl:with-param>

    <xsl:if test="(($pageNumber +1 ) * $recordsPerPage) < ($numberOfRecords)">
      <a href="?page={$pageNumber +1}">next</a>

  <xsl:template name="for.loop">

    <xsl:param name="i"/>
    <xsl:param name="count"/>
    <xsl:param name="page"/>
    <xsl:if test="$i <= $count - 1">

      <xsl:if test="$page != $i">
        <a href="{umbraco.library:NiceUrl($currentPage/@id)}?page={$i - 1}" >

          <xsl:value-of select="$i" />

      <xsl:if test="$page = $i">

        <xsl:value-of select="$i" />

    <xsl:if test="$i <= $count - 1">
      <xsl:call-template name="for.loop">
        <xsl:with-param name="i">
          <xsl:value-of select="$i + 1"/>
        <xsl:with-param name="count">
          <xsl:value-of select="$count"/>
        <xsl:with-param name="page">
          <xsl:value-of select="$page"/>


Syndicating to RSS using the built in .net SyndicationFeed classes

My boss recently showed me a pretty handy bunch of classes for generating RSS and ATOM feeds, all built into dot net.

Start by adding a new reference to your project; System.Services.Web.

The SyndicationFeed class holds all the data about your feed and lets you spit everything out in a number of different formats (RSS2.0, ATOM1.0)- each item in the feed is held in a generic list of SyndicationItem objects. As I work for a publishers, I was creating an RSS feed of coming soon books so I added an extension method to my book class- ToSyndicationItem();

public static SyndicationItem ToSyndicationItem(this Book book)
    return new SyndicationItem(book.CoverTitle + " " + book.Subtitle, book.Description, new Uri(book.GetURL()))
        Summary = new TextSyndicationContent(book.DescriptionShort, TextSyndicationContentKind.Plaintext),
        Id = book.Id.ToString(),
        LastUpdatedTime = book.InsertedDate

This allows me to use all the standard select methods I already in my book class, to also populate my RSS feed. So to create the feed all I need do in my RSS.ashx handler file is;

List<Book> books = Book.GetBookPublishedBetween(DateTime.Now,DateTime.Now.AddDays( int.Parse( GroupConstants.ComingSoonMaxDays)));
List<SyndicationItem> syndicationItems = new List<SyndicationItem>();
foreach (Book book in books)

feed = new SyndicationFeed(syndicationItems)
    Title = new TextSyndicationContent("Coming Soon Titles"),
    Description = new TextSyndicationContent("Forthcoming publications."),
    BaseUri = new Uri(LinkHelper.GetBaseUrl())

var output = new StringWriter();
var writer = new XmlTextWriter(output);

new Rss20FeedFormatter(feed).WriteTo(writer);

context.Response.ContentType = "application/rss+xml";

, , ,

1 Comment


Simple piece of XSL to format an RSS Feed;

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="">
 <xsl:output method="html"></xsl:output>
    <xsl:template match="rss/channel/item">
      <a href="{link}" title="{title}">
        <xsl:value-of select="title" />
        <xsl:value-of select="description" />

No Comments

Consuming RSS Feeds using controls

Real simple example, using an XmlDataSource and my new super best friend, the ListView control;

    <asp:ListView ID="RSSList" runat="server" DataSourceID="RSSData">
                <li id="itemPlaceholder" runat="server" />
                <%#XPath("title") %>
            <%#XPath("author") %>
            <a href='<%#XPath("link") %>' title=''>View Original Post</a>

No Comments

Visually build XPath using “Sketch Path”

Paul found an awesome tool fopr visually parsing XML files and building XPath statements, called Sketch Path available for download here

No Comments

Quick XML serialisation of an object..

Quick code snippet for taking a serialisable object, serialising to XMl then spitting out a string for you to write out to a debug log or something- i used this for spitting back the responses I was getting from a web service call i was making

            StringBuilder sb_xml = new StringBuilder();
            XmlSerializer s = new XmlSerializer( typeof( Hachette.Checkout.Vista.Stock.ProductStockLiteResultResponse ) );
            StringWriter w = new StringWriter(sb_xml);
            s.Serialize(w, ws_response);
            Response.Write("<!-- Response = " + sb_xml + " -->");

No Comments

I absolutely love these. They came at the lace wigs are good quality, and very soft. Absolutely love these extensions. I just love this hair. Hair came on time, I waited until after hair extensions uk very full, no shedding and it is been installed for 3 weeks now and yes I jus ordered 3 more bundles. Lol. I definitely recommend this company for your bundles ladies. They are soft, hair bundles on the head for human hair wigs and I would continue to recommend them. I have thinner hair so they cover and blend nicely.