Warning: Undefined variable $html in /customers/9/6/e/chocofant.dk/httpd.www/2010/php/MessageController.php on line 98

Validating XML

Here is a simple example of how you can validate xml input.
// The input could come from a web service
string xml = {XML input string}

// Path to schema
string xsdFilePath = "Item.xsd";

// Set xsd schema
XmlSchemaSet schemas = new XmlSchemaSet();
schemas.Add(null, xsdFilePath);

// Callback handler to handle validation events
ValidationEventHandler eventHandler = new ValidationEventHandler(ValidationCallBack);

// Load xmldocument
XmlDocument xDoc = new XmlDocument();
xDoc.LoadXml(xml);

// Add schema and validate document
xDoc.Schemas = schemas;
xDoc.Validate(eventHandler);

Definition of CallBack method.
private void ValidationCallBack(object sender, ValidationEventArgs e)
{
switch (e.Severity)
{
case XmlSeverityType.Error:
throw new Exception(e.Message);
case XmlSeverityType.Warning:
throw new Exception(e.Message);
default: break;
}
}

XML input.
<Item>
<Id>Unique ID</Id>
<Date>2000-00-00 00:00:00</Date>
<Result>Data</Result>
</Item>

Schema definition.
<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified"
elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Item">
<xs:complexType>
<xs:sequence>
<xs:element name="Id" />
<xs:element name="Date" />
<xs:element name="Result" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>


Accessing COM+ programmatically

Add a reference to the COMAdmin assembly.
using COMAdmin;

A couple of enums representing the values for Transaction and Isolation level on Service components.
enum Transaction
{
Ignored = 0,
None = 1,
Supported = 2 ,
Required = 3 ,
RequiresNew = 4
}

enum TxIsolationLevel
{
Any = 0,
ReadUnCommitted = 1,
ReadCommitted = 2,
RepeatableRead = 3,
Serializable = 4
}

Connect to the COM+ catalog
COMAdminCatalogClass cat = new COMAdminCatalogClass();
cat.Connect("ComPlusHost");

Pick you collection, in this case the collection with the "Applications" name and print all the application names.
COMAdminCatalogCollection apps =
cat.GetCollection("Applications") as COMAdminCatalogCollection;

apps.Populate();
IEnumerator i = apps.GetEnumerator();
while (i.MoveNext())
{
ICatalogObject app = i.Current as ICatalogObject;
Console.WriteLine("Application Name: {0}", app.Name.ToString());
}

Print out some properties for the items in the collection.
foreach (COMAdminCatalogObject obj in apps)
{
if (obj.Name.ToString().Equals("MyComponent"))
{
ICatalogCollection col =
apps.GetCollection("Components", obj.Key) as
ICatalogCollection;
col.Populate();

foreach (COMAdminCatalogObject comp in col)
{
Console.WriteLine("Component Name: {0}", comp.Name.ToString());

Console.WriteLine("Component Level: {0}, {1}",
Enum.GetName(typeof(Transaction), comp.get_Value("Transaction")),

Enum.GetName(typeof(TxIsolationLevel),
comp.get_Value("TxIsolationLevel")));
}
}
}



<- Previous page |