Nội dung profile.xml:Powershell XML importnode từ tập tin khác nhau
<files>
<file folder="CaptureServer" filename="CSConfig" object="CSConfig">
<Profile name="BBH1200Kofax">
<OutputCache>\</OutputCache>
<EncryptedConnectionString>564rgr=</EncryptedConnectionString>
<ConvertDocsBeforeRelease>false</ConvertDocsBeforeRelease>
</Profile>
</file>
<file folder="CaptureServices3" filename="CSConfig" object="CSConfig">
<Profile name="BBH1200Kofax">
<ReleaseToEnterprise>true</ReleaseToEnterprise>
<CaptureServerUrl />
<OutputCache />
<Credentials>
<EncryptedPassword>46s4rg=</EncryptedPassword>
<UserName />
<Domain />
</Credentials>
<ConvertDocsBeforeRelease>false</ConvertDocsBeforeRelease>
</Profile>
</file>
</files>
Nội dung rules.xml:
<file folder="" filename="Rules" object="ArrayOfIBarcodeRule">
<Profile name="Test471">
<IBarcodeRule>
<RuleName>DOC-TESTTESTTEST-Code128</RuleName>
<FieldSequenceNumber>1</FieldSequenceNumber>
<FieldRectangle>
<Location>
<X>0</X>
<Y>0</Y>
</Location>
<Size>
<Width>0</Width>
<Height>0</Height>
</Size>
</FieldRectangle>
<SeparationValue>TESTTESTTEST</SeparationValue>
</IBarcodeRule>
</Profile>
</file>
Tôi cố gắng để thêm toàn bộ nội dung của rules.xml (file node) như một nút khác trong tệp tin profile.xml. Như bạn có thể thấy, có một loạt các nút tập tin khác trong tệp tin cấu hình, và tệp rules.xml sẽ là một nút khác.
Đây là mã tôi đã cố gắng, và nó dường như không làm bất cứ điều gì:
$xml = [xml](Get-Content ".\profile.xml")
$newxml = [xml](Get-Content ".\rules.xml")
$xml.ImportNode($newxml.get_DocumentElement(), $true)
$xml.Save(".\profile.xml")
Hoạt động hoàn hảo, cảm ơn bạn! – SeanM