1XML::Grove::Factory(3)User Contributed Perl DocumentationXML::Grove::Factory(3)
2
3
4

NAME

6       XML::Grove::Factory - simplify creation of XML::Grove objects
7

SYNOPSIS

9        use XML::Grove::Factory;
10
11        ### An object that creates Grove objects directly
12        my $gf = XML::Grove::Factory->grove_factory;
13
14        $grove = $gf->document( CONTENTS );
15        $element = $gf->element( $name, { ATTRIBUTES }, CONTENTS );
16        $pi = $gf->pi( $target, $data );
17        $comment = $gf->comment( $data );
18
19        ### An object that creates elements by method name
20        my $ef = XML::Grove::Factory->element_factory();
21
22        $element = $ef->NAME( { ATTRIBUTES }, CONTENTS);
23
24        ### Similar to `element_factory', but creates functions in the
25        ### current package
26        XML::Grove::Factory->element_functions( PREFIX, ELEMENTS );
27
28        $element = NAME( { ATTRIBUTES }, CONTENTS );
29

DESCRIPTION

31       "XML::Grove::Factory" provides objects or defines functions that let
32       you simply and quickly create the most commonly used XML::Grove
33       objects.  "XML::Grove::Factory" supports three types of object cre‐
34       ation.  The first type is to create raw XML::Grove objects.  The second
35       type creates XML elements by element name.  The third type is like the
36       second, but defines local functions for you to call instead of using an
37       object, which might save typing in some cases.
38
39       The three types of factories can be mixed.  For example, you can use
40       local functions for all element names that don't conflict with your own
41       sub names or contain special characters, and then use a `"grove_fac‐
42       tory()"' object for those elements that do conflict.
43
44       In the examples that follow, each example is creating an XML instance
45       similar to the following, assuming it's pretty printed:
46
47           <?xml version="1.0"?>
48           <HTML>
49             <HEAD>
50               <TITLE>Some Title</TITLE>
51             </HEAD>
52             <BODY bgcolor="#FFFFFF">
53               <P>A paragraph.</P>
54             </BODY>
55           </HTML>
56

GROVE FACTORY

58       $gf = XML::Grove::Factory->grove_factory()
59           Creates a new grove factory object that creates raw XML::Grove
60           objects.
61
62       $gf->document( CONTENTS );
63           Creates an XML::Grove::Document object.  CONTENTS may contain pro‐
64           cessing instructions, strings containing only whitespace charac‐
65           ters, and a single element object (but note that there is no check‐
66           ing).  Strings are converted to XML::Grove::Characters objects.
67
68       $gf->element($name, CONTENTS);
69       $gf->element($name, { ATTRIBUTES }, CONTENTS);
70           Creates an XML::Grove::Element object with the name `$name'.  If
71           the argument following `$name' is an anonymous hash, ATTRIBUTES,
72           then they will be copied to the elements attributes.  CONTENTS will
73           be stored in the element's content (note that there is no validity
74           checking).  Strings in CONTENTS are converted to XML::Grove::Char‐
75           acters objects.
76
77       $gf->pi( TARGET, DATA)
78       $gf->pi( DATA )
79           Create an XML::Grove::PI object with TARGET and DATA.
80
81       $gf->comment( DATA )
82           Create an XML::Grove::Comment object with DATA.
83
84       GROVE FACTORY EXAMPLE
85
86        use XML::Grove::Factory;
87
88        $gf = XML::Grove::Factory->grove_factory;
89
90        $element =
91          $gf->element('HTML',
92            $gf->element('HEAD',
93              $gf->element('TITLE', 'Some Title')),
94            $gf->element('BODY', { bgcolor => '#FFFFFF' },
95              $gf->element('P', 'A paragraph.')));
96

ELEMENT FACTORY

98       $ef = XML::Grove::Factory->element_factory()
99           Creates a new element factory object for creating elements.  `"ele‐
100           ment_factory()"' objects work by creating an element for any name
101           used to call the object.
102
103       $ef->NAME( CONTENTS )
104       $ef->NAME( { ATTRIBUTES }, CONTENTS)
105           Creates an XML::Grove::Element object with the given NAME,
106           ATTRIBUTES, and CONTENTS.  The hash containing ATTRIBUTES is
107           optional if this element doesn't need attributes.  Strings in CON‐
108           TENTS are converted to XML::Grove::Characters objects.
109
110       ELEMENT FACTORY EXAMPLE
111
112        use XML::Grove::Factory;
113
114        $ef = XML::Grove::Factory->element_factory();
115
116        $element =
117          $ef->HTML(
118            $ef->HEAD(
119              $ef->TITLE('Some Title')),
120            $ef->BODY({ bgcolor => '#FFFFFF' },
121              $ef->P('A paragraph.')));
122

ELEMENT FUNCTIONS

124       XML::Grove::Factory->element_functions (PREFIX, ELEMENTS)
125           Creates functions in the current package for creating elements with
126           the names provided in the list ELEMENTS.  PREFIX will be prepended
127           to every function name, or PREFIX can be an empty string ('') if
128           you're confident that there won't be any conflicts with functions
129           in your package.
130
131       NAME( CONTENTS )
132       NAME( { ATTRIBUTES }, CONTENTS )
133       PREFIXNAME( CONTENTS )
134       PREFIXNAME( { ATTRIBUTES }, CONTENTS )
135           Functions created for `"NAME"' or `"PREFIXNAME"' can be called to
136           create XML::Grove::Element objects with the given NAME, ATTRIBUTES,
137           and CONTENT.  The hash containing ATTRIBUTES is optional if this
138           element doesn't need attributes.  Strings in CONTENT are converted
139           to XML::Grove::Characters objects.
140
141       ELEMENT FACTORY EXAMPLE
142
143        use XML::Grove::Factory;
144
145        XML::Grove::Factory->element_functions('', qw{ HTML HEAD TITLE BODY P });
146
147        $element =
148          HTML(
149            HEAD(
150              TITLE('Some Title')),
151            BODY({ bgcolor => '#FFFFFF' },
152              P('A paragraph.')));
153

AUTHOR

155       Ken MacLeod, ken@bitsko.slc.ut.us
156
157       Inspired by the HTML::AsSubs module by Gisle Aas.
158

SEE ALSO

160       perl(1), XML::Grove(3).
161
162       Extensible Markup Language (XML) <http://www.w3c.org/XML>
163
164
165
166perl v5.8.8                       1999-08-25            XML::Grove::Factory(3)
Impressum