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)
Getting node names/values from a DCR
jdee
I'd like to get the node names/values from a DCR in my TPL. The issue is, my DCT is created dynamically and could contain literally anything. How can I parse out the XML to get the node names and values?
Thanks,
jdee
Find more posts tagged with
Comments
gzevin
well.. you could always parse using XML::
OM and then use the node/attribute values to read the DCR. However I think it's a HUGE job
Greg Zevin, Ph.D. Comp. Sc.
Independent Interwoven Consultant/Architect
Sydney, AU
Adam Stoller
Are you saying that there's no established DTD for these DCRs? (are they "iwov" format or "xml" format?)
Also - I'm not sure of what your use of the output is - so it's possible that something like this might do the trick:
use File:
lurp qw(slurp);
my $fname = "fishtest";
my $xml = slurp($fname);
$xml =~ s/\n//gms;
my %nodes;
while($xml =~ m{
<item \s+ name \s* = \s* ['"] ([^'"]+) ['"] .*? >
[^<]*
<value> ([^<]+) </value>
}gmsx){
push(@{$nodes{$1}}, $2);
}
foreach my $node (keys(%nodes)){
print "$node:\n";
print "\t$_\n" foreach(@{$nodes{$node}});
}
Note: This will not list nodes for which there are no values - I'll leave that as an exercise for the bored ;-)
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com
jdee
Here's what I came up with, worked for my needs:
my $rootnode = TeamSite:
CRnode->new($xml);
my
@nodes
= $rootnode->get_node_list('somenode.*');
foreach my $node (
@nodes)
{
if ($node->type() ne "CDATA") {
$newxml .= '<item name="' . $node->type() . '" ';
my
@subnodes
= $rootnode->get_node_list('somenode.' . $node->type() . '.*');
foreach my $subnode (
@subnodes)
{
if ($subnode->type() ne "CDATA") {
$newxml .= '' . $subnode->type() . '="' . $subnode->value() . '" ';
}
}
$newxml .= '/>';
}
}