CÁC GIẢI PHÁP LẬP TRÌNH C# - Trang 177

177

Chương 5: XML

w.WriteEndElement();

// Kết thúc tài liệu.

w.WriteEndElement();

w.WriteEndDocument();

w.Flush();

fs.Close();

Console.WriteLine("Document created. " +

"Press Enter to read the document.");

Console.ReadLine();

fs = new FileStream("products.xml", FileMode.Open);

XmlTextReader r = new XmlTextReader(fs);

// Đọc tất cả các nút.

while (r.Read()) {

if (r.NodeType == XmlNodeType.Element) {

Console.WriteLine();

Console.WriteLine("<" + r.Name + ">");

if (r.HasAttributes) {

for (int i = 0; i < r.AttributeCount; i++) {

Console.WriteLine("\tATTRIBUTE: " +

r.GetAttribute(i));

}

}

}

else if (r.NodeType == XmlNodeType.Text) {

Console.WriteLine("\tVALUE: " + r.Value);

}

}

Console.ReadLine();

}

Liên Kết Chia Sẽ

** Đây là liên kết chia sẻ bới cộng đồng người dùng, chúng tôi không chịu trách nhiệm gì về nội dung của các thông tin này. Nếu có liên kết nào không phù hợp xin hãy báo cho admin.