- 论坛徽章:
- 0
|
谢谢!上面有解说,要是给出例子就更直观了。
toString ( [ norecurse ] )
Output (and all children) the node to a string. Doesn't process children if the norecurse option is a true value.
- sub toString {
- my ($self, $norecurse) = @_;
-
- my $string = '';
- if (! $self->[node_name] ) {
- # root node
- return join('', map { $_->toString($norecurse) } @{$self->[node_children]});
- }
-
- $string .= "<" . $self->[node_name];
- $string .= join('', map { $_->toString } @{$self->[node_namespaces]});
- $string .= join('', map { $_->toString } @{$self->[node_attribs]});
-
- if (@{$self->[node_children]}) {
- $string .= ">";
-
- if (!$norecurse) {
- $string .= join('', map { $_->toString($norecurse) } @{$self->[node_children]});
- }
-
- $string .= "</" . $self->[node_name] . ">";
- }
- else {
- $string .= " />";
- }
-
- return $string;
- }
复制代码
|
|