how to send text value to an xml file dynamically

Last post 07-03-2009 4:49 AM by kavita_khandhadia. 10 replies.

Sort Posts:

  • how to send text value to an xml file dynamically

    07-02-2009, 8:15 AM
    • Member
      4 point Member
    • prince23
    • Member since 06-30-2009, 5:16 PM
    • Posts 46

    <email>
            <user name>" "<user name>
            <city message>Have   successfully  changed  the  passsword"></city>
     </email>
     here the  scenario is like this  :


     user  want  to  change the password  after  user  has  changed  the password  sucessfully .  i need   to  send  an  e-mail  to the mail id he  has  given.
     i have  an  xml file  where  i have the  data "  have  successfully  change   the Password" . now  i need   to   appeneded  username as   user name  will be  changing   .i cannot  hard  cord   the    values in the  xml   file .  so  i need to  pass input  values  from a textbox  to  the  xml  file.
     
         any help  would  great

  • Re: how to send text value to an xml file dynamically

    07-02-2009, 8:38 AM

     Which .NET version do you use? With .NET 3.5 you can use LINQ to XML to manipulate XML documents, with earlier versions you can use System.Xml.XmlDocument.

    Also note that <user name> is not XML, spaces in elements names are not allowed, you either need <user-name> or <user_name>

    Martin Honnen --- MVP XML
    My blog
  • Re: how to send text value to an xml file dynamically

    07-02-2009, 9:06 AM
    • Member
      4 point Member
    • prince23
    • Member since 06-30-2009, 5:16 PM
    • Posts 46

     <user name> is not XML, spaces in elements names are not allowed

      here  i am  using  blank  space  because.   user   who  changes  his password  his  name  has  to  come.  we cannot harcode the values  and  keep. so  user  who ever  changes  this pasword  this user name  should  come  dynamically.   once  i get the  user name. i need  to pass the value s into a  xslt  file  which  converts this  into an html   format   and  send me  back    to  my  email  application where  i send  email

     hope  my question in Clear 

     

     Thank  you

  • Re: how to send text value to an xml file dynamically

    07-02-2009, 9:11 AM

    Please resturcure ur sample xml..its not at all correct.. each node has problem... see my sample xml here..

    string myXml = "<email>"+
            "<user_name>Kavita</user_name>"+
            "<city_message>has successfully  changed  the  passsword</city_message>" +
        "</email>";


            XmlDocument xDoc = new XmlDocument();
            xDoc.LoadXml(myXml);

            XmlNode xNode = xDoc.SelectSingleNode("email");
             string userName="";
             string message = "";
            foreach(XmlElement xe in xNode.ChildNodes)
            {
                if(xe.Name == "user_name")
                {
                    userName = xe.InnerText;
                }
                 if(xe.Name == "city_message")
                {
                    message = xe.InnerText;
                }
            }

            string MyMessage = userName + " " + message;

            MyLabel.text = MyMessage;



    the above method will giv eu out put as

    Kavita has successfully  changed  the  passsword


    Please mark this post as Answer if it is of help to you!

    " You can't do anything about length of life, but sure you can do about depth of life..! "
  • Re: how to send text value to an xml file dynamically

    07-02-2009, 2:09 PM
    • Member
      4 point Member
    • prince23
    • Member since 06-30-2009, 5:16 PM
    • Posts 46

     thanks  4  the  replay

    <email>

    <user_name>Kavita</user_name>

    <city_message>has successfully changed the passsword</city_message>

    </email>

     what  told  works   fine  for a    single  user

     MYQuestion  i  dnt wnat  o specify "kavitha  " anywhere

     if there  5  user  who have  login in  and  have  change  the  password 

    then this  above  concept  does  not  work as  name   will  vary for each one

     in the  xml file.  user  nam e  will not be  know  at any time 

    once  the  user  has  login in   ill be  holding the  object of   details

      obj. name="kiran" comeing  like this now  i want  to add  kiran in xml file    once  the  meassage is   sent  then dellete  kiran from  xml file

    1: <user_name></user_name>

    2: <user_name>kiran </user_name> aftre message is  sent delete  the name   from  xml file . so that any user  who  chages  this password name  again  goes there

    3: <user_name></user_name>

    but this message :<city_message>has successfully changed the passsword</city_message>can be kept contsant

  • Re: how to send text value to an xml file dynamically

    07-02-2009, 10:47 PM
    • Member
      4 point Member
    • prince23
    • Member since 06-30-2009, 5:16 PM
    • Posts 46

    have  cretaed an  xml   fine

    string myXml = "<email>"+
            "<user_name>Kavita</user_name>"+
            "<city_message>has successfully  changed  the  passsword</city_message>" +
        "</email>";

     now   i need  to send  myXml   as  now  generted as input   to   xslt  file

      so that i can  the   html  from xslt file

     thank  you

    looking forward  for   ur  help

  • Re: how to send text value to an xml file dynamically

    07-03-2009, 12:45 AM

    prince23:

     thanks  4  the  replay

    <email>

    <user_name>Kavita</user_name>

    <city_message>has successfully changed the passsword</city_message>

    </email>

     what  told  works   fine  for a    single  user

     MYQuestion  i  dnt wnat  o specify "kavitha  " anywhere

     if there  5  user  who have  login in  and  have  change  the  password 

    then this  above  concept  does  not  work as  name   will  vary for each one

     in the  xml file.  user  nam e  will not be  know  at any time

    I know that.. that why i have written for each loop see the line

    foreach(XmlElement xe in xNode.ChildNodes)
            {


    here u can add ur comparision...of the obj.Name = "kiran"

    If u are still confused provide me ur Sample xml with 5 user names and the exact our of xml after the message has been sent.

    You see that i havent hardcoded kavita anywher in my code...

    Please mark this post as Answer if it is of help to you!

    " You can't do anything about length of life, but sure you can do about depth of life..! "
  • Re: how to send text value to an xml file dynamically

    07-03-2009, 2:10 AM
    • Member
      4 point Member
    • prince23
    • Member since 06-30-2009, 5:16 PM
    • Posts 46

    hi kavita 

    string myXml   = "<email>"+
    "<user_name>Kavita</user_name>"+
    "<city_message>has successfully changed the passsword</city_message>" +
    "</email>"; 

     this is   my code  in  .cs  which    contains  data  in  xml  format right  so that  i can   send  this  string  "myxml"   as  input  to xslt  file  which  converts into    html  .and  give  the  result  . 

     

    XPathDocument doc = new XPathDocument(Server.MapPath("XMLFile1.xml"));// know  i   dnt reqiure have  an  XMLFile1.xml 

    because  my  string    "myXml" is  already having the data. so if  there is  any  way i  can send  this data  to  xslt  file .

     i am new   to .net    so finding tough  for  the   syntax . if  any one  can even  get the  code  how  to  write things in xslt  file  would  great

     

     

     

  • Re: how to send text value to an xml file dynamically

    07-03-2009, 2:28 AM
    Answer

    prince23:


    because  my  string    "myXml" is  already having the data. so if  there is  any  way i  can send  this data  to  xslt  file .


    Yes u can do that.. see this code

    XslTransform xslt = new XslTransform();
            xslt.Load("file:///D:/Kavita/SortXml/sort.xslt");
    //here sort.xslt shuid be the name of ur xslt file..please update the path also.
            XPathDocument xpath = new XPathDocument("D:\\Kavita\\SortXml\\unSortXml.xml");
    //here unSortXml is ur input XML.
            Stream Streamdata = new FileStream(MapPath("Out.xml"), FileMode.Create, FileAccess.ReadWrite);
            xslt.Transform(xpath, null, Streamdata, null);



    here u apply xslt on ur xml. Mark as answer if the post helped u :)


    Please mark this post as Answer if it is of help to you!

    " You can't do anything about length of life, but sure you can do about depth of life..! "
  • Re: how to send text value to an xml file dynamically

    07-03-2009, 4:18 AM
    Answer
    • Member
      4 point Member
    • prince23
    • Member since 06-30-2009, 5:16 PM
    • Posts 46

    hi kavita.

    thanks   for ur  help 

     thsi is  my code  that  runs  now

    string s1= TextBox1.Text;

    string myXml = "<email>"+

    "<user_name>"

    +s1+"</user_name>"+

    "<city_message>has successfully changed the passsword</city_message>"

    +

    "</email>"

    ;

    string  body = TranformXML(myXml);

    private static string TranformXML(string xmlFile)

    {

    StringBuilder resultString = new StringBuilder();

    string FilePath = HttpContext.Current.Server.MapPath("XSLTFile2.xslt");

    MemoryStream m = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(xmlFile));

    XPathDocument xpathDoc = new XPathDocument(new StreamReader(m));

    //Create the new transform object

    XslCompiledTransform transform = new XslCompiledTransform();

    //String to store the resulting transformed XML (Excel file)

    XmlWriter writer = XmlWriter.Create(resultString);

    transform.Load(FilePath); //Loading XSLT file.

    transform.Transform(xpathDoc, writer); //Transforming the XML file

    return resultString.ToString();

    }

     

     my  xslt  file

    <?

    xml version="1.0" encoding="UTF-8"

    ?>

    <

    xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

    >

    <

    xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"

    />

    <

    xsl:template match="/"

    >

    <

    html

    >

    <

    head

    />

    <

    body bgcolor ="green"

    >

    <

    h1>Password Changed</h1

    >

    <

    xsl:apply-templates

    />

    </

    body

    >

    </

    html

    >

    </

    xsl:template

    >

    <

    xsl:template match="user_name"

    >

    <

    tr

    >

    <

    td

    >

    User Name :

    <xsl:value-of select="@user_name"

    />

    </

    td

    >

    </

    tr

    >

    <

    xsl:apply-templates

    />

    </

    xsl:template

    >

    <

    xsl:template match="city_message"

    >

    <

    tr

    >

    <

    td

    >

    Message :

    <xsl:value-of select="@city_message"

    />

    </

    td

    >

    </

    tr

    >

    <

    xsl:apply-templates

    />

    </

    xsl:template

    >

    </

    xsl:stylesheet

    >

    this is  my code  that  runs  fine 

      thank  you

  • Re: how to send text value to an xml file dynamically

    07-03-2009, 4:49 AM

    Yeah ur code looks good.. dont forget to mark as answer to all the threads that was helpful to u.


    Please mark this post as Answer if it is of help to you!

    " You can't do anything about length of life, but sure you can do about depth of life..! "
Page 1 of 1 (11 items)