我对一些 XML 文件有疑问。
我有大约 500 多个文本文件,我从中读取并提取数据并将其导出为 XML。但是,生成的 XML 被中途截断。
<Maps>
<Location>
</Location>
<Locat
它有点像这样截断。当我尝试在记事本中打开它时,它似乎用完了记事本的整个页面。可能是由于内存问题,因为我有大量数据。是否有任何解决方法。我在虚拟机上运行程序
private XmlTextWriter writer = new XmlTextWriter("Maps.xml", System.Text.Encoding.UTF8);
static void Main(string[] args)
{
Program prog = new Program();
String[] filenames = Directory.GetFiles(@"maps_new");
prog.writer.WriteStartDocument();
prog.writer.WriteStartElement("Maps");
foreach (String file in filenames)
{
prog.extractToXML(file);
}
prog.writer.WriteEndElement();
prog.writer.WriteEndDocument();
}
public void extractToXML(String filename)
{
XPathNodeIterator NodeIter;
XPathDocument xmldoc = new XPathDocument(filename);
XPathNavigator nav = xmldoc.CreateNavigator();
String query = "//Schema/@tree";
NodeIter = nav.Select(query);
writer.WriteStartElement("file");
writer.WriteStartAttribute("name");
writer.WriteString(extractFileName(filename));
writer.WriteEndAttribute();
while (NodeIter.MoveNext())
{
writer.WriteStartElement("type");
writer.WriteString(extractFileName(NodeIter.Current.Value.ToString()));
writer.WriteEndElement();
}
NodeIter = nav.Select("//Location");
while (NodeIter.MoveNext())
{
writer.WriteStartElement("Location");
writer.WriteString(NodeIter.Current.Value.ToString());
writer.WriteEndElement();
}
writer.WriteEndElement();
}