XML数据直线排列 [英] XML Data Comes in straight line
本文介绍了XML数据直线排列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
WebServiceOutput wso = new WebServiceOutput();
BinaryWriter binWriter = new BinaryWriter(File.Open(@C:\ DAF\config\xyz.xml,FileMode.Create, FileAccess.Write));
binWriter.Write(HierarchyFileContent);
binWriter.Close();
让我知道,当我尝试使用FileMode.Create创建新的xml文件时。文件将保存在一行中,而不是相应的。
WebServiceOutput wso = new WebServiceOutput();
BinaryWriter binWriter = new BinaryWriter(File.Open(@"C:\DAF\config\xyz.xml", FileMode.Create, FileAccess.Write));
binWriter.Write(HierarchyFileContent);
binWriter.Close();
Let me know, When i am trying to create new xml file using "FileMode.Create". File will be saved in a single line not in appropriate from.
推荐答案
您可以通过将其加载到XDocument中来实现格式正确的XML字符串。
然后只需在其上调用ToString
:
You can achieve the properly formatted XML string by loading it into anXDocument
and then just callingToString
on it:
WebServiceOutput wso = new WebServiceOutput();
BinaryWriter binWriter = new BinaryWriter(File.Open(@"C:\DAF\config\xyz.xml", FileMode.Create, FileAccess.Write));
// Prettify (indent) 'HierarchyFileContent' content.
binWriter.Write(XDocument.Parse(HierarchyFileContent).ToString());
binWriter.Close();
这篇关于XML数据直线排列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文