I have this XML-file with this structure:
<?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>
I want to add a line to company -> category -> category1 "Office2" -> category2 "Project2"
The line is:
<category3 name="Test4"/>
I've tried this:
$Path = "C:file.xml"
$xml = [xml](get-content $Path)
$xml.Load($Path)
$test = $xml.company.category
$test.category1 *what to do here*
I know how to do this with one sub-element, and how to clone and add. But I don't know where to start with this one.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…