如何从XML字符串中删除节点数据 [英] How to remove node data from an XML string
问题描述
大家好 Hi all 这篇关于如何从XML字符串中删除节点数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
以下是我在.xml文件中的xml
< pre lang =HTML> < pre > <? xml version = 1.0 encoding = UTF-8 ?>
< data >
< 输入 >
< common >
< AOGatewayID > < / AOGatewayID >
< SRNUM > < / SRNUM >
< WONUM > < / WONUM > ;
< INCNUM / >
< ; ResolverGroup > < / ResolverGroup >
< ContactEmail > < / ContactEmail >
< / common >
< params > 跨度>:二零一六年十一月三十○日;:;:;:;:;:;:;:;:;:;:;:;:;:;:;:;:;:;:;:;:;: ;:;:;:; RequestedFor:NEX9KUT < / params >
< / input > 跨度>
< 进程名称 > < / Processname >
< retry-count > < / retry-count >
< status > < / status >
< Error_Desc > < / Error_Desc >
< / data >
我需要删除< params>标记并将新的xml保存在单独的文件中
请帮助我。
我尝试过:
[Xml] $ xml =获取内容D:\ Logs\File.xml
$ parent_xpath ='/ data / input'
$ nodes = $ xml.SelectNodes($ parent_xpath)
$ nodes | %{
$ child_node = $ _。SelectSingleNode('params')
$ _。RemoveChild($ child_node)| Out-Null
} xml = Get-ContentD:\ Logs \File.xml
parent_xpath ='/ data / input'
nodes =
Below is the xml i am having in a .xml file
<pre><?xml version="1.0" encoding="UTF-8"?>
<data>
<input>
<common>
<AOGatewayID></AOGatewayID>
<SRNUM></SRNUM>
<WONUM></WONUM>
<INCNUM />
<ResolverGroup></ResolverGroup>
<ContactEmail></ContactEmail>
</common>
<params>:11/30/2016;:;:;:;:;:;:;:;:;:;:;:;:;:;:;:;:;:;:;:;:;:;:;:;:;RequestedFor:NEX9KUT</params>
</input>
<Processname></Processname>
<retry-count></retry-count>
<status></status>
<Error_Desc></Error_Desc>
</data>
I need to delete the <params> tag and save the new xml in separate file
Please help me on this.
What I have tried:
[Xml]$xml = Get-Content "D:\Logs\File.xml"
$parent_xpath = '/data/input'
$nodes = $xml.SelectNodes($parent_xpath)
$nodes | % {
$child_node = $_.SelectSingleNode('params')
$_.RemoveChild($child_node) | Out-Null
}xml = Get-Content "D:\Logs\File.xml"
parent_xpath = '/data/input'
nodes =