需要使用Powershell生成给定格式的XML层次结构 [英] need to generate XML hierarchy using powershell for the given format

查看:93
本文介绍了需要使用Powershell生成给定格式的XML层次结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是需要在XML中创建的层次结构
示例:
MyFile-

here is the hierarchy that need to create in XML
Example:
MyFile-

<Meta>
 <Image>
   <PNG>
       <URL>
   <PNG>
       <URL>
   <PNG>
       <URL>
   <PNG>
       <URL>
   <PNG>
       <URL>



我当前的实现:



my current implementation:

[xml] $file = Get-content C:\MyFile.xml
$Parent =$file.Meta
$Child = $file.CreateElement("Image",$Parent.NamespaceURI)
$Parent.AppendChild($Child)
$file.Save("C:\MyFile.xml")

for($j=0; $j -lt 10; $j++){
	$ParentNode =$file.Meta["Image"]
	$ChildNode = $file.CreateElement("PNG",$Parent.NamespaceURI)
	$ParentNode.AppendChild($ChildNode)
	$file.Save("C:\MyFile.xml")
   
	$ParentSubNode =$file.Meta.Image["PNG"]
	$SubChildNode = $metafile.CreateElement("URL",$ParentNode.NamespaceURI)
	$ParentSubNode.AppendChild($SubChildNode)
	$file.Save("C:\MyFile.xml")
    }




上面的代码将xml创建为;




The above code is crating the xml as;

<Meta>
 <Image>
   <PNG>
       <URL>
       <URL>
       <URL>
       <URL>
   <PNG>
   <PNG>
   <PNG>



*节点名称不应带有后缀0,1,2..etc



*the node names should not be changed with suffix 0,1,2..etc

Can some one pls help me to solve this issue?

推荐答案

file =获取内容C:\ MyFile.xml
file = Get-content C:\MyFile.xml


父=


文件.元


这篇关于需要使用Powershell生成给定格式的XML层次结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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