打开/保存XML而节点的属性之间preserving换行符 [英] opening/saving xml while preserving newline between node's attributes

查看:196
本文介绍了打开/保存XML而节点的属性之间preserving换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我到目前为止有:

$XML = New-Object System.Xml.XmlDocument
$XML.PreserveWhitespace = $true
$XML.Load($path)
#change some node attributes
$XML.Save($path)

如果我需要打开一个XML文件,并采取这样一个片段:

If I take open an XML file, and take a snippet like this:

<Node 
Name="tyjytj" 
Number="rthjr" 
Source="rjyrtjrjrtj" 
BinaryDrive="teheherhehtr" />

这将节省这样的:

It will save it like this:

<Node Name="tyjytj" Number="rthjr" Source="rjyrtjrjrtj" BinaryDrive="teheherhehtr" />

不过,我希望能够改变(例如)节点的名称,同时保持各属性之间的换行。我想要的格式,以保持完全究竟是怎么回事之前,我打开/保存它。

But I want to be able to change (for example) the Name of the Node, while keeping newlines between each attribute. I want the format to remain exactly how it was before I open/saved it.

推荐答案

在世界上没有任何XML解析器会告诉你是否在开始标记的属性由空格,换行,或制表符分隔。你不应该去关心。

No XML parser in the world is going to tell you whether the attributes in a start tag are separated by spaces, newlines, or tabs. You aren't supposed to care.

这篇关于打开/保存XML而节点的属性之间preserving换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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