1AnyEvent::XMPP::Node(3)User Contributed Perl DocumentatioAnnyEvent::XMPP::Node(3)
2
3
4
6 AnyEvent::XMPP::Node - XML node tree helper for the parser.
7
9 use AnyEvent::XMPP::Node;
10 ...
11
13 This class represens a XML node. AnyEvent::XMPP should usually not
14 require messing with the parse tree, but sometimes it is neccessary.
15
16 If you experience any need for messing with these and feel
17 AnyEvent::XMPP should rather take care of it drop me a mail, feature
18 request or most preferably a patch!
19
20 Every AnyEvent::XMPP::Node has a namespace, attributes, text and child
21 nodes.
22
23 You can access these with the following methods:
24
26 new ($ns, $el, $attrs, $parser)
27 Creates a new AnyEvent::XMPP::Node object with the node tag name
28 $el in the namespace URI $ns and the attributes $attrs. The $parser
29 must be the instance of "AnyEvent::XMPP::Parser" which generated
30 this node.
31
32 name
33 The tag name of this node.
34
35 namespace
36 Returns the namespace URI of this node.
37
38 eq ($namespace_or_alias, $name) or eq ($node)
39 Returns true whether the current element matches the tag name $name
40 in the namespaces pointed at by $namespace_or_alias.
41
42 You can either pass an alias that was defined in
43 AnyEvent::XMPP::Namespaces or pass an namespace URI in
44 $namespace_or_alias. If no alias with the name $namespace_or_alias
45 was found in AnyEvent::XMPP::Namespaces it will be interpreted as
46 namespace URI.
47
48 The first argument to eq can also be another AnyEvent::XMPP::Node
49 instance.
50
51 eq_ns ($namespace_or_alias) or eq_ns ($node)
52 This method return true if the namespace of this instance of
53 AnyEvent::XMPP::Node matches the namespace described by
54 $namespace_or_alias or the namespace of the $node which has to be
55 another AnyEvent::XMPP::Node instance.
56
57 See "eq" for the meaning of $namespace_or_alias.
58
59 attr ($name)
60 Returns the contents of the $name attribute.
61
62 add_node ($node)
63 Adds a sub-node to the current node.
64
65 nodes
66 Returns a list of sub nodes.
67
68 add_text ($string)
69 Adds character data to the current node.
70
71 text
72 Returns the text for this node.
73
74 find_all (@path)
75 This method does a recursive descent through the sub-nodes and
76 fetches all nodes that match the last element of @path.
77
78 The elements of @path consist of a array reference to an array with
79 two elements: the namespace key known by the $parser and the
80 tagname we search for.
81
82 write_on ($writer)
83 This writes the current node out to the AnyEvent::XMPP::Writer
84 object in $writer.
85
86 as_string ()
87 This method returns the original character representation of this
88 XML element (and it's children nodes). Please note that the string
89 is a unicode string, meaning: to get octets use:
90
91 my $octets = encode ('UTF-8', $node->as_string);
92
93 Now you can roll stunts like this:
94
95 my $libxml = XML::LibXML->new;
96 my $doc = $libxml->parse_string (encode ('UTF-8', $node->as_string ()));
97
98 (You can use your favorite XML parser :)
99
100 append_raw ($string)
101 This method is called by the parser to store original strings of
102 this element.
103
104 to_sax_events ($handler)
105 This method takes anything that can receive SAX events. See also
106 XML::GDOME::SAX::Builder or XML::Handler::BuildDOM or
107 XML::LibXML::SAX::Builder.
108
109 With this you can convert this node to any DOM level 2 structure
110 you want:
111
112 my $builder = XML::LibXML::SAX::Builder->new;
113 $node->to_sax_events ($builder);
114 my $dom = $builder->result;
115 print "Canonized: " . $dom->toStringC14N . "\n";
116
118 Robin Redeker, "<elmex at ta-sa.org>", JID: "<elmex at jabber.org>"
119
121 Copyright 2007, 2008 Robin Redeker, all rights reserved.
122
123 This program is free software; you can redistribute it and/or modify it
124 under the same terms as Perl itself.
125
126
127
128perl v5.34.0 2021-07-22 AnyEvent::XMPP::Node(3)