I know I wrote before a week ago when I knew even less than now but I am
getting better please anyone give me a clue or an example. Am I completely
off track?
I have a datarow in a table with the fields to map to an xsd. Then i call a
web service upload method that wants the xml strongly typed to the xsd in a
string.
so I have generated a class from a xsd newcust.cs in .net 1.1 c#
to start with just to see what it means to use an xsd with a dataset to
create an xml document for starter but I get the error at the end I know I
am new but I am running out of options to teach myself from examples online.
using System;
using System.Xml;
using System.Xml.Seri alization;
using System.IO;
namespace xmlsenddata
{
[XmlRootAttribut e("PurchaseOrde r", Namespace="",Is Nullable = true)]
public class newcust
{
public DOCUMENT xdoc;
public DOCUMENTDOCUMEN THEADER xhdr;
public DOCUMENTCustome r xcust;
}
public class DOCUMENT
{
[System.Xml.Seri alization.XmlEl ementAttribute( Form=System.Xml .Schema.XmlSche maForm.Unqualif ied)]
public DOCUMENTDOCUMEN THEADER DOCUMENTHEADER;
[System.Xml.Seri alization.XmlEl ementAttribute( "Customer",
Form=System.Xml .Schema.XmlSche maForm.Unqualif ied)]
public DOCUMENTCustome r[] Customer;
}
public class DOCUMENTDOCUMEN THEADER
{
[System.Xml.Seri alization.XmlEl ementAttribute( Form=System.Xml .Schema.XmlSche maForm.Unqualif ied)]
public string SENDER;
[System.Xml.Seri alization.XmlEl ementAttribute( Form=System.Xml .Schema.XmlSche maForm.Unqualif ied)]
public string RECIPIENT;
[System.Xml.Seri alization.XmlEl ementAttribute( Form=System.Xml .Schema.XmlSche maForm.Unqualif ied)]
public string TYPE;
[System.Xml.Seri alization.XmlEl ementAttribute( Form=System.Xml .Schema.XmlSche maForm.Unqualif ied)]
public string SUBTYPE;
[System.Xml.Seri alization.XmlEl ementAttribute( Form=System.Xml .Schema.XmlSche maForm.Unqualif ied)]
public string REFERENCENO;
}
public class DOCUMENTCustome r
{
[System.Xml.Seri alization.XmlEl ementAttribute( Form=System.Xml .Schema.XmlSche maForm.Unqualif ied)]
public string AccountNumber;
[System.Xml.Seri alization.XmlEl ementAttribute( Form=System.Xml .Schema.XmlSche maForm.Unqualif ied)]
public string Address1;
[System.Xml.Seri alization.XmlEl ementAttribute( Form=System.Xml .Schema.XmlSche maForm.Unqualif ied)]
public string City;
[System.Xml.Seri alization.XmlEl ementAttribute( Form=System.Xml .Schema.XmlSche maForm.Unqualif ied)]
public string State;
[System.Xml.Seri alization.XmlEl ementAttribute( Form=System.Xml .Schema.XmlSche maForm.Unqualif ied)]
public string Zip;
}
}
I have a web page that gets a data set and I try to use the data to
serialize an XML doc using the class newcust.
public class WebForm2 : System.Web.UI.P age
{
string connString = "Data Source=tsbusisd ev; Initial Catalog=pubs;
Integrated Security=SSPI";
string sqlQueryString = "";
public newcust nc = new newcust();
private void Page_Load(objec t sender, System.EventArg s e)
{
newcustomer();
}
private void newcustomer()
{
sqlQueryString = "Select * from authors where au_id = '172-32-1176'";
SqlConnection myConn = new SqlConnection(c onnString);
SqlDataAdapter adapter = new SqlDataAdapter( );
adapter.SelectC ommand = new SqlCommand(sqlQ ueryString,myCo nn);
DataSet myDs = new DataSet();
adapter.Fill(my Ds);
XmlSerializer serializer = new XmlSerializer(t ypeof(newcust)) ;
TextWriter writer = new StreamWriter("c :\\docnc.xml");
//Create header
nc.xhdr.RECIPIE NT = "GEW_EASINE T";
nc.xhdr.TYPE = "ESP_CUSTOM ER";
nc.xhdr.SENDER = "GEW_WEB";
nc.xhdr.SUBTYPE ="NEW-GEW";
nc.xhdr.REFEREN CENO=myDs.Table s[0].Rows[0]["au_id"].ToString();
//create cust
nc.xcust.Accoun tNumber = myDs.Tables[0].Rows[0]["contract"].ToString();
nc.xcust.Addres s1 = myDs.Tables[0].Rows[0]["address"].ToString();
nc.xcust.City = myDs.Tables[0].Rows[0]["city"].ToString();
nc.xcust.State = myDs.Tables[0].Rows[0]["state"].ToString();
nc.xcust.Zip = myDs.Tables[0].Rows[0]["zip"].ToString();
//write file
serializer.Seri alize(writer, nc);
writer.Close();
}
I get an error
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.
Exception Details: System.NullRefe renceException: Object reference not set
to an instance of an object.
Source Error:
Line 39: TextWriter writer = new StreamWriter("c :\\docnc.xml");
Line 40: //Create header
Line 41: nc.xhdr.RECIPIE NT = "GEW_EASINE T";
Line 42: nc.xhdr.TYPE = "ESP_CUSTOM ER";
Line 43: nc.xhdr.SENDER = "GEW_WEB";
I know I wrote before a week ago when I knew even less than now but I am
getting better please anyone give me a clue or an example. Am I completely
off track?
I have a datarow in a table with the fields to map to an xsd. Then i call a
web service upload method that wants the xml strongly typed to the xsd in a
string.
--
cindy