Posted on January 30th, 2006 by gernot.
Categories: CSharp.
Tags: .NET, C#, code, schema, validation, xml
This is a short tutorial how one can validate a XML Document against a XML schema by using C# and the .NET framework.
using System.Xml;
using System.Xml.Schema;namespace XMLValidation
{
class XMLValidatorTest
{private bool XMLisValid = true;
public void ReadValidateXMLFile()
{
XmlTextReader reader = new XmlTextReader(“C:\\test.xml”);
XmlValidatingReader validator = new XmlValidatingReader(reader);
validator.ValidationType = ValidationType.Schema;
validator.ValidationEventHandler +=
new ValidationEventHandler(this.XMLValidationEventHandler);while (validator.Read())
{
//Add code here to process XML content
}
validator.Close();//Check if XML document is valid or not
if (this.XMLisValid)
Console.WriteLine(“XML Document is valid”);
else
Console.WriteLine(“XML Document is invalid”);
}
}public static void XMLValidationEventHandler(
object sender,ValidationEventArgs args)
{
this.XMLisValid = false;
Console.WriteLine(“XML Validation event” + args.Message);
}}
}
In the XML File:
‹?xml version=”1.0″ encoding=”utf-8″ ?›
‹testNS:testRoot
xmlns:testNS=”http://www.gego.info/testxmlns”
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation=”http://www.gego.info/testxmlns test.xsd”›
In the XSD File:
‹?xml version=”1.0″ encoding=”utf-8″ ?›
‹xs:schema
id=”test”
targetNamespace=”http://www.gego.info/testxmlns”
elementFormDefault=”qualified”
attributeFormDefault=”unqualified”
xmlns=”http://www.gego.info/testxmlns”
xmlns:xs=”http://www.w3.org/2001/XMLSchema”›
Posted on January 25th, 2006 by gernot.
Categories: CSS.
Tags: code, CSS, Webstandards
Everyone knows the problem: Webpages which have too much text on too small space or vica versa. The solution is either make the page fluid or fixed, and with the help of css this is pretty simple:
body {
margin: 0;
padding: 0;
background-color: #000;
color: #fff;
}
#page {
margin: 0 auto;
padding: 0;
width: 760px;
background: #fff;
}
click here for example Here the page never changes its size.
Try and change the size of the browser window.
body {
margin: 0;
padding: 0;
background-color: #000;
color: #fff;
}
#page {
margin: auto;
padding: 0;
width: 90%;
background: #fff;
}
click here for example Here the page always changes its size to fit to the resolution or browser window
Try and change the size of the browser window.
Posted on January 25th, 2006 by gernot.
Categories: CSharp.
Tags: .NET, C#, code, gui
This is a short Tutorial how to create and use User Controls in the .NET Framework (C#):

Here I want to describe how one can fire an event (e.g.: from a button) in the UserControl and notify the Main Application, which uses the User Control:
In MyUserControl1.cs:
//Just a TestString
public string TestString = “Test123″;
// Declare delegate Button1 clicked.
public delegate void Button1_ClickHandler();
// Declare the event, which is associated with our delegate
[Category("Action")] [Description("Fires when the Button1 is clicked.")]
public event Button1_ClickHandler Button1_Clicked;
// Handler for Button1
// NOTE: Don’t forget to add this Handler to the Button itself
private void Button1_Click(object sender, System.EventArgs e)
{
if (Button1_Clicked != null)
// Notify Subscribers
Button1_Clicked();
else
Console.WriteLine(“No Subscribers for Button1″);
}
In Form1.cs:
// NOTE: Don’t forget to add this Handler to the UserControl itself
private void MyUserControl11_Button1_Clicked()
{
Console.WriteLine(“Button1 was clicked in MyUserControl11, TestString:”
+ MyUserControl11.TestString);
}