Wednesday, November 16, 2011

generate classes from XSD file

To generate the classes from XSD, run the following on the command line
LinqToXsd.exe /Myschema.xsd

Note: download above exe from codeplex
http://linqtoxsd.codeplex.com/

serialization - Deserialization example

public class MySampleClass
{
//class fields
public string mystring = "Hello World";
public int myint = 1234;
public string[] mystrarray = new string[4];
private int myprivateint = 4321;

//public property
private string _mynameproperty;
public string MyNameProperty
{
get { return _mynameproperty; }
set { _mynameproperty = value; }
}
//constructor
public MySampleClass()
{ }
//public method
public string MyMethod()
{
return _mynameproperty;
}
}


public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
//Serialization exmaple
//serialization is the process of saving class member data into XML
//only public properties and fields can be serialized
MySampleClass objmysampleClass = new MySampleClass();
objmysampleClass.MyNameProperty = "This is Prashant Rathod";
objmysampleClass.mystrarray[0] = "adfsasf";
objmysampleClass.mystrarray[1] = "546345";
objmysampleClass.mystrarray[2] = "uoafas";
objmysampleClass.mystrarray[3] = "34672";

XmlSerializer myxmlserializer = new XmlSerializer(typeof(MySampleClass));
StreamWriter mystreamwriter = new StreamWriter(@"c:\MysampleSerializeXMLfile.xml");
myxmlserializer.Serialize(mystreamwriter, objmysampleClass);
mystreamwriter.Close();
//Deserialization is the reverse process – loading class member data from an XML document
MySampleClass objfromXMLfile = new MySampleClass();
XmlSerializer myserializer = new XmlSerializer(typeof(MySampleClass));
FileStream filestream = new FileStream(@"c:\MysampleSerializeXMLfile.xml", FileMode.Open);
objfromXMLfile = (MySampleClass)myserializer.Deserialize(filestream);

Console.WriteLine(objfromXMLfile.mystring);
Console.WriteLine(objfromXMLfile.MyNameProperty);
Console.WriteLine(objfromXMLfile.myint);
Console.WriteLine(objfromXMLfile.mystrarray);

}
}

Monday, November 14, 2011

reading values from xml datatype in sql database

declare @test xml
DECLARE @ProvPayNoID int
set @test = '
'

SET @ProvPayNoID = @test.value('(/Fields/Field/@Value)[3]', 'int' )
SELECT @ProvPayNoID

declare @providerpayno int

select top 100 convert(xml,ExtraProperties).value('(/Fields/Field/@Value)[1]', 'int' ) as provpayno
from dbm.MedicalClaimsStaging
where BatchId='e5fff885-91bc-40a7-9350-5d176ca2fdfa'


declare @myDoc xml
DECLARE @ProdID int
set @myDoc = '
1 year parts and labor
3 year parts and labor extended maintenance is available
'
SET @ProdID = @myDoc.value('(/Root/ProductDescription/@ProductID)[1]', 'int' )
SELECT @ProdID










'

SET @ProvPayNoID = @test.value('(/Fields/Field/@Value)[3]', 'int' )
SELECT @ProvPayNoID

declare @providerpayno int

select top 100 convert(xml,ExtraProperties).value('(/Fields/Field/@Value)[1]', 'int' ) as provpayno
from mytable



declare @myDoc xml
DECLARE @ProdID int
set @myDoc = '


1 year parts and labor
3 year parts and labor extended maintenance is available


'
SET @ProdID = @myDoc.value('(/Root/ProductDescription/@ProductID)[1]', 'int' )
SELECT @ProdID

Sunday, November 6, 2011

XML to XSD error

Error: Cannot have more than one type of file as input.

because the parameter sequence is not correct.

Parameter should be
nevigate to folder that has xml file

cd c:\xmltoxsdtest
type: XSD myxmlfile.xml
hit enter

create XSD file from XML file

using microsoft XSD.exe tool
1) go to command line (.Net command line)
2) cd path to where your xml file is located (cd c:\myxsdmapping)
3) type "XSD myxmlfile.xml
4) that it -- very simple

Thursday, October 13, 2011

add pssnapin to computer all powershell session - powershell

go to
%systemroot%\System32\WindowsPowerShell\v1.0

2) Create profile.ps1 file
add following

[void][System.Reflection.Assembly]::LoadFile("C:\ProgramFiles\My.Powershell.DLL")
Add-PSSnapin -name "My.Powershell"

3) powershell global config

create powershell.exe.config file
configuration
appSettings
add key="SMTP_SERVER" value="mail.mydomain.com"
add key="email_from" value="HciPowershell@gmail.com"
add key="Working_Path" value="G:\AutoRun\"
add key="healthxhrafromemail" value="DevTeam@hciactive.com"
appSettings
configuration

Monday, October 3, 2011