XML数据直线排列 [英] XML Data Comes in straight line

查看:105
本文介绍了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 an XDocument and then just calling ToString 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆