1
Answer

Serialize XM into Object..

Photo of ca guy

ca guy

15y
3.4k
1

Hi Guys,
             I am trying to read xml file into object, having difficult time to determine class structure, i am getting confused between attributes & nodes. Can anyone please help me how i should define class that match XML structure? Here is the structure of XML file
Thank you
<?xml version="1.0" encoding="UTF-8"?>
<root>
    <item id="job1" type="test">
        <attr name="BOOK" type="string" value="TEST LOCATION"/>
        <attr name="ORIGIN" type="string" value="COPY"/>
        <childcomponent type="test">
            <attr name="CODE" type="string" value="375"/>
        </childcomponent>
        <resources>
            <resource file="12532160239881.tiff"
                mime="image" type="ICMBASE"/>
        </resources>
    </item>
    <item id="job2" type="PROD">
        <attr name="BOOK" type="string" value="TEST LOCATION"/>
        <childcomponent type="test">
            <attr name="CODE" type="string" value="375"/>
        </childcomponent>
        <childcomponent type="test">
            <attr name="CODE" type="string" value="997105514"/>
        </childcomponent>
        <childcomponent type="test">
            <attr name="CODE" type="string" value="997105509"/>
        </childcomponent>
        <resources>
            <resource file="12532160239882.tiff"
                mime="image" type="ICMBASE"/>
        </resources>
    </item>
    <item id="job3" type="PROD">
        <attr name="BOOK" type="string" value="TEST LOCATION"/>
        <attr name="ORIGIN" type="string" value="COPY"/>
        <attr name="COMMENT" type="string" value="BL - 5/16/05 - 1/1/06"/>
        <childcomponent type="test">
            <attr name="CODE" type="string" value="375"/>
        </childcomponent>
        <resources>
            <resource file="12532160239883.tiff"
                mime="image" type="ICMBASE"/>
        </resources>
    </item>
    <item id="job4" type="PROD">
        <attr name="BOOK" type="string" value="NEW YORK CI IMAGING TEAM"/>
        <childcomponent type="test">
            <attr name="CODE" type="string" value="377"/>
        </childcomponent>
        <resources>
            <resource file="12532160239884.tiff"
                mime="image" type="ICMBASE"/>
        </resources>
    </item>
    <item id="job5" type="PROD">
        <attr name="BOOK" type="string" value="TEST LOCATION"/>
        <attr name="ORIGIN" type="string" value="COPY"/>
        <attr name="COMMENT" type="string" value="Insurnace Information"/>
        <attr name="DATE" type="date" value="2005-06-17"/>
        <childcomponent type="test">
            <attr name="CODE" type="string" value="375"/>
            <attr name="DESC" type="string" value="Evidence of Insurance"/>
        </childcomponent>
        <childcomponent type="test">
            <attr name="CODE" type="string" value="997105514"/>
        </childcomponent>
        <childcomponent type="test">
            <attr name="CODE" type="string" value="997105509"/>
        </childcomponent>
        <resources>
            <resource file="12532160239885.tiff"
                mime="image" type="ICMBASE"/>
        </resources>
    </item>
</root>

Answers (1)

0
Photo of Kirtan Patel
NA 35k 2.8m 15y
you need to add Name Space

using System.Text;
Accepted
0
Photo of Pankaj Singh
NA 69 0 15y
Hi,

This line not working::
message.SubjectEncoding = Encoding.UTF8;
0
Photo of Kirtan Patel
NA 35k 2.8m 15y
check "Do you like this answer"  if it helped you :)

protected
void Button1_Click(object sender, EventArgs e)
{
SmtpClient client = new SmtpClient();
MailMessage message = new MailMessage();
client.Port = 587;
client.Host = "smtp.gmail.com";
client.UseDefaultCredentials = true;
client.Credentials = new System.Net.NetworkCredential("kirtan007@gmail.com", "mygmailpassword");
client.EnableSsl = true;
try
{
MailAddress SendTo = new MailAddress("kirtan007@gmail.com");

MailAddress SendFrom = new MailAddress("Test@gmail.com");
message = new MailMessage(SendFrom, SendTo);
message.Body = "this is content Of Mail";
message.Subject = "Test Subject";
message.SubjectEncoding = Encoding.UTF8;

//Add Mail Header

message.Headers.Add("You Name", "Your Company Name");

client.Send(message);

Page.RegisterClientScriptBlock("Thanks!", "<script>alert('Thanks! for using this tool.')</script>");
}
catch
{

}
}
0
Photo of Pankaj Singh
NA 69 0 15y
Hi,

In your code there is no code to display name, when we sending mail.
0
Photo of Kirtan Patel
NA 35k 2.8m 15y
Here is Better Code to Send mail using ASp.net

 protected void btnSend_Click(object sender, EventArgs e)
{
SmtpClient client = new SmtpClient();
MailMessage message = new MailMessage();
client.Port = 587;
client.Host = "smtp.gmail.com";
client.UseDefaultCredentials = true;
client.Credentials = new System.Net.NetworkCredential(txtemail.Text ,txtpass.Text );
client.EnableSsl = true;
try
{
MailAddress SendTo = new MailAddress(txtTo.Text);
MailAddress SendFrom = new MailAddress(txtFrom.Text);
message = new MailMessage(SendFrom, SendTo);
message.Body = txtMessage.Text;
message.Subject = txtSub.Text;
client.Send(message);
txtStatus.Text = "Your email has been sent";
Page.RegisterClientScriptBlock("Thanks!", "<script>alert('Thanks! for using this tool.')</script>");
}
catch (Exception ex)
{
txtStatus.Text = ex.ToString();
}
}
}
check "Do you like this answer" if it helped you :)







0
Photo of Pankaj Singh
NA 69 0 15y
hi,

My code:

  1. try  
  2. {  
  3.     //Creating new mail message  
  4.     System.Web.Mail.MailMessage MyMail = new System.Web.Mail.MailMessage();  
  5.   
  6.     //Display Name can be sent using following format  
  7.     //\<<Friendly Display Name>>\ <mailaddress>"  
  8.     MyMail.From = @"\Webtips Emailer\ <admin@webtips.co.in>";  
  9.   
  10.     //To Address  
  11.     MyMail.To = "webtips.co.in@gmail.com";  
  12.   
  13.     // BCC Address  
  14.     MyMail.Bcc = "somename@someserver.com";  
  15.   
  16.     //Mail Subject  
  17.     MyMail.Subject = "Subject Of the mail";  
  18.   
  19.     //Body of the mail  
  20.     MyMail.Body = "<html><body>test mail message</body></html>";  
  21.     MyMail.BodyFormat = System.Web.Mail.MailFormat.Html;  
  22.       
  23.     //SMTP Server name or IP from which mail to be sent  
  24.     System.Web.Mail.SmtpMail.SmtpServer = "smtp.someserver.com";  
  25.   
  26.     //Sending Mail  
  27.     System.Web.Mail.SmtpMail.Send(MyMail);  
  28. }  
  29. catch  
  30. {  

Pankaj

0
Photo of Venkatesh Ellur
NA 39 0 15y
Hey pankaj can you please post the code so that i can try helping you out.