XML Attributes
You will notice that there are no attributes in the sample XML. That is the preferred style, in fact, it was the required style until 3.0.005.05 (late December 2015). At that point, attributes could be provided on structure tags (not on leaf tags). Those attributes would automatically be transformed into additional leaf tags for the given structural element. For example:
<DetailLine Description="Construction Paper 50/Pack"> <Quantity>3</Quantity> <Item>CP106</Item> <UnitPrice>2.00</UnitPrice> <Amount>6.00</Amount> </DetailLine>
would become (behind the scenes)
<DetailLine> <Description>Construction Paper 50/Pack</Description> <Quantity>3</Quantity> <Item>CP106</Item> <UnitPrice>2.00</UnitPrice> <Amount>6.00</Amount> </DetailLine>
No filter specification is required. That operation is automatic. To avoid the automatic transformation of attributes to leaf data elements you can use the -ConvertAttributes No command-line option.
Note that putting attributes on leaf nodes (nodes with data, and no child nodes) will not work. For example, the following is not allowed. It will not work.
<Item Desc="Paper">CP106</Item> !!Wrong
Besides writing filters, there is an even easier way to get at attributes, even those on leaf nodes. Contrary to what you would think, this requires that you override the standard-setting and specify -ConvertAttributes No. In that way, you've told Merge not to do its standard thing w.r.t. attributes but to let you handle it.
There is an attribute() function on each data DOM node. The _data
DOM node for any given field is most easily referenced via the field's _dataSource property. Hence a construct in the pattern _field.dataSource.attribute("attrName{_}")
will get the value of the named attribute, or "" if the attribute does not exist. Do beware of the possibility that _dataSouce
may return null if there is no _data
node associated with a given field.