Reading XML

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bobjones122
    New Member
    • Dec 2007
    • 8

    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
  • syed rizwan iqbal shah
    New Member
    • Mar 2008
    • 2

    #2
    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().Table s[0].DefaultView;
    XmlSerializer serializer = new XmlSerializer(d ata.GetType());
    StringBuilder sb = new StringBuilder() ;
    TextWriter writer = new StringWriter(sb );

    serializer.Seri alize(writer, data);
    StringReader reader = new StringReader(wr iter.ToString() );

    DataSet dst = new DataSet();
    dst.ReadXml(rea der);
    dv = new DataView(dst.Ta bles[0]);

    following code help full for reading data and as well send it into database.
    _______________ _______________ _____________
    using System;
    using System.Collecti ons;
    using System.Componen tModel;
    using System.Configur ation;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Secu rity;
    using System.Web.Sess ionState;
    using System.Web.UI;
    using System.Web.UI.H tmlControls;
    using System.Web.UI.W ebControls;
    using System.Web.UI.W ebControls.WebP arts;
    using System.Xml.Linq ;
    using System.Data.Ole Db;
    using System.Data.Sql Client;
    using System.Data.Pro viderBase;
    using System.Web.Mail ;
    using System.Xml;
    using System.Xml.Seri alization;
    using System.Xml.Sche ma;
    using System.Text;
    using System.Text.Reg ularExpressions ;
    using System.IO;



    namespace WebApplication3
    {
    public partial class _Default : System.Web.UI.P age
    {
    protected void Page_Load(objec t 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 < ListBoxHearAbou t.Items.Count; z++)
    {
    if (ListBoxHearAbo ut.Items[z].Selected)
    {
    ListHearValues. Text += ListBoxHearAbou t.Items[z].Value.ToString () + "\n";
    }
    }




    string DetailData = "";
    DetailData += TextBoxDetail.T ext + TextBoxAddress. Text + TextBoxAddress2 .Text + TextBoxCity.Tex t + TextBoxProvince .Text + TextBoxPostalCo de.Text + TextBoxFax.Text + TextBoxWebsite. Text + TextBoxAttendee .Text + ListSecAValues. Text + ListSecBValues. Text + TextBoxSecADate .Text + TextBoxSecBDate .Text + TextBoxNumberAt t.Text + TextBoxSubTotal .Text + TextBoxGst.Text + TextBoxTotalDue .Text + DropdownPayment .SelectedItem.T ext + TextBoxCreditCa rdMonth.Text + TextBoxCreditCa rdYear.Text + TextBoxCreditCa rdName.Text + ListHearValues. Text + TextBoxComments .Text;
    System.Xml.Seri alization.XmlSe rializer serializ = new System.Xml.Seri alization.XmlSe rializer(Detail Data.GetType()) ;
    StringBuilder sb = new StringBuilder() ;
    TextWriter writer = new StringWriter(sb );
    serializ.Serial ize(writer, DetailData);


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

    conn.Open();
    str = "insert into Registrations (EventCode,Even tDate,EventTime ,EventLocation, Name,Company,Ph one,Email,Detai ls) values ('Event of Toronto','03/15/2008','09:30:00 AM','Toronto',' " + TextBoxName.Tex t.ToString() + "','" + TextBoxCompany. Text.ToString() + "','" + TextBoxPhone.Te xt + "','" + TextBoxEmail.Te xt.ToString() + "','" + writer.ToString ()+ "')";


    //sr = "insert into Registrations (EventCode,Even tDate,EventTime ,EventLocation, Name,Company,Ph one,Email,Detai ls) values ('Event of Toronto','03/15/2008','09:30:00 AM','Toronto',' " + Request.Form.Ge t("TextBoxName. text").ToString () + "','" + Request.Form.Ge t("TextBoxCompa ny.text").ToStr ing() + "','" + Request.Form.Ge t("TextBoxPhone .text") + "','" + Request.Form.Ge t("TextBoxEmail .text").ToStrin g() + "','" + Request.Form.Ge t("TextBoxDetai l.text").ToStri ng() + "')";



    SqlCommand md = new SqlCommand(str, conn);

    //int y = md.ExecuteNonQu ery();
    int g = md.ExecuteNonQu ery();


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

    mails.To = TextBoxEmail.Te xt;
    //mails.Bcc = "abcdef@gmail.c om";
    mails.From = "WebRegistratio n@BAASS.accdoc. com";
    mails.Subject = "Welcome: " + TextBoxName;

    mails.Body = "Hello " + TextBoxName.Tex t +
    "\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.Tex t + " \n \n \n Company Name:" + TextBoxCompany. Text + " \n Payment Method:" + DropdownPayment .SelectedItem.T ext + " \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#ma p "+
    "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.c om \n www.baass.com \n Bringing Technology to Business";

    SmtpMail.SmtpSe rver = "localhost" ;
    SmtpMail.Send(m ails);

    MailMessage myself = new MailMessage();
    myself.To = "sshah@baass.co m";
    myself.From = "WebRegistratio n@BAASS.accdoc. com";
    myself.Subject = "BAASS Thornhill Online Course Registration Confirmation";
    myself.Body = "Hello " + TextBoxName.Tex t +
    "\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.Tex t + " \n \n \n Company Name:" + TextBoxCompany. Text +
    " \n Payment Method:" + DropdownPayment .SelectedItem.T ext + " \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#ma p 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.c om "+
    "\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.Tex t + "\n \n \n Company Name: " + TextBoxCompany. Text + " \n Address 1: " + TextBoxAddress. Text + "Address 2: " + TextBoxAddress2 .Text + " \n City: " + TextBoxCity.Tex t + " \n Province: "
    + TextBoxProvince .Text + " \n Postal Code: " + TextBoxPostalCo de.Text +
    " \n Phone Number: " + TextBoxPhone.Te xt + " \n Fax Number: " + TextBoxFax.Text + " \n Person's Email: " + TextBoxEmail.Te xt + " \n Website: " + TextBoxWebsite. Text +
    " \n Number of Attendees: " + TextBoxNumberAt t.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.T ext + " \n Credit Card Number: " + TextBoxCreditCa rd.Text + " \n Expiry Date: MONTH: "
    + TextBoxCreditCa rdMonth.Text + " Year: " + TextBoxCreditCa rdYear.Text + " \n Card Holder Name: " + TextBoxCreditCa rdName.Text + " \n How did you hear about this course: " + ListHearValues. Text + " \n Message: " + TextBoxComments .Text +
    " \n -----------------------------------------------------------------------------------\n";


    SmtpMail.SmtpSe rver = "Exchange";

    SmtpMail.Send(m yself);
    Response.Redire ct("Thanks.aspx ");

    Comment

    Working...