I am using a scriptable task to create some XML and running into an issue where an element is a reserved word (interface).
For example
var interfaceXml = new XML('<interfaces><interface><name></name><addressGroups><addressGroup><primaryAddress></primaryAddress><subnetMask></subnetMask></addressGroup></addressGroups><mtu></mtu><type></type><isConnected></isConnected><connectedToId></connectedToId></interface></interfaces>');
interfaceXml.interfaces[0].interface[0].name="GW-172.16.120.1";
How do I escape the interface word?
Hi Gortee,
Here is the correct syntax:
interfaceXml["interface"][0].name = "GW-172.16.120.1";
Also note that the root XML tag (<interfaces>) is not used in the expression.
BTW, for this particular XML content, where there is a single child node <interface> of the root node <interfaces>, you can omit the array index [0] from the expression, so the following expression will also work:
interfaceXml["interface"].name = "GW-172.16.120.1";
I don't know anything about vRealize but one way to avoid element name conflicts in XML documents is to use XML namespace.
Hi Gortee,
Here is the correct syntax:
interfaceXml["interface"][0].name = "GW-172.16.120.1";
Also note that the root XML tag (<interfaces>) is not used in the expression.
BTW, for this particular XML content, where there is a single child node <interface> of the root node <interfaces>, you can omit the array index [0] from the expression, so the following expression will also work:
interfaceXml["interface"].name = "GW-172.16.120.1";
Thanks for the help! Worked perfectly.