我有这个结构的xml文件:
<?xml version="1.0" encoding="utf-8"?>
<company>
<category>
<category1 name="Office1">
<category2 name="Project1">
<category3 name="Test1"/>
<category3 name="Test2"/>
</category2>
<category2 name="Project2">
<category3 name="Test1"/>
<category3 name="Test2"/>
<category3 name="Test3"/>
</category2>
</category1>
<category1 name="Office2">
<category2 name="Project1">
<category3 name="Test1"/>
<category3 name="Test2"/>
</category2>
<category2 name="Project2">
<category3 name="Test1"/>
<category3 name="Test2"/>
<category3 name="Test3"/>
</category2>
</category1>
</category>
</company>
Run Code Online (Sandbox Code Playgroud)
我想为公司添加一行 - >类别 - > category1"Office2" - > category2"Project2"该行是:
<category3 name="Test4"/>
Run Code Online (Sandbox Code Playgroud)
我试过这个:
$Path = "C:\file.xml"
$xml = [xml](get-content $Path)
$xml.Load($Path)
$test = $xml.company.category
$test.category1 *what to do here*
Run Code Online (Sandbox Code Playgroud)
我知道如何使用一个子元素,以及如何克隆和添加.但我不知道从哪里开始.