问题描述
你好,
这可能很简单,但是我很困惑,我想写Xml文件
例如:
Hello,
This may be simple, but iam confused, i want to write Xml file
for eg:
<sports>
<racing>
<tournament totalrounds="5" cars="2" />
</racing>
<start>
<car name="car1" direction="Left" roundscount="3">
<round begin="100" end="1000" />
<round begin="100" end="500" />
<round begin="500" end="1500" />
</car>
<car name="car2" direction="Right" roundscount="2">
<round begin="1000" end="100">
<round begin="1500" end="500">
</round></round></car>
</start>
</sports>
在这里,Totalrounds = 5是car1的3轮和car2的2轮.
不.的汽车= 2,这些值是动态的.
我想循环运行,因为如果有例如:说100轮和10辆车.它应该相应地编写xml.
该车的回合计数应该是动态变化的,例如3车6轮意味着每辆车的回合计数= 2,即,它应为每辆车随机显示,并且还应指示方向将一辆车向左移至另一辆车再向右移,然后再向左移..
可以得到任何帮助.
Here Totalrounds=5 is 3 rounds of car1 and 2 rounds of car2.
no. of cars =2 these values are dynamic.
i want to run in a loop because if there are eg: say 100 rounds and 10 cars.it should write the xml accordingly.
Roundscount should come dynamically for that car say 3 cars 6 rounds means roundscount=2 for each car i.e, it should show randomly for each car and also direction one car left other car right again next car directio left..
any help can be appreciated.
推荐答案
- 使用
System.Xml.XmlDocument
类.它实现了DOM接口;如果文档太大,则这种方法最简单,也足够好.
请参见 [ ^ ]. - 使用类
System.Xml.XmlTextWriter
和System.Xml.XmlTextReader
;这是最快的读取方法,尤其是您需要跳过一些数据.
请参见 http://msdn.microsoft.com/en-us/library/system.xml.xmlwriter.aspx [ ^ ], [ ^ ]. - 使用类
System.Xml.Linq.XDocument
;这是类似于XmlDocument
的最适当的方法,它支持LINQ to XML编程.
请参见 [ ^ ],http://msdn.microsoft.com/en-us/library/bb387063.aspx [ ^ ].
- Use
System.Xml.XmlDocument
class. It implements DOM interface; this way is the easiest and good enough if the size if the document is not too big.
See http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx[^]. - Use the classes
System.Xml.XmlTextWriter
andSystem.Xml.XmlTextReader
; this is the fastest way of reading, especially is you need to skip some data.
See http://msdn.microsoft.com/en-us/library/system.xml.xmlwriter.aspx[^], http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx[^]. - Use the class
System.Xml.Linq.XDocument
; this is the most adequate way similar to that ofXmlDocument
, supporting LINQ to XML Programming.
See http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx[^], http://msdn.microsoft.com/en-us/library/bb387063.aspx[^].
这篇关于在WPF中使用C#编写Xml文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!