469,608 Members | 2,462 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,608 developers. It's quick & easy.

Reading XML

Using VBA, is it possible to read a specific child node? For example, I only want to read the second child node and all I know about the node is that it's the second node in my node list. In this example, I'd want to read Info B only:

<Example>
- <Child>
<Data>Data A</Data>
<Info>Info A</Info>
</Child>
- <Child>
<Data>Data B</Data>
<Info>Info B</Info>
</Child>
</Example>
Thank you
Jan 8 '08 #1
1 1271
In ASP.net (C#) we can send the text data form different textbox into database as a XML STRING.
the following code helpfull for readingxml on node level.
Try this :)

DataView data = new DataSet().Tables[0].DefaultView;
XmlSerializer serializer = new XmlSerializer(data.GetType());
StringBuilder sb = new StringBuilder();
TextWriter writer = new StringWriter(sb);

serializer.Serialize(writer, data);
StringReader reader = new StringReader(writer.ToString());

DataSet dst = new DataSet();
dst.ReadXml(reader);
dv = new DataView(dst.Tables[0]);

following code help full for reading data and as well send it into database.
___________________________________________
using System;
using System.Collections;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Data.ProviderBase;
using System.Web.Mail;
using System.Xml;
using System.Xml.Serialization;
using System.Xml.Schema;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;



namespace WebApplication3
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}


protected void Button1_Click1(object sender, EventArgs e)
{



//for List 1
for (int i = 0; i < ListSecA.Items.Count; i++)
{
if (ListSecA.Items[i].Selected)
{
ListSecAValues.Text += ListSecA.Items[i].Value.ToString() + "\n";
}
}
// For List 2
for (int x = 0; x < ListSecB.Items.Count; x++)
{
if (ListSecB.Items[x].Selected)
{
ListSecBValues.Text += ListSecB.Items[x].Value.ToString() + "\n";
}
}
// For list 3
for (int z = 0; z < ListBoxHearAbout.Items.Count; z++)
{
if (ListBoxHearAbout.Items[z].Selected)
{
ListHearValues.Text += ListBoxHearAbout.Items[z].Value.ToString() + "\n";
}
}




string DetailData = "";
DetailData += TextBoxDetail.Text + TextBoxAddress.Text + TextBoxAddress2.Text + TextBoxCity.Text + TextBoxProvince.Text + TextBoxPostalCode.Text + TextBoxFax.Text + TextBoxWebsite.Text + TextBoxAttendee.Text + ListSecAValues.Text + ListSecBValues.Text + TextBoxSecADate.Text + TextBoxSecBDate.Text + TextBoxNumberAtt.Text + TextBoxSubTotal.Text + TextBoxGst.Text + TextBoxTotalDue.Text + DropdownPayment.SelectedItem.Text + TextBoxCreditCardMonth.Text + TextBoxCreditCardYear.Text + TextBoxCreditCardName.Text + ListHearValues.Text + TextBoxComments.Text;
System.Xml.Serialization.XmlSerializer serializ = new System.Xml.Serialization.XmlSerializer(DetailData. GetType());
StringBuilder sb = new StringBuilder();
TextWriter writer = new StringWriter(sb);
serializ.Serialize(writer, DetailData);


string str = "";
SqlConnection conn = new SqlConnection(
"Data source=SYED-PC;Initial Catalog=baass;Integrated Security=True");

conn.Open();
str = "insert into Registrations (EventCode,EventDate,EventTime,EventLocation,Name, Company,Phone,Email,Details) values ('Event of Toronto','03/15/2008','09:30:00 AM','Toronto','" + TextBoxName.Text.ToString() + "','" + TextBoxCompany.Text.ToString() + "','" + TextBoxPhone.Text + "','" + TextBoxEmail.Text.ToString() + "','" + writer.ToString()+ "')";


//sr = "insert into Registrations (EventCode,EventDate,EventTime,EventLocation,Name, Company,Phone,Email,Details) values ('Event of Toronto','03/15/2008','09:30:00 AM','Toronto','" + Request.Form.Get("TextBoxName.text").ToString() + "','" + Request.Form.Get("TextBoxCompany.text").ToString() + "','" + Request.Form.Get("TextBoxPhone.text") + "','" + Request.Form.Get("TextBoxEmail.text").ToString() + "','" + Request.Form.Get("TextBoxDetail.text").ToString() + "')";



SqlCommand md = new SqlCommand(str, conn);

//int y = md.ExecuteNonQuery();
int g = md.ExecuteNonQuery();


conn.Close();
MailMessage mails = new MailMessage();

mails.To = TextBoxEmail.Text;
//mails.Bcc = "abcdef@gmail.com";
mails.From = "WebRegistration@BAASS.accdoc.com";
mails.Subject = "Welcome: " + TextBoxName;

mails.Body = "Hello " + TextBoxName.Text +
"\n \n \n Thank you for your registration request. You have successfully registered \n for the following BAASS Training Course(s). \n \n Series A Course(s):"
+ ListSecAValues.Text + "\n \n Date(s) for Series A Course(s): " + TextBoxSecADate.Text + " \n Time(s) for Series A Course(s): \n \n Series B Course(s):"
+ ListSecBValues.Text + " \n \n Date(s) for Series B Course(s):" + TextBoxSecBDate.Text + "\n Time(s) for Series B Course(s): \n \n \n Registrant Name(s):"
+ TextBoxName.Text + " \n \n \n Company Name:" + TextBoxCompany.Text + " \n Payment Method:" + DropdownPayment.SelectedItem.Text + " \n Total Amount:"
+ TextBoxTotalDue.Text + " \n Location: BAASS Training Centre, 1200 Centre Street, Thornhill, ON L4J 3M9 \n \n \n Please visit www.baass.com/baass01.nsf/pages/Contact.html#map "+
"for a map to the location. \n \n \n Please do not hesitate to contact us if you require further information. \n \n \n Thank you, \n \n \n Susie Pedota \n Consultant Office Manager "+
"\n BAASS Business Solutions Inc.\n Tel: 905.660.1285 Ext. 237 \n Toronto Tel: 416.777.1285 \n Fax: 905.660.3823 \n spedota@baass.com \n www.baass.com \n Bringing Technology to Business";

SmtpMail.SmtpServer = "localhost";
SmtpMail.Send(mails);

MailMessage myself = new MailMessage();
myself.To = "sshah@baass.com";
myself.From = "WebRegistration@BAASS.accdoc.com";
myself.Subject = "BAASS Thornhill Online Course Registration Confirmation";
myself.Body = "Hello " + TextBoxName.Text +
"\n \n \n Thank you for your registration request. You have successfully" +
"registered \n for the following BAASS Training Course(s). \n \n Series A Course(s):" + ListSecAValues.Text +
"\n \n Date(s) for Series A Course(s): " + TextBoxSecADate.Text +
" \n Time(s) for Series A Course(s): \n \n Series B Course(s):"
+ ListSecBValues.Text + " \n \n Date(s) for Series B Course(s):" + TextBoxSecBDate.Text +
"\n Time(s) for Series B Course(s): \n \n \n Registrant Name(s):"
+ TextBoxName.Text + " \n \n \n Company Name:" + TextBoxCompany.Text +
" \n Payment Method:" + DropdownPayment.SelectedItem.Text + " \n Total Amount:" + TextBoxTotalDue.Text +
" \n Location: BAASS Training Centre, 1200 Centre Street, Thornhill, ON L4J 3M9 \n \n \n Please visit "+
"www.baass.com/baass01.nsf/pages/Contact.html#map for a map to the location. \n \n \n Please do not hesitate"+
" to contact us if you require further information. \n \n \n Thank you, \n \n \n Susie Pedota \n Consultant Office Manager "+
"\n BAASS Business Solutions Inc.\n Tel: 905.660.1285 Ext. 237 \n Toronto Tel: 416.777.1285 \n Fax: 905.660.3823 \n spedota@baass.com "+
"\n www.baass.com \n Bringing Technology to Business \n \n \n \n ----------------------------------------------------------------------------------- "+
"\n The following message was sent as a Online Course Registration request. \n Clicking on reply or reply with history will allow you to respond to this \n request. \n \n Registrant Name(s):"
+ TextBoxName.Text + "\n \n \n Company Name: " + TextBoxCompany.Text + " \n Address 1: " + TextBoxAddress.Text + "Address 2: " + TextBoxAddress2.Text + " \n City: " + TextBoxCity.Text + " \n Province: "
+ TextBoxProvince.Text + " \n Postal Code: " + TextBoxPostalCode.Text +
" \n Phone Number: " + TextBoxPhone.Text + " \n Fax Number: " + TextBoxFax.Text + " \n Person's Email: " + TextBoxEmail.Text + " \n Website: " + TextBoxWebsite.Text +
" \n Number of Attendees: " + TextBoxNumberAtt.Text + " \n \n Series A Course(s):"
+ ListSecAValues.Text + "\n \n Date(s) for Series A Course(s): " + TextBoxSecADate.Text + " \n \n Series B Course(s):" + ListSecBValues.Text + " \n \n Date(s) for Series B Course(s):" + TextBoxSecBDate.Text + " \n Subtotal Amount: "
+ TextBoxSubTotal.Text + " \n GST Amount: " + TextBoxGst.Text + " \n Total Due: " + TextBoxTotalDue.Text + " \n Payment Method: " + DropdownPayment.SelectedItem.Text + " \n Credit Card Number: " + TextBoxCreditCard.Text + " \n Expiry Date: MONTH: "
+ TextBoxCreditCardMonth.Text + " Year: " + TextBoxCreditCardYear.Text + " \n Card Holder Name: " + TextBoxCreditCardName.Text + " \n How did you hear about this course: " + ListHearValues.Text + " \n Message: " + TextBoxComments.Text +
" \n -----------------------------------------------------------------------------------\n";


SmtpMail.SmtpServer = "Exchange";

SmtpMail.Send(myself);
Response.Redirect("Thanks.aspx");
Mar 3 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Andy | last post: by
6 posts views Thread by Raymond Hettinger | last post: by
4 posts views Thread by Xah Lee | last post: by
24 posts views Thread by Hendrik Schober | last post: by
19 posts views Thread by Lionel B | last post: by
4 posts views Thread by Oliver Knoll | last post: by
6 posts views Thread by KevinD | last post: by
9 posts views Thread by Mike Reed | last post: by
4 posts views Thread by Gaijinco | last post: by
reply views Thread by guiromero | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.