30th July 2006, 02:45 pm
Let’s say we have an XML file and we want to deserialize that file to our implemented class. This is an easy task if the XML file is simple. However if it has more complex types, it can take a long time to implement the class without error. XSD comes with .Net framework SDK. I does not have a user interface, we can access it from the command line tools.
-
We start it from Visual Studio 2005 -> Visual Studio Tools -> Visual Studio Command Prompt .
- Next we need to have a valid XML file that I want to generate the class from. I just use for this sample, the xml output of the yahoo search REST query. Just dowload the xml output of the query
Yahoo Search xml+class+generator or any other xml file that you want to generate the class from. We save the file as xml.
- We use the command xsd to the xml file to generate the xsd schema file.
D:\\test>xsd webSearch.xml
Microsoft (R) Xml Schemas/DataTypes support utility
[Microsoft (R) .NET Framework, Version 2.0.50727.42]
Copyright (C) Microsoft Corporation. All rights reserved.
Writing file ‘D:\\test\\webSearch.xsd’.
D:\\test>
- Next we use the generated xsd file to generate our class. The generated xsd can contain multiple class, so it would be better to use /classes switch. The default language is C#; however you might want to use it in your Visual Basic Project, to do that just add the switch /language:vb
D:\\test>xsd webSearch.xsd /CLASSES /language:vb
Microsoft (R) Xml Schemas/DataTypes support utility
[Microsoft (R) .NET Framework, Version 2.0.50727.42]
Copyright (C) Microsoft Corporation. All rights reserved.
Writing file ‘D:\\test\\webSearch.vb’.
D:\\test>xsd webSearch.xsd /CLASSES
Microsoft (R) Xml Schemas/DataTypes support utility
[Microsoft (R) .NET Framework, Version 2.0.50727.42]
Copyright (C) Microsoft Corporation. All rights reserved.
Writing file ‘D:\\test\\webSearch.cs’.
- Now we have the class file that we use to deserialize the xml object without any exception. So I add the XML file and the generated cs file to my project.
using System;
using System.Collections.Generic;
using System.Text;
namespace XSDTest
{
class Program
{
static void Main(string[] args)
{
System.IO.StreamReader str = new System.IO.StreamReader("webSearch.xml");
System.Xml.Serialization.XmlSerializer xSerializer = new System.Xml.Serialization.XmlSerializer(typeof(ResultSet));
ResultSet res = (ResultSet) xSerializer.Deserialize(str);
foreach (ResultSetResult r in res.Result)
{
Console.WriteLine(r.Title);
Console.WriteLine(r.Summary);
Console.WriteLine();
}
str.Close();
Console.ReadLine();
}
}
}
- Here is the output :
XML Class Generator for C++
Oracle9i XML Developer’s Kits Guide - XDK. Release 2 (9.2) Part Number A96621-01
. 19. XML Class Generator for C++ This chapter contains the following sections:
Accessing XML C++ Class Generator … Accessing XML C++ Class Generator. The XML
C++ Class Generator is provided with Oracle9i and is also available for XML Class Generator for Java
Oracle9i XML Developer’s Kits Guide - XDK. Release 2 (9.2) Part Number A96621-01
. 7. XML Class Generator for Java. This chapter contains the following sections:
Accessing XML Class Generator for Java … The Oracle XML Class Generator for Java is provided with Oracle9i’s XDK for Java …
As you may see this is the easiest and exceptionless solution for using xml output of some web services. What we simply do is generate the classfile, deserialize the xml file to our class and use it.
Download
Downloads: 1644 File Name: xsdtest.zip
.
Tags:
.Net,
C#,
code-generation,
download,
net_framework,
visual_studio,
websearch,
XML,
xml_file,
xml_schemas,
xsd Category:
.Net,
C#,
XML |
7 Comments
26th July 2006, 01:15 am
I get the coolest exception from .Net FatalExecutionError. What is cool for that exception is that it is assuming that itself might be wrong. “This error may be a bug in the CLR.” So I might not be the one who generated, I can just blame CLR for doing that 

“The runtime has encountered a fatal error. The address of the error was at
0×79eebbc1, on thread 0×141c. The error code is 0xc0000005. This error may
be a bug in the CLR or in the unsafe or non-verifiable portions of user
code. Common sources of this bug include user marshaling errors for
COM-interop or PInvoke, which may corrupt the stack.”
Luckily this is not a bug in the CLR. It was my fault. In this sample project, I try to generate a reflected dynamic IL function (I call it like that) to lower the execution time for the reflection. The sample works perfect with value types and reference types, however I have a problem with generic value types. Some boxing and unboxing operation might be faulty in this snippet. What is really causing that error is because I generate IL code dynamically and IL code is the compiled code, the runtime executes the statements of IL, and it gets an internal exception. Normally such a code wouldn’t compile that way so it will continue to operate normally. As a result it suspects from itself.
I will share more on dynamic execution in a later post when I get finished the code and solved my bug.
public class DynamicReflectionHelper
{
public delegate object GetPropertyFieldDelegate(object obj);
public static GetPropertyFieldDelegate GetP(object o,string memberName)
{
Type v = o.GetType();
PropertyInfo pi = v.GetProperty(memberName);
FieldInfo fi = v.GetField(memberName);
if (pi != null || fi != null)
{
DynamicMethod dm = new DynamicMethod( "GetPropertyorField_" + memberName, typeof(object), new Type[] { typeof(object) }, v.Module);
ILGenerator il = dm.GetILGenerator();
il.Emit(OpCodes.Ldarg_0);
if (pi.PropertyType.IsValueType)
il.Emit(OpCodes.Box, pi.PropertyType);
if (pi.PropertyType.IsGenericType)
il.Emit(OpCodes.Nop);
if (pi != null)
il.EmitCall(OpCodes.Callvirt, pi.GetGetMethod(), null);
else if (fi != null)
il.Emit(OpCodes.Ldfld, fi);
il.Emit(OpCodes.Ret);
return (GetPropertyFieldDelegate) dm.CreateDelegate( typeof(GetPropertyFieldDelegate));
}
else
throw new NullReferenceException("No property or Field");
}
}
19th July 2006, 09:05 pm
Have you ever wanted to execute a set of commands before or after the compilation, like copying the contents of the directory to the target compilation directory, or copy output of the compilation to a specified folder. This feature is integrated inside visual studio with the name; “Pre-build or Post-build event command line”. You access it from the project properties, in the build events tab.

If you want to do something before the compilation you enter the shell commands to pre-build, and post-build is the operations for after the compilation. We can use the predefined macros without hard copying the directory names. The edit window will guide us to find the macros.

Let’s say we want to copy the contents of the output directory to the root d:\. What we do is to edit the post-build event command with the command :
copy /D $(TargetPath) c:\
When we build it. We just get the error, “The command “copy D:\DEV\_Projects\sampleProj\bin\sample.dll d:\” exited with code 1.” Trying to execute the code from command line you get a similar error ‘The system cannot find the file specified.’
copy D:\\DEV\\_Projects\\sampleProj\\bin\\sample.dll d:"
The system cannot find the file specified.
What we forget is the need for the quotations for the long directory and filenames.
copy /D \"$(TargetPath)\" "c:\"
As a result, we can do whatever bat file operations before or after the compilation.
17th July 2006, 10:47 pm
I use for TOAD the development as the oracle IDE like most people. When I’ve heard about oracle sql I was wondered, first of all it is developed by the oracle itself, second it’s free :)The first version of the product was bad, I was unable yo use it properly, but with the patch 2 it is much better. I suffer TOAD a lot while writing pl-sql. I am not feeling very comfortable without intellisense, and Oracle Sql Developer does that great.
Screenshots
Connection Settings Window, very simple to configure.

Editing a stored procedure
Intellisense on table names, table columns, procedure names, packet names


17th July 2006, 10:17 pm
I was having trouble with one of my SPs and I needed to handle it correctly. As a result I needed to "throw" (raise) the exception. In that case we have three oppurtunities. SQLCODE and SQLERRM can be used to output the message.
- Throw one of the default exceptions
These exceptions are defined by the database itself. Like ZERO_DIVIDE NO_DATA_FOUND exceptions. OTHERS will catch everything other that you have specified. To have the behaviour of try catch statements, it’s a good practice to write your exception handler in begin and blocks.
BEGIN
--DO SOMETHING
EXCEPTION WHEN ZERO_DIVIDE THEN
--UPDATE SOMETHING
WHEN OTHERS THEN
P_CODE:= SQLCODE;
P_MSG := SQLERRM;
END;
- Throw user defined exceptions
We are not limited to oracle’s internal exception types we can declare our exception variable and throw (raise) it.
userisnotonline EXCEPTION;
BEGIN
--DO SOMETHING
IF x>5 THEN
RAISE userisnotonline;
END IF;
COMMIT;
WHEN userisnotonline THEN
ROLLBACK;
P_message := 'user is not online';
RAISE userisnotonline;
END;
- Raise an application error
If you want to provide a customized output for your error messages or want to make something more complex than oracle’s exceptions you can write your own application errors. User defined exception can not contain any information, you can not specify the output or code of the error. raise_application_error command can be utilized for sending your custom error messages.
The first parameter is the error number. We have -20000 to -20999 numbers that we can use.
We don’t have rights to debug and trace in our development Oracle database. So I use raise application error for tracing, just like alert in javascript. It is not the correct way, but it works.
-- insert something, get the primary key to a variable.
IF p_key >3 THEN
raise_application_error(-20001, 'This field cant be lower than 3');
END IF;
16th July 2006, 07:17 pm
To make an HTML element transparent. Just use these css elements in your css class. filter, moz-opacity, opacity.
Internet Explorer uses filter and firefox uses moz-opacity.
.transparent
{
filter:alpha(opacity=60);
-moz-opacity: 0.6;
opacity: 0.6;
}
<div class="transparent">A transparent div.
</div>
The opacity value changes from 0 to 1.