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)
Can a node be removed run time using XMLNode?
sabih
Consider the following portion of a DCR. I am trying to delete the entire node of Related_Content_Links at run time based on the "Value" attribute of the "link" node.
- <Links_and_Attachments>
- <Article_Links>
- <Related_Content_Links>
<Related_Content_Link><link Type = 'Article' Value = '28'/></Related_Content_Link>
<Related_Content_Link_Display_Name>Auto Insurance</Related_Content_Link_Display_Name>
</Related_Content_Links>
- <Related_Content_Links>
<Related_Content_Link><link Type = 'Article' Value = '34'/></Related_Content_Link>
<Related_Content_Link_Display_Name>Education Savings</Related_Content_Link_Display_Name>
</Related_Content_Links>
- <Related_Content_Links>
<Related_Content_Link><link Type = 'Article' Value = '33'/></Related_Content_Link>
<Related_Content_Link_Display_Name>Retirement Savings</Related_Content_Link_Display_Name>
</Related_Content_Links>
</Article_Links>
</Links_and_Attachments>
Find more posts tagged with
Comments
Migrateduser
Surprisingly, XMLnode doesn't seem to have a delete method. The first thing that comes to mind for me would be to use the get_inner_xml method on the parent node, then use a regex to strip out the element (and its children) you want to delete from that string, and use set_inner_xml() to reset the contents of the parent node.
Or, use a different module like XML:
OM (which also ships with TS)
BIRT_align_properties.jpg
gzevin
yes, Jon **** somehow decided not to have it
Yes, I'd vote for XML:
OM too
Greg Zevin, Ph.D. Comp. Sc.
Independent Interwoven Consultant/Architect
Sydney, AU
sabih
I am trying to use the inner_xml but some how it just overwrites my entire DCR with the filtered value. I need to just delete the portion say with the value as "28" from the DCR snippet at the bottom.
my $rootnode = TeamSite::XMLnode->new($xml);
my
@list
= $rootnode->get_node_list('Page2.Links_and_Attachments.Article_Links.Related_Content_Links');
my $test = $rootnode->get_inner_xml('Page2.Links_and_Attachments.Article_Links');
foreach my $node (
@list)
{
//ommited some of the steps
....
my $value = substr($myNode->value(), $position1, $position2-$position1);
$test =~ s/<Related_Content_Links>.*Value = '$value'.*<\/Related_Content_Links>//g;
$rootnode->set_inner_xml($test);
open (WRITEFILE, ">$dcr") or die "Failed to open $dcr, $!";
print WRITEFILE $test;
close WRITEFILE;
}
DCR Snippet:
.....
....
<Page2>
- <Links_and_Attachments>
- <Article_Links>
------ portion to be deleted ---------
- <Related_Content_Links>
<Related_Content_Link><link Type = 'Article' Value = '28'/></Related_Content_Link>
<Related_Content_Link_Display_Name>Auto Insurance</Related_Content_Link_Display_Name>
</Related_Content_Links>
----------------------------------------
- <Related_Content_Links>
<Related_Content_Link><link Type = 'Article' Value = '34'/></Related_Content_Link>
<Related_Content_Link_Display_Name>Education Savings</Related_Content_Link_Display_Name>
</Related_Content_Links>
- <Related_Content_Links>
<Related_Content_Link><link Type = 'Article' Value = '33'/></Related_Content_Link>
<Related_Content_Link_Display_Name>Retirement Savings</Related_Content_Link_Display_Name>
</Related_Content_Links>
<Detail_Article_Link_Display_Name />
</Article_Links>
</Links_and_Attachments>
</Page2>
....
...
Edited by sabih on 01/13/05 10:12 AM (server time).
Migrateduser
Your problem is right here
In reply to:
$rootnode->set_inner_xml($test);
You don't want to change the xml of the root node, you want to change it on the node referenced by the accessor Page2.Links_And_Attachments.Article_Links. Get a reference to that node by calling $rootnode's get_node method with that accessor, then use the set_inner_xml method of the node that returns.
sabih
Ok I got that right. Now how should I go about over writing the file? What string should I be writing to an existing DCR?
Migrateduser
I think you're after the method called get_xml (as opposed to get_inner_xml) on the rootnode. You may have to manually emit the prologue prior to writing the string to the file. The perldoc for TeamSite::XMLparser should give the definitive answer (or you could just experiment).