using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml; struct goodatribute { public string goodname; public int goodID; public int price; public override string ToString() { return "goodname:" + goodname + " goodID:" + goodID + " goodprice:"+price; } } class MyApp { static void Main() { List<goodatribute> good = new List<goodatribute>(); goodatribute TV = new goodatribute(); TV.goodname = "LG"; TV.goodID = 10; TV.price = 100; goodatribute car = new goodatribute(); car.goodname = "Ferrari"; car.goodID = 12; car.price = 100000; good.Add(TV); good.Add(car); XmlTextWriter writer = null; writer = new XmlTextWriter("orders.xml", System.Text.Encoding.Unicode); writer.Formatting = Formatting.Indented;</code> <code>writer.WriteStartDocument(); writer.WriteStartElement("orders"); for (int i = 0; i < 2; ++i) { writer.WriteStartElement("order" + Convert.ToString(i + 1)); writer.WriteStartElement("Name"); writer.WriteElementString("Name", good[i].goodname); writer.WriteEndElement(); writer.WriteStartElement("ID"); writer.WriteElementString("ID", Convert.ToString(good[i].goodID)); writer.WriteEndElement(); writer.WriteStartElement("Price"); writer.WriteElementString("Good price", Convert.ToString(good[i].price)); writer.WriteEndElement(); writer.WriteEndElement(); } writer.WriteEndDocument(); writer.Close(); XmlDocument doc = new XmlDocument(); doc.Load("orders.xml");**//the problems start from here** for (int i = 0; i < 2; ++i) { XmlNodeList nodes = doc.GetElementsByTagName("order" + Convert.ToString(i+1)); Console.WriteLine(nodes[i]["Name"].InnerText); Console.WriteLine(nodes[i]["ID"].InnerText); Console.WriteLine(nodes[i]["Price"].InnerText); } } } error opening XML file, exeption description:
Message=Знак "0", шестнадцатеричное значение 0x30, не может стоять в начале имени., строка 3, позиция 10. May be the problem in nodes name? The XML file created but cant be opening and showing on screen. the code get crush on this line: doc.Load("orders.xml");
What did i done wrong? can you help me to fix it?
No comments:
Post a Comment