How To Add Or Change XML Encoding With .NET

Last time I wrote about comparing XML strings in .NET, and continuing that theme I’d like to discuss another handy XML trick.  As the last article pointed out, not all XML strings are created equal.  In fact, sometimes they are missing the necessary XML version and encoding information, like in the following sample XML:

    <SampleField2 value="test value" />
    <SampleField3 type="int">456</SampleField3>

Notice anything missing?   Yes, the declaration information is not at the start of the XML string.  Declaration information like in the below example:

<?xml version="1.0" encoding="utf-8"?>

Continue reading

How to Compare XML Strings Using .NET

So you want to compare two XML strings together to see if they are equal. Obviously, it would be easy to just compare the two strings using a regular string equality comparison and call it a day. However, what if the XML strings looked like the following:

    <SampleField2 value="test value" />
    <SampleField3 type="int">456</SampleField3>
    <SampleField2     value="test value" />
        <SampleField3 type="int">456</SampleField3></SampleXML>

All of the nodes, attributes and values are the same, but the formatting is way off. Obviously, a string equality comparison between these two would return false. Is there anything that can be done about this? Not to fear, .NET provides a pretty simple solution. Continue reading

Pulling the value from a tag in an XML data type using T-SQL

If you need to extract the data from an XML data type column to be used as part of query, and you need it to be a usable data type in MS-SQL, you can use the Value() method.  Using the Value method, we can extract the data contained within an XML tag as a SQL Data Type. The Value() method takes two arguments:

XQuery and SQLType

The following returns the value stored in the second <SSID> tag as a VarChar(50):

— First we create an XML variable to store the data that we’ll use for this example
DECLARE @x xml
SET @x =      ‘<NETWORKS>
<SSID> Wompsters University </SSID>
<SSID> Wompsters Inc </SSID>

— Select the second SSID value and specify that we’d like to return it as a VarChar(50), (Keep in mind the <SSID> position starts at 1, not 0)
SELECT @x.value(‘(//NETWORKS/SSID)[2]’, ‘varchar(50)’);

— This will return the VarChar “Wompsters Inc”, which you could use like a normal String in any SQL query

Benn McGuire
QA Test Engineer
ImageSource, Inc.

Serialization and Deserialization

Serialization is a process of converting an object into a stream of data, to easily transfer over the network or to save to disk.   So, using this concept of serialization, we can serialize any object to XML string.
Here is a person class that we can serialize.

Here is the code that takes the person object into string of xml format.

Using Serialization in .NET is provided by the System.Runtim.Serialization name space.

Once you have the XML string, now you can save it to disk, store it into database, or transfer over the network.
Here is the deserialization method that takes serialized string of XML into the person object.

Kyoungsu Do
Software Quality Engineer
ImageSource, Inc. 


The DataContractSerializer – XML Files Made Easy

With the release of .NET 3.5, Microsoft has included a fun new tool for data serializing.  The DataContractSerializer was introduced as a replacement for the current XmlSerializer class, and is the preferred XML data serializer of developers at ImageSource.

The DataContractSerializer class uses opt-in properties for it’s serialization rather than the XmlSerializer class’s opt-out methodology.  This means that the programmer must specify what class properties are to included in serialization.  It’s also up to the programmer to serialize fields, properties and non-public data.

Continue reading

Hello World Feature in Windows SharePoint Services 3.0

Let’s go back to basics and see how to create a simple custom feature in WSS.  I assume you already create a WSS site or have access to one.

Creating HelloWorldBasic Project

Navigate to C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\FEATURES and create a new folder HelloWorldBasic

Creating feature.xml File

Create a feature.xml file with the following info

Title="Hello World Feature"
Description="My custom feature"

<ElementManifest Location="elements.xml"/>
Creating elements.xml File

In the same folder, create a new file and called it elements.xml with following info

Title="Hello World"
Description="My custom menu item"
Installing HelloWorldBasic Feature

Open the command prompt and execute the commands as shown below


You should see a successful msg

Activating the Feature in WSS

Open your favorite browser and navigate to your WSS site.  From there hit Site Actions | Site Settings | Site features and hit the Activate button


You can run your custom feature now by going back to the Site Actions menu


Hope this helps.

Phong Hoang
Development Manager
ImageSource, Inc.