VMware Cloud Community
Gortee
Hot Shot
Hot Shot
Jump to solution

Escape character for a reserved word

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? 

Joseph Griffiths http://blog.jgriffiths.org @Gortees VCDX-DCV #143
Reply
0 Kudos
1 Solution

Accepted Solutions
iiliev
VMware Employee
VMware Employee
Jump to solution

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"

View solution in original post

Reply
0 Kudos
3 Replies
bluefirestorm
Champion
Champion
Jump to solution

I don't know anything about vRealize but one way to avoid element name conflicts in XML documents is to use XML namespace.

https://www.w3.org/TR/xml-names11/

https://msdn.microsoft.com/en-us/library/aa468565.aspx

Reply
0 Kudos
iiliev
VMware Employee
VMware Employee
Jump to solution

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"
Reply
0 Kudos
Gortee
Hot Shot
Hot Shot
Jump to solution

Thanks for the help!  Worked perfectly.

Joseph Griffiths http://blog.jgriffiths.org @Gortees VCDX-DCV #143
Reply
0 Kudos