Appending to an XML file dynamically

If you need to store information inside an XML file without losing its contents, you can use the following.

This code allows you to append your data into existing XML elements.

public void StoreToXML()

        {

 

  XmlDocument xdoc = new XmlDocument();

  xdoc.Load(“scores.xml”);

  xdoc.GetElementsByTagName(“Asset”).Item(0).InnerXml =

                           xdoc.GetElementsByTagName(“Asset”).Item(0).InnerXml + “<Player>”+ PlayerName + “</Player><Score>” + Score.ToString() +“</Score>”;

     

          

FileStream fsxml = new FileStream(“scores.xml”,FileMode.Truncate,FileAccess.Write,FileShare.ReadWrite);

          

            // XML Document Saved

            xdoc.Save(fsxml);

            fsxml.Flush();

            fsxml.Close();

         }

For running the above code, You should have an XML file and inside that, you should have the following elements.

<root>

<Asset>

</Asset>

</root>

Ex-Output:

<root>

<Asset>

<Player> NewPlayer </Player>

<Score> NewScore </Score>

</Asset>

</root>

Reading node values from an XML

Commonly we are using Dataset,Datatable to fetch values from XML.

I faced a situation in which dataset/datatable is not available. So i did the same thing using Multidimensional array as follows..

public string[,] GetSectionContents()

        {

 string[,] strContent = new string[100, 3];

int categorylength = 0,i=0;

                  

   using (XmlReader xmlreader = XmlReader.Create(“myxml.xml”))

            {

                while (xmlreader.Read())

                {

                    // Only detects start elements.

                    if (xmlreader.Name == “Item”)

                    {

                        while (xmlreader.Read())

                        {

                            switch (xmlreader.Name)

                            {

                                case “Item”:

                                    if (xmlreader.IsStartElement())

                                    {

                                        categorylength++;

                                        i = 0;

                                    }

                                    break;

                                case “Title”:

                                    strContent[categorylength, i] = xmlreader.ReadElementContentAsString();

                                    i++;

                                    break;

                                case “URL”:

                                    strContent[categorylength, i] = xmlreader.ReadElementContentAsString();

                                    i++;

                                    break;

                                case “ThumbnailImage”:

                                    strContent[categorylength, i] = xmlreader.ReadElementContentAsString();

                                    i++;

                                    break;

                            }

                        }

                    }

                }

                return strContent;

}

XML file will be like the below one,

<Root>
<SiteName>Framework</SiteName>
<SiteURL/>
<Logo/>
<Author>VVF</Author>
<UpdatedOn>Tue, 17 Aug 2010 11:25:57 GMT</UpdatedOn>
<Request>
<URL>
http://vvf.site.com/api/search/category?type=cat&name=movies
</URL>
<Parameter>type=cat&name=movies</Parameter>
<RequestedOn>Tue, 28 Sep 2010 05:49:18 GMT</RequestedOn>
<IPAddress>124.227.224.18</IPAddress>
</Request>
<Response>
<Item>
<Title>Aginamoto</Title>
<Description/>
<Category>Movies</Category>
<URL>Verandah/Video.aspx?videoID=415&CategoryID=4</URL>
<ThumbnailImage>Images/415-ABP-1-vpf.gif</ThumbnailImage>
<Rating>3</Rating>
<Duration>00:00:32</Duration>
</Item>
</Response>
</Root>

Rounded corners in HTML using CSS

Hi all

Below is one of the example to display a container with rounded corners in all the browsers.

HTML Source

<html>
<head>
<title>Rounded Corner</title>
<style type="text/css">
.roundcont {
	width: 285px;
	background-color: #f90;
	color: #fff;
}

.roundtop {
	background: url(tr.gif) no-repeat top right;
}

.roundbottom {
	background: url(br.gif) no-repeat top right;
}

img.corner {
   width: 15px;
   height: 15px;
   border: none;
   display: block !important;
}

</style>
</head>
<body>
<div class="roundcont">
   <div class="roundtop">
	 <img src="tl.gif" alt=""
	 width="15" height="15" class="corner"
	 style="display: none" />
   </div>

 <p> <center>This is the example for displaying Rounded Corners</center></p>

   <div class="roundbottom">
	 <img src="bl.gif" alt=""
	 width="15" height="15" class="corner"
	 style="display: none" />
   </div>
</div>
</body>
</html>
 

Images used (Save in the folder in which you are placing the HTML file)

Output will be like the below one,