XML paths in 4D-Exchange
with the complexity of EWS item structures it is necessary to be able to easily access any element in the items DOM.
Sadly the tools provided be 4D are limited, for example it is not possible to easily access a specific instance of an element with multiple occurrences if this specific element is identified by a key attribute.
Imagine this structure:
<t:EmailAddresses>
<t:Entry Key="EmailAddress1">fflintstone@flintsunited.com</t:Entry>
<t:Entry Key="EmailAddress2">fred@rubble.com</t:Entry>
<t:Entry Key="EmailAddress3">theflintstones@boulder.com</t:Entry>
</t:EmailAddresses>
in order to address the element with the key EmailAddress3 you will have to loop through all entries in order to verify an compare the key attributes.
We can do that quite faster by using the following syntax when getting or setting the value through one of the EWS_ItemSet commands:
Error:=EWS_ItemSetValue($tx_ItemRef;"EmailAddresses/Entry|Key|EmailAddress3";"familyflintstones@boulder.com"
as you can see we embed the attribute name and value right into the path of the element. As in EWS items most indexing attributes are called Key you can even omit the attribute name in these cases, further reducing it to
Error:=EWS_ItemSetValue($tx_ItemRef;"EmailAddresses/Entry|EmailAddress3";"familyflintstones@boulder.com"
actually you can reduce it even further for indexed fields, as you can omit the Entry element, thus reducing it further to:
Error:=EWS_ItemSetValue($tx_ItemRef;"EmailAddresses|EmailAddress3";"familyflintstones@boulder.com"
So the nomenclature rule here for the path node is
ElementName{{|AttributeName#'Key'}|AttributeValue}
ok, this example is still quite simple, what about this one
<t:PhysicalAddresses>
<t:Entry Key="Business">
<t:Street>Granite Alley 13</t:Street>
<t:City>Pebble Village</t:City>
<t:State/>
<t:CountryOrRegion>Stoneland</t:CountryOrRegion>
<t:PostalCode>65432</t:PostalCode>
</t:Entry>
<t:Entry Key="Home">
<t:Street>Glacier Road 1</t:Street>
<t:City>Rubbleville</t:City>
<t:State/>
<t:CountryOrRegion>Stoneland</t:CountryOrRegion>
<t:PostalCode>65457</t:PostalCode>
</t:Entry>
</t:PhysicalAddresses>
in order to access the street of the home address you can now write as follows:
$t_Street:=EWS_ItemGetValueText($tx_ItemRef;"PhysicalAddresses|Home/Street")
This nomenclature can be used by any of the components commands that takes an XML path (or field name) as a parameter