1Net::LDAP::DSML(3) User Contributed Perl Documentation Net::LDAP::DSML(3)
2
3
4
6 Net::LDAP::DSML -- A DSML Writer for Net::LDAP
7
9 For a directory entry;
10
11 use Net::LDAP;
12 use Net::LDAP::DSML;
13 use IO::File;
14
15
16 my $server = "localhost";
17 my $file = "testdsml.xml";
18 my $ldap = Net::LDAP->new($server);
19
20 $ldap->bind();
21
22
23 #
24 # For file i/o
25 #
26 my $file = "testdsml.xml";
27
28 my $io = IO::File->new($file,"w")
29 or die ("failed to open $file as filehandle.$!\n");
30
31 my $dsml = Net::LDAP::DSML->new(output => $io, pretty_print => 1 )
32 or die ("DSML object creation problem using an output file.\n");
33 # OR
34 #
35 # For file i/o
36 #
37
38 open (IO,">$file") or die("failed to open $file.$!");
39
40 my $dsml = Net::LDAP::DSML->new(output => *IO, pretty_print => 1)
41 or die ("DSML object creation problem using an output file.\n");
42
43 # OR
44 #
45 # For array usage.
46 # Pass a reference to an array.
47 #
48
49 my @data = ();
50 $dsml = Net::LDAP::DSML->new(output => \@data, pretty_print => 1)
51 or die ("DSML object cration problem using an output array.\n");
52
53
54 my $mesg = $ldap->search(
55 base => 'o=airius.com',
56 scope => 'sub',
57 filter => 'ou=accounting',
58 callback => sub {
59 my ($mesg,$entry) =@_;
60 $dsml->write_entry($entry)
61 if (ref $entry eq 'Net::LDAP::Entry');
62 }
63 );
64
65 die ("search failed with ",$mesg->code(),"\n") if $mesg->code();
66
67 For directory schema;
68
69 A file or array can be used for output, in the following example
70 only an array will be used.
71
72 my $schema = $ldap->schema();
73 my @data = ();
74 my $dsml = Net::LDAP::DSML->new(output => \@data, pretty_print => 1 )
75 or die ("DSML object creation problem using an output array.\n");
76
77 $dsml->write_schema($schema);
78
79 print "Finished printing DSML\n";
80
82 Directory Service Markup Language (DSML) is the XML standard for
83 representing directory service information in XML.
84
85 At the moment this module only writes DSML entry and schema entities.
86 Reading DSML entities is a future project.
87
88 Eventually this module will be a full level 2 consumer and producer
89 enabling you to give you full DSML conformance. Currently this module
90 has the ability to be a level 2 producer. The user must understand the
91 his/her directory server will determine the consumer and producer level
92 they can achieve.
93
94 To determine conformance, it is useful to divide DSML documents into
95 four types:
96
97 1.Documents containing no directory schema nor any references to
98 an external schema.
99 2.Documents containing no directory schema but containing at
100 least one reference to an external schema.
101 3.Documents containing only a directory schema.
102 4.Documents containing both a directory schema and entries.
103
104 A producer of DSML must be able to produce documents of type 1. A
105 producer of DSML may, in addition, be able to produce documents of
106 types 2 thru 4.
107
108 A producer that can produce documents of type 1 is said to be a level 1
109 producer. A producer than can produce documents of all four types is
110 said to be a level 2 producer.
111
113 The module uses callbacks to improve performance (at least the
114 appearance of improving performance ;) and to reduce the amount of
115 memory required to parse large DSML files. Every time a single entry or
116 schema is processed we pass the Net::LDAP object (either an Entry or
117 Schema object) to the callback routine.
118
120 new ()
121 Creates a new Net::LDAP::DSML object. There are 2 options to this
122 method.
123
124 "output" is a reference to either a file handle that has already
125 been opened or to an array.
126
127 "pretty_print" is an option to print a new line at the end of each
128 element sequence. It makes the reading of the XML output easier
129 for a human.
130
131 Example
132
133 my $dsml = Net::LDAP::DSML->new();
134 Prints xml data to standard out.
135
136 my $dsml = Net::LDAP::DSML->new(output => \@array);
137 my $dsml = Net::LDAP::DSML->new(output => *FILE);
138 Prints xml data to a file or array.
139
140 my $dsml = Net::LDAP::DSML->new(output => \@array, pretty_print => 1);
141 my $dsml = Net::LDAP::DSML->new(output => *FILE, pretty_print => 1);
142 Prints xml data to a file or array in pretty print style.
143
145 start_dsml ()
146 Start a DSML file.
147
148 end_dsml ()
149 End a DSML file.
150
151 write_entry ( ENTRY )
152 Entry is a Net::LDAP::Entry object. The write method will parse the
153 LDAP data in the Entry object and put it into DSML XML format.
154
155 Example
156
157 my $entry = $mesg->entry();
158 $dsml->write_entry($entry);
159
160 write_schema ( SCHEMA )
161 Schema is a Net::LDAP::Schema object. The write_schema method will
162 parse the LDAP data in the Schema object and put it into DSML XML
163 format.
164
165 Example
166
167 my $schema = $ldap->schema();
168 $dsml->write_schema($schema);
169
171 Graham Barr gbarr@pobox.com
172
174 Net::LDAP, XML::SAX::Base
175
177 Copyright (c) 2002-2006 Graham Barr. All rights reserved. This program
178 is free software; you can redistribute it and/or modify it under the
179 same terms as Perl itself.
180
181
182
183perl v5.16.3 2013-06-07 Net::LDAP::DSML(3)