ART#202 - How to layer (repository) XML files in ATG ?



Layering XMLs is the core of creating and extending ATG repositories. As discussed in previous articles, repository XMLs consist of all the item-descriptor properties and their corresponding mapping to table's columns.. 
A point to be noted again is that these XMLs can be placed anywhere in your config-path, just like the configuration files.
Just like configuration files of the same name and config-path-location, can be layered by a configuration file in another module, XML files work the same way. These files are layered and a composite single XML file is created at runtime.

Suppose, you have two XML files of same name, layered in different modules at same location, the files are combined using "xml-combine=<value>" attribute. This attribute can be applied to any XML tag.

xml-combine="append"
Matches the tags and appends them.
See below example:- 



The first XML defines a tag automobiles, which has a vehicle with name "skoda".
This vehicles tag has has "features" in which each "feature" with an attirbute (like seats, airbags etc.) is defined.
Now, consider the left one as OOTB XML, here they have 2 features for vehicle "skoda", viz. seats and airbags.
Let us consider the 2nd XML as our layered one, where we replicate the whole tag structure, and want to "append" a new "feature" to the OOTB xml.

Now, ATG check our layered XML (2nd one), and matches it with OOTB xml, it finds the "vehicle" tag with name "skoda". Please note that the "matching" of tags is done by ATG on the basis of "name" attribute. Be sure to have a name attribute in almost every tag you use.
So, it matches the "name" tag and checks the tags within it.
Inside vehicle "skoda", the "features" tag has "xml-combine" attribute marked as "append". Now, it appends all the tags within "features" tag (in a nested manner).

Therefore, the resulting XML tag has 3 features as you can see in the last XML (or combined XML).
NOTE: Please note that, even if you DO NOT specify the "xml-combine"attribute for a tag, ATG considers it "xml-combine="append" by default.


xml-combine="replace"
Matches the tags and replaces it.
See below example:-


Here, again the tags are matched by name. 
vehicle "skoda" had two OOTB features viz. seats and airbags.
Now, we want to remove these two features and add our own feature "seatbelts". 
Therefore, we use "xml-combine=replace" attribute in our "features" tag, so that all the previous tags within the "features" tag are removed and are new one is added.
(See the resulting XML)



xml-combine="remove"
Now this one is pretty dangerous..!
It matches the tag and removes it.
See below example:-



Here, the matching tag with "name" is found and the tag, along ith its innter (nested) tags get removed from the resulting xml.

xml-combine="prepend"
This mode is similar "xml-combine=append". The only difference is that, the tags in the 2nd XML (the layered one), appear first and ones in the 1st XML (which we considered OOTB) appear next.

This would surely get you going, but if you are looking for some more info, you can have a look HERE.

Now before we hop on to customizing and creating repositories, we must understand what type of repositories are present and how do they function.

Back



Next







1 comment:

Subscribe

Get All The Latest Updates Delivered Straight Into Your Inbox For Free!

Flickr