Gortee
Hot Shot
Hot Shot

Escape character for a reserved word

Jump to solution

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
0 Kudos
1 Solution

Accepted Solutions
iiliev
VMware Employee
VMware Employee

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

0 Kudos
3 Replies
bluefirestorm
Virtuoso
Virtuoso

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

0 Kudos
iiliev
VMware Employee
VMware Employee

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

0 Kudos
Gortee
Hot Shot
Hot Shot

Thanks for the help!  Worked perfectly.

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