0

I read for hours trying to figure this out, but I'm new to XML.

I am trying to add the following:

<componentInfo osType="Windows" consumeLicense="1" clientSidePackage="1" ComponentName="File System" ComponentId="702"/>

I am trying to add this in <components>

This is what I have before the componenets tag:

-<CVInstallManager_ClientSetup Operationtype="0" OEMID="1" JobID="0" Focus="Instance001">-<CommServeInfo><CommserveHostInfo hostName="$Var2"/></CommServeInfo>-<clientComposition packageDeliveryOption="0" activateClient="1">-<clientInfo>-<client installDirectory="" evmgrcPort="8402" cvdPort="8400"><clientEntity hostName="$VAr1" clientName="$Var3"/><jobResulsDir path=""/></client><clientGroups clientGroupName=""/><clientProps enableAccessControl="0"/></clientInfo>

I've got the XML loaded like the following:

$InstallXML = [xml] (Get-Content "C:\somedir\dir\InstallXMLTest.xml")

I understand I need to browse to the tag, similar to:

$InstallXML.CVInstallManager_ClientSetup.CommServeInfo.CommserveHostInfo.hostName = $args[1]

But I have no idea how I add, not replace data. Please save me!

4
  • I have no idea whats going on in that thread.. I need to add attributes to an element that is already present, That thread looks like an in - depth discussion. I'm looking for explanation really, Commented Dec 15, 2015 at 9:16
  • Hi Mike, does the example in the first answer of this question help you ? stackoverflow.com/q/3041489/3677139 Commented Dec 15, 2015 at 10:04
  • The accepted answer shows (rather simple and straightforward) how to add an attribute to a node and how to append that node to another node. It contains everything you need for solving your problem. Other answers can be found by searching this site. Please do some legwork yourself. We're not here for spoon-feeding you a solution. Commented Dec 15, 2015 at 11:42
  • I've figured it out.. stackoverflow.com/questions/3041489/… Basically you create the element and assign attributes, you then move that to what ever tag/element you want to. This is what threw me off. By no means do I want to be spoon fed, but I've been trying this for several days and not made much progress. I used the following to do what I want: code $b = $InstallXML.CreateElement("componentInfo") $b.SetAttribute('ComponentId', '705') $InstallXML.CVInstallManager_ClientSetup.clientComposition.components.AppendChild($b) code Commented Dec 15, 2015 at 14:28

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.