source: trunk/gsdl/perllib/cpan/XML/XPath/Node/Attribute.pm@ 7909

Last change on this file since 7909 was 7909, checked in by mdewsnip, 20 years ago

CPAN module for processing XPath expressions.

  • Property svn:keywords set to Author Date Id Revision
File size: 2.1 KB
Line 
1# $Id: Attribute.pm 7909 2004-08-06 05:11:55Z mdewsnip $
2
3package XML::XPath::Node::Attribute;
4
5use strict;
6use vars qw/@ISA/;
7
8@ISA = ('XML::XPath::Node');
9
10package XML::XPath::Node::AttributeImpl;
11
12use vars qw/@ISA/;
13@ISA = ('XML::XPath::NodeImpl', 'XML::XPath::Node::Attribute');
14use XML::XPath::Node ':node_keys';
15
16sub new {
17 my $class = shift;
18 my ($key, $val, $prefix) = @_;
19
20 my $pos = XML::XPath::Node->nextPos;
21
22 my @vals;
23 @vals[node_global_pos, node_prefix, node_key, node_value] =
24 ($pos, $prefix, $key, $val);
25 my $self = \@vals;
26
27 bless $self, $class;
28
29}
30
31sub getNodeType { ATTRIBUTE_NODE }
32
33sub isAttributeNode { 1; }
34
35sub getName {
36 my $self = shift;
37 $self->[node_key];
38}
39
40sub getLocalName {
41 my $self = shift;
42 my $local = $self->[node_key];
43 $local =~ s/.*://;
44 return $local;
45}
46
47sub getNodeValue {
48 my $self = shift;
49 $self->[node_value];
50}
51
52sub getData {
53 shift->getNodeValue(@_);
54}
55
56sub setNodeValue {
57 my $self = shift;
58 $self->[node_value] = shift;
59}
60
61sub getPrefix {
62 my $self = shift;
63 $self->[node_prefix];
64}
65
66sub string_value {
67 my $self = shift;
68 return $self->[node_value];
69}
70
71sub toString {
72 my $self = shift;
73 my $string = ' ';
74# if ($self->[node_prefix]) {
75# $string .= $self->[node_prefix] . ':';
76# }
77 $string .= join('',
78 $self->[node_key],
79 '="',
80 XML::XPath::Node::XMLescape($self->[node_value], '"&><'),
81 '"');
82 return $string;
83}
84
85sub getNamespace {
86 my $self = shift;
87 my ($prefix) = @_;
88 $prefix ||= $self->getPrefix;
89 if (my $parent = $self->getParentNode) {
90 return $parent->getNamespace($prefix);
91 }
92}
93
941;
95__END__
96
97=head1 NAME
98
99Attribute - a single attribute
100
101=head1 API
102
103=head2 new ( key, value, prefix )
104
105Create a new attribute node.
106
107=head2 getName
108
109Returns the key for the attribute
110
111=head2 getLocalName
112
113As getName above, but without namespace information
114
115=head2 getNodeValue / getData
116
117Returns the value
118
119=head2 setNodeValue
120
121Sets the value of the attribute node.
122
123=head2 getPrefix
124
125Returns the prefix
126
127=head2 getNamespace
128
129Return the namespace.
130
131=head2 toString
132
133Generates key="value", encoded correctly.
134
135=cut
Note: See TracBrowser for help on using the repository browser.