\
<WindowsSdkPackageVersion>10.0.19041.38</WindowsSdkPackageVersion>
private void button1_Click(object sender, EventArgs e) {
System.Xml.XmlWriter w = System.Xml.XmlWriter.Create(@"c:\\temp\\booklist.xml");
w.WriteStartElement("booklist");
w.WriteAttributeString("count", "5");
for (int i = 1; i <= 5; i++) {
w.WriteStartElement("book");
w.WriteAttributeString("isbn", (i * 10).ToString());
w.WriteElementString("title", "book name " + i.ToString());
w.WriteStartElement("price");
w.WriteAttributeString("unit", "NTD");
w.WriteString((i+500).ToString());
w.WriteEndElement();
w.WriteEndElement();
}
w.WriteEndElement();
w.Close();
}
// using System.Xml;
private void button2_Click(object sender, EventArgs e) {
XmlDocument doc = new XmlDocument();
doc.Load(@"c:\\temp\\booklist.xml");
(sender as Button).Text = "OK";
}
private void button2_Click(object sender, EventArgs e)
{
XmlDocument doc = new XmlDocument();
string x = textBox2.Text;
doc.Load(@"c:\\\\temp\\\\booklist.xml");
XmlNode title = doc.SelectSingleNode($"/booklist/book[{x}]/title");
if (title == null)
{
(sender as Button).Text = "not found";
return;
}
textBox1.Text += title.InnerText + "\\\\r\\\\n";
(sender as Button).Text = "OK";
}
整理HTML的相關網站(HTML TIDY)