Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts

Friday, May 8, 2009

[C#] Format a XML string using XmlTextWriter

// a demo string
string xml = "<Root><Eles><Ele>abc</Ele><Ele>123</Ele></Eles></Root>";

System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.LoadXml(xml);

System.IO.StringWriter sw = new System.IO.StringWriter();
using (System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(sw))
{
writer.Indentation = 2; // the Indentation
writer.Formatting = System.Xml.Formatting.Indented;
doc.WriteContentTo(writer);
writer.Close();
}

// out put the formated xml
Console.WriteLine(sw.ToString());


 


From: http://jack-fx.com/blog/programming-Tag/ 

Wednesday, April 1, 2009

Tips : How To Built a Cheap but High Quality Website

Normally, if you want to have professional designers custom build your site, you must be prepared to dish out at least a few hundred dollars. All this can change if you know where to find the best deals, the best designs for the lowest price. Here's a rough guide:

First, you must understand that it is a rip off to get companies to design websites for you. Have you ever seen those advertisements in newspaper classified ad sections that offer a 5-page website at $500? These companies are established companies with physical locations, therefore they have to increase the amount they charge to pay off some overheads: office rent, designer's wages, advertising costs and so on.

Therefore, it would be wise to find freelance designers who work from home. These people are often working from home so they do not have a high operation cost like that of a company. On the other hand, they will be able to design images with quality similar to those of designers from big companies, so it's a "no-brainer" choice.

… …

Go http://jack-fx.com/tech-article/105.htm to view the full article

Sunday, March 29, 2009

A Programming hint: Prefer Small, Simple Functions

As experienced programmers, in whatever language we favored before C#, we internalized several practices for developing more efficient code. Sometimes what worked in our previous environment is counterproductive in the .NET environment. This is very true when you try to hand-optimize algorithms for the C# compiler. Your actions often prevent the JIT compiler from more effective optimizations. Your extra work, in the name of performance, actually generates slower code. You're better off writing the clearest code you can create. Let the JIT compiler do the rest. One of the most common examples of premature optimizations causing problems is when you create longer, more complicated functions in the hopes of avoiding function calls. Practices such as hoisting function logic into the bodies of loops actually harm the performance of your .NET applications. It's counterintuitive, so let's go over all the details.

This chapter's introduction contains a simplified discussion of how the JIT compiler performs its work. The .NET runtime invokes the JIT compiler to translate the IL generated by the C# compiler into machine code. This task is amortized across the lifetime of your program's execution. Instead of JITing your entire application when it starts, the CLR invokes the JITer on a function-by-function basis. This minimizes the startup cost to a reasonable level, yet keeps the application from becoming unresponsive later when more code needs to be JITed. Functions that do not ever get called do not get JITed. You can minimize the amount of extraneous code that gets JITed by factoring code into more, smaller functions rather than fewer larger functions.

For detail, go http://jack-fx.com/tech-article/102.htm