Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Web CMS (TeamSite)
Attach files by reading fields in a DCR
enthusiast
I am working on a mechanism to attach files mentioned in various fields of a given DCR to the workflow task. I am successful to do so as long as the fields are on root level using a hash for each DCT as the key and all corresponding fields as the values. Incase of 1 and 2 level of replicants, I am having hard time in accessing the fields. Any idea of how to extract that information using any of the teamsite dcr parsing module. Note that the DCR is in iwov format on Teamsite 6.5.
thanks,
Find more posts tagged with
Comments
nipper
post a sample DCR and your perl code. This is pretty easy
Andy
Migrateduser
Yeah, I've had to do this a few times recently, in fact. It would help if you were to post your DCR but in general, if you have a container called CONTAINER (clever, aren't I?) and then a subcontainer called SUBCONTAINER which is a replicant and has two subelements, SUB1 and SUB2, you would extract the values with the following code using TeamSite:
CRnode and TeamSite:
CRparser, assuming you have your $rootnode set up properly, which it sounds like you would:
$rootnode->value('CONTAINER.SUBCONTAINER[0].SUB1');
$rootnode->value('CONTAINER.SUBCONTAINER[0].SUB2');
You could iterate on the [0] in order to get other replicants' values.
Dave
enthusiast
Here is the DCR:
<item name="General">
<value><item name="FooterPromotion">
<value>
<item name="Image">
<value>/images/homepage/header_browsetopics.gif</value>
</item>
<item name="AltText">
<value>1234</value>
</item>
<item name="URL">
<value>URL1</value>
</item>
</value>
<value>
<item name="Image">
<value>/images/homepage/header_browsetopics2.gif</value>
</item>
<item name="AltText">
<value>4567</value>
</item>
<item name="URL">
<value>URL2</value>
</item>
</value>
</value>
</item>
Portion of related PERL:
my %configHash = (
'THC_Home_Page/General' => ["General.FooterPromotion.Image"]
)
foreach $dcr (
@selected_DCRs)
{
if ( open (FILE, "<$dcr") ) {
while() {
$xml .= $_;
}
close(FILE);
} else {
debug ("Error opening DCR: '$dcr'");
}
debug ("\$xml: '$xml\n");
#$rootnode = TeamSite::XMLnode->new($xml);
$rootnode = TeamSite:
CRnode->new($xml);
#debug ("\$rootnode: ".$rootnode->value('General.OverrideCSS'));
if ($rootnode) {
undef ($xml); # we don't need this scalar now
# Get type of this DCR
my $tempType = getDCRTemplateType($dcr);
#debug ("Inside Parse DCR:\ntempType for DCR '$dcr' is: $tempType\n");
# Get Item list for this DCR
@elementsArray
= @{$configHash{$tempType}};
#debug ("elementsArray for $tempType is:
@elementsArray\n")
;
# Get a values of required Items from this DCR
foreach $itemName (
@elementsArray)
{
$itemValue = $rootnode->value($itemName);
debug ("itemValue = $itemValue \n");
push (
@attachFiles
, $itemValue) if ($itemValue =~/\S/);
}
} else {
debug ("DCR '$dcr' is not a valid XML");
$task->CallBack(1, "DCR '$dcr' is not a valid XML");
}
Migrateduser
Thank goodness for "View Source", eh?
What specific problems are you noticing when trying to retrieve those values? That is, what do your debug statements say in your block of code? Anyone here could go through your code and probably find the issue but having you explain it just saves a little time.
enthusiast
I can extract the values of all fields that are not in replicant. When I get a replicant or a replicant with in a replicant as the hash value of a given DCR, I am having bit of a difficulty in iterating through different levels of replicant and extracting the values since the position of the replicant is not constant.
Thanks.
Migrateduser
Okay, I didn't explain myself well but thank you for cleaning your earlier post.
I believe what you're interested in is 'General.FooterPromotion[' . $i . '].Image' such that:
my $num_children = scalar($rootnode->get_node_list('General.FooterPromotion'));
for ($i=0;$i<=$num_children;$i++) {
push(
@some_array
,$rootnode->value('General.FooterPromotion[$i].Image'));
}
... for instance.
enthusiast
Thanks for your post, but the problem is that the said replicant(s) can occur at any position and the field element names will also be different for all dcrs. How can I determine if a given element is a replicant and how can I form the correct string from the hash to fetch the child elements?
e.g.
Myroot.level1[ ].level2[ ].fieldvalue.
Myroot2.abc.level1[ ].fieldvalue2
Should I consider all fields within the path as replicants or is there a function available to recognize them?
nipper
That makes it more difficult. Maybe a regex is the best way to go.
Do you have a list of names ? Is it always Image ?
You can easily do a regex on that.
Andy
enthusiast
I think I got it for atleast 2 levels of replicants. Thanks for all your help.