TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
chetan Allipur
NA
541
167k
How to get both Elements and Attributes to create XML File
Mar 20 2017 8:07 AM
Here is my code. Here i am getting only Elements. I want Attribute value also. Please anyone Help me.
private void Button_Click_1(object sender, RoutedEventArgs e)
{
try
{
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.NewLineOnAttributes = true;
XDocument Xdoc = new XDocument(new XElement("Users"));
if (System.IO.File.Exists(@"D:\Example.xml"))
Xdoc = XDocument.Load(@"D:\Example.xml");
else
{
Xdoc = new XDocument();
XElement xmlstart = new XElement("Users");
Xdoc.Add(xmlstart);
}
XElement xml = /*new XElement("Users",*/
new XElement("Person",
new XElement("Name", txtNames.Text)),
new XElement("Age", txtAge.Text),
new XElement("Address", txtAddress.Text));
if (Xdoc.Descendants().Count() > 0)
Xdoc.Descendants().First().Add(xml);
else
Xdoc.Add(xml);
Xdoc.Save(@"D:\Example.xml");
MessageBox.Show("Saved to XML File");
txtNames.Text = "";
txtAge.Text = "";
txtAddress.Text = "";
}
catch (Exception)
{
throw;
}
}
Reply
Answers (
1
)
How to create the XML file from the textboxs.
How to connect datagrid with database .