0

I have a web form that contains a username, password and an address (textboxes). My intention is, when I click on the insert-button, to convert that to XML.

Can you help me?

2 Answers 2

2

If you already have some object model you could use a XmlSerializer to directly serialize it to XML or XDocument if you want to generate the XML manually.

Sign up to request clarification or add additional context in comments.

Comments

1
    /// <summary>
    /// Returns an xml containing a user formatted like
    ///  <user username="..." password="..." address="..."></user>
    /// </summary>
    /// <param name="username"></param>
    /// <param name="password"></param>
    /// <param name="address"></param>
    /// <returns></returns>
    public string ConvertUserToXml(string  username, string password, string address)
    {
        var xdoc = new XDocument();
        var user = new XElement("user");
        user.Add(new XAttribute("username", username));
        user.Add(new XAttribute("password", password));
        user.Add(new XAttribute("address", address));
        xdoc.Add(user);
        return xdoc.ToString();
    }

If you want to get just the wrapped user (not an entire xml document), return user.ToString() instead (but note that it will not be a valid xml document in itself).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.