如何从XML字符串中删除节点数据 [英] How to remove node data from an XML string

查看:93
本文介绍了如何从XML字符串中删除节点数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好



以下是我在.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 =


Hi all

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 =


这篇关于如何从XML字符串中删除节点数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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