将新子项附加到特定节点

时间:2016-02-02 09:22:30

标签: xml powershell

如何使用PowerShell更新XML文件,之前选择正确的节点?

到目前为止我已经尝试过了:

<component>

我想将一个子项添加到节点<component>。有多个$(document).ready(function () { $('form').validate({ ignore: '.ignore', rules: { //tenant 'firstName': { required: true, minlength: 2 }, 'lastName': { required: true, minlength: 2}, 'email': { required: true, email: true }, 'phone': { required: true, digits: true}, 'password': { required: true, minlength: 5 }, //apartment 'intercom': { required: true,digits: true, minlength: 4, maxlength: 4}, 'apartmentNumber': { required: true, digits: true}, 'description': { required: true }, //meters 'description': { required: true}, 'serialNumber': { required: true}, 'unit': { required: true }, 'apartment': { required: true }, //invoice 'serialNumber': { required: true}, 'totalAmount': { required: true, number: true} 节点,所以我需要通过名称预先选择正确的节点。

1 个答案:

答案 0 :(得分:3)

您已经拥有选择预期父节点并创建新子节点的代码。您只需将新子项附加到父级。

$parent = $XML.selectSingleNode("//ns:component[@name='Microsoft-Windows-Shell-Setup']", $NSMGR)

$NEWCHILD = $XML.CreateElement("TESTELEMENT")
$NEWCHILD.set_innerXML("TESTTEXT")
$parent.AppendChild($NEWCHILD)