Solution 1:
If you want to Write a XML string using XmlWriter, you can use below code.
Add below namespace references to the project.
using System.Xml;
using System.IO;
using System.Text;
The XmlWriter and XmlTextWriter classes are defined in the System.XML namespace.
StringBuilder strbuilder = new StringBuilder();
using (XmlTextWriter xmltxtwriter = new XmlTextWriter(stringWriter))
{
xmltxtwriter.Formatting = Formatting.Indented;
// Add elements to the string
xmltxtwriter.WriteStartElement("Employee");
xmltxtwriter.WriteAttributeString("Contract Year", "2010");
xmltxtwriter.WriteStartElement("Name");
xmltxtwriter.WriteString("Employee Name");
xmltxtwriter.WriteEndElement();
xmltxtwriter.WriteStartElement("UserName");
xmltxtwriter.WriteString("User Name");
xmltxtwriter.WriteEndElement();
xmltxtwriter.WriteStartElement("StartDate");
xmltxtwriter.WriteString("Start Date of Contract");
xmltxtwriter.WriteEndElement();
xmltxtwriter.WriteStartElement("EndDate");
xmltxtwriter.WriteString("End Date of Contract");
xmltxtwriter.WriteEndElement();
xmltxtwriter.Close();
}
Console.WriteLine(strbuilder.ToString());
Console.Read();
Solution 2:
If you want to Write to XML File using XmlWriter, you can use below code.
Add below namespace reference to the project.
using System.Xml;
The XmlWriter and XmlTextWriter classes are defined in the System.XML namespace.
// Creates an XML file, if it doesn’t exist
using (XmlTextWriter writer= new XmlTextWriter("C:\\Test.xml",null ))
{
// Starts a new document
writer.WriteStartDocument();
// Add elements to the file
writer.WriteStartElement("Employee");
writer.WriteAttributeString("Contract Year", "2010");
writer.WriteStartElement("Name");
writer.WriteString("Employee Name");
writer.WriteEndElement();
writer.WriteStartElement("UserName");
writer.WriteString("User Name");
writer.WriteEndElement();
writer.WriteStartElement("StartDate");
writer.WriteString("Start Date of Contract");
writer.WriteEndElement();
writer.WriteStartElement("EndDate");
writer.WriteString("End Date of Contract");
writer.WriteEndElement();
// Ends the document
writer.WriteEndDocument();
writer.Close();
}
The .NET Framework allows developers to use the same set of skills to rapidly buid great applications for the web, windows, services and more.
Date and Time in status bar using Javascript
Do you want to show Date and Time in status bar using Javascript? Or If you want to display Date and Time in status bar having MM/DD/YYY hh:mm:ss AM/PM format, copy below code in your page.
<head id="Head1" runat="server">
<title>Date and Time (MM/DD/YYYY hh:mm:ss AM/PM) in Status Bar Using Javascript</title>
<script language="JavaScript" type="text/javascript">
var timerID = null;
var timerRunning = false;
function showDateAndTime()
{
var vNow = new Date();
var vHr = vNow.getHours();
var vMin = vNow.getMinutes();
var vSec = vNow.getSeconds()
var vTime = vNow.getMonth()+1 + "/" + vNow.getDate() + "/" + vNow.getUTCFullYear()+ " "
vTime += "" + ((vHr >12) ? vHr -12 :vHr)
vTime += ((vMin < 10) ? ":0" : ":") + vMin
vTime += ((vSec < 10) ? ":0" : ":") + vSec
vTime += (vHr >= 12) ? " PM" : " AM"
window.status = vTime;
timerID = setTimeout("showDateAndTime()",1000);
timerRunning = true;
}
</script>
</head>
<body onload="showDateAndTime()">
</body>
<head id="Head1" runat="server">
<title>Date and Time (MM/DD/YYYY hh:mm:ss AM/PM) in Status Bar Using Javascript</title>
<script language="JavaScript" type="text/javascript">
var timerID = null;
var timerRunning = false;
function showDateAndTime()
{
var vNow = new Date();
var vHr = vNow.getHours();
var vMin = vNow.getMinutes();
var vSec = vNow.getSeconds()
var vTime = vNow.getMonth()+1 + "/" + vNow.getDate() + "/" + vNow.getUTCFullYear()+ " "
vTime += "" + ((vHr >12) ? vHr -12 :vHr)
vTime += ((vMin < 10) ? ":0" : ":") + vMin
vTime += ((vSec < 10) ? ":0" : ":") + vSec
vTime += (vHr >= 12) ? " PM" : " AM"
window.status = vTime;
timerID = setTimeout("showDateAndTime()",1000);
timerRunning = true;
}
</script>
</head>
<body onload="showDateAndTime()">
</body>
Subscribe to:
Posts (Atom)