DataLoader/XMLWriter.pm untested

filter: Statementstmt 0.0% 0 / 440 Branchbran 0.0% 0 / 272 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 725 CC 137 SCAR 98.1
CC
137
Cov
0%
makexml
18906.0
new
2.0
BEGIN
2.0
CRAP 18240.4
1  
2  
3  
4 package DBIx::XML::DataLoader::XMLWriter;
5  
6 use strict;
7 use warnings;
8  
9 my $VERSION="1.0b";
10 ###########
11 sub new{
12 #########
13 my $self=shift;
14  
15 bless \$self;
16  
17 ##########
18 } # end sub new
19 #################
20  
21 ##################
22 sub makexml{
23 ############
24  
25 ###############################################################
26 #### this sub will expect 2 variables to be passed to it
27 #### $data: should be a hash_ref to our data
28 #### $doc_root: should be set to the document_root
29 ###############################################################
30  
31  
32 ##
33 my $self=shift;
34 my $data=shift;
35 my %all_data=%{$data};
36 my $doc_root=shift;
37 my %doc=($doc_root=>[{}]);
38  
39 ############
40  
41 use XML::Simple;
42 my $parser = new XML::Simple(noescape=>1,keeproot=>1);
43 use DBIx::XML::DataLoader::Date;
44 my $date=DBIx::XML::DataLoader::Date->now();
45  
46 my $rootcnt="0";
47 ##############################################
48 ### here we walk though all the db results
49 ## building our xml doc as we go.
50 ###############################################
51 my @all_finished_tables;
52 my @allthekeys;
53 KEY_LOOP: for my $keys (sort keys %all_data){push @allthekeys, $keys;}
54 my @testkeys=@allthekeys;
55  
56 TABLE_LOOP:
57 while (@allthekeys){
58 my $keys= shift @allthekeys;
59 my $table_node=$all_data{$keys}->{node};
60 my %table_pass;
61 my $fparent;
62 if($all_data{$keys}->{parent}){
63  
64 PARENTCHECK:for my $finished_tables (@all_finished_tables){
65 if($finished_tables eq $all_data{$keys}->{parent}){
66 $fparent="yes";
67 last PARENTCHECK;
68 }
69 }
70  
71 if(!$fparent){
72 $fparent="yes";
73 BPARENTCHECK: for my $test_table (@allthekeys){
74 if($test_table eq $all_data{$keys}->{parent}){
75 $fparent=undef;last BPARENTCHECK;
76 }
77 }
78 }
79  
80 if(!$fparent){push @allthekeys, $keys;next TABLE_LOOP;}
81 }
82  
83  
84 push @all_finished_tables, $keys;
85 $table_pass{parent}->{hasone}="no";
86 my $dbname=$all_data{$keys}->{dbname};
87 if($all_data{$keys}->{data}){
88 LOOPCNT: for my $lpcnt (sort keys %{$all_data{$keys}->{data}}){
89  
90 my $table_xpath=$all_data{$keys}->{xpath};
91 $table_xpath=~ s[^\./][];
92 my $the_root=$doc_root;
93 my @info=@{$all_data{$keys}->{data}->{$lpcnt}};
94 my $tableroot=$all_data{$keys}->{node};
95 my %table_doc;
96 INFO: for my $info (@info){
97 my $value=$info->{val};
98 ### here we set any values that have xpaths starting from the document root
99 ## this seems to work
100 if($info->{xpath} =~ m[^/]){
101 ## do root doc stuff here
102 my $xpath=$info->{xpath};
103 $xpath =~ s[^/+][];
104 my @path=split m[/], $xpath;
105 my $the_root=shift @path;
106 my $path_cnt=scalar @path;
107 #my $value=$info->{val};
108 if($path_cnt==1){
109 if(!$doc{$the_root}[$rootcnt]->{$path[$path_cnt-1]}[0]){
110 $doc{$the_root}[$rootcnt]->{$path[$path_cnt-1]}[0]=$value;
111 next INFO;}
112 if($doc{$the_root}[$rootcnt]->{$path[$path_cnt-1]}[0]){
113 if($doc{$the_root}[$rootcnt]->{$path[$path_cnt-1]}[0] ne $value){
114 $rootcnt++;
115 $doc{$the_root}[$rootcnt]->{$path[$path_cnt-1]}[0]=$value;
116 next INFO;
117 }
118  
119 }
120  
121 }
122  
123 if($path_cnt==2){
124 if(!$doc{$the_root}[$rootcnt]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}[0]){
125 $doc{$the_root}[$rootcnt]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}[0]=$value;
126 next INFO;
127 }
128 if($doc{$the_root}[$rootcnt]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}[0]){
129 if($doc{$the_root}[$rootcnt]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}[0] ne $value){
130 $rootcnt++;
131 $doc{$the_root}[$rootcnt]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}[0]=$value;
132 next INFO;
133 }
134 }
135  
136 }
137 if($path_cnt==3){
138 if(!$doc{$the_root}[$rootcnt]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}[0]){
139 $doc{$the_root}[$rootcnt]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}[0]=$value;
140 next INFO;
141 }
142 if($doc{$the_root}[$rootcnt]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}[0]){
143 if($doc{$the_root}[$rootcnt]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}[0] ne $value){
144 $rootcnt++;
145 $doc{$the_root}[$rootcnt]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}[0]=$value;
146 next INFO;
147 }
148 }
149  
150 }
151 if($path_cnt==4){
152 if(!$doc{$the_root}[$rootcnt]->{$path[$path_cnt-4]}[0]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}[0]){
153 $doc{$the_root}[$rootcnt]->{$path[$path_cnt-4]}[0]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}[0]=$value;
154 next INFO;
155 }
156 if($doc{$the_root}[$rootcnt]->{$path[$path_cnt-4]}[0]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}[0]){
157 if($doc{$the_root}[$rootcnt]->{$path[$path_cnt-4]}[0]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}[0] ne $value){
158 $rootcnt++;
159 $doc{$the_root}[$rootcnt]->{$path[$path_cnt-4]}[0]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}[0]=$value;
160 next INFO;
161 }
162 }
163 }
164 if($path_cnt==5){
165 if(!$doc{$the_root}[$rootcnt]->{$path[$path_cnt-5]}[0]->{$path[$path_cnt-4]}[0]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}[0]){
166 $doc{$the_root}[$rootcnt]->{$path[$path_cnt-5]}[0]->{$path[$path_cnt-4]}[0]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}[0]=$value;
167 next INFO;
168 }
169 if($doc{$the_root}[$rootcnt]->{$path[$path_cnt-5]}[0]->{$path[$path_cnt-4]}[0]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}[0]){
170 if($doc{$the_root}[$rootcnt]->{$path[$path_cnt-5]}[0]->{$path[$path_cnt-4]}[0]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}[0]
171 ne $value){
172 $rootcnt++;
173 $doc{$the_root}[$rootcnt]->{$path[$path_cnt-5]}[0]->{$path[$path_cnt-4]}[0]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}[0]=$value;
174 next INFO;
175 }
176 }
177 }
178 if($path_cnt==6){
179 if(!$doc{$the_root}[$rootcnt]->{$path[$path_cnt-6]}[0]->{$path[$path_cnt-5]}[0]->{$path[$path_cnt-4]}[0]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}[0]){
180 $doc{$the_root}[$rootcnt]->{$path[$path_cnt-6]}[0]->{$path[$path_cnt-5]}[0]->{$path[$path_cnt-4]}[0]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}[0]=$value;
181 next INFO;
182 }
183 if($doc{$the_root}[$rootcnt]->{$path[$path_cnt-6]}[0]->{$path[$path_cnt-5]}[0]->{$path[$path_cnt-4]}[0]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}[0]){
184 if($doc{$the_root}[$rootcnt]->{$path[$path_cnt-6]}[0]->{$path[$path_cnt-5]}[0]->{$path[$path_cnt-4]}[0]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}[0]
185 ne $value){
186 $rootcnt++;
187 $doc{$the_root}[$rootcnt]->{$path[$path_cnt-6]}[0]->{$path[$path_cnt-5]}[0]->{$path[$path_cnt-4]}[0]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}[0]=$value;
188 next INFO;
189 }
190 }
191 }
192 next INFO;
193 }
194 ##################################
195  
196 ## here we check to see if this table has a parent in the xml output document
197 my $xpath=$info->{xpath};
198 if(($xpath =~ /^parent/i)or($xpath =~ m[^\.\./])){
199 $table_pass{parent}->{$lpcnt}->{value}=$value;
200 $table_pass{parent}->{$lpcnt}->{xpath}=$info->{xpath};
201 $table_pass{parent}->{$lpcnt}->{attribute}=$info->{attribute};
202 $table_pass{parent}->{hasone}="yes";
203 next INFO;
204 }
205 $info->{xpath} =~ s[^\./][];
206 my @current_xpath=split m[/], $info->{xpath};
207 my $path_cnt=scalar @current_xpath;
208 if($table_node ne $doc_root){
209 #######################################################
210 if($path_cnt == 1){
211 if($table_node ne $info->{item_node}){
212 if($info->{attribute}){
213 $table_doc{$current_xpath[0]}[0]->{$info->{attribute}}=$value;
214 next INFO;
215 } # end if
216 if(!$info->{attribute}){
217 if($value){
218 $table_doc{$current_xpath[0]}[0]->{content}.=$value;}
219 next INFO;
220 }
221 }
222 if($table_node eq $info->{item_node}){
223 if($info->{attribute}){
224 $table_doc{$info->{attribute}}=$value;
225 #print $parser->XMLout(\%table_doc, rootname=>$table_node);
226 next INFO;
227 } # end if
228 if(!$info->{attribute}){
229  
230 $table_doc{content}.=$value;
231 next INFO;
232 }
233 }
234 } #if $path_cnt==1
235 #######################################################
236 if($path_cnt == 2){
237  
238 if($table_node ne $info->{item_node}){
239  
240 if($info->{attribute}){
241 $table_doc{$current_xpath[0]}[0]->{$info->{attribute}}=$value;
242 next INFO;
243 } # end if
244 if(!$info->{attribute}){
245 $table_doc{$current_xpath[0]}[0]->{$current_xpath[1]}[0]->{content}.=$value;
246 next INFO;
247 }
248 }
249 if($table_node eq $info->{item_node}){
250  
251 if($info->{attribute}){
252 $table_doc{$info->{attribute}}=$value;
253 next INFO;
254 }
255 if(!$info->{attribute}){
256 $table_doc{$current_xpath[1]}[0]->{content}.=$value;
257 next INFO;
258 }
259 }
260 } #if $path_cnt==2
261 #######################################################
262 if($path_cnt == 3){
263 if($table_node ne $info->{item_node}){
264 if($info->{attribute}){
265 $table_doc{$current_xpath[0]}[0]->{$current_xpath[1]}[0]->{$info->{attribute}}=$value;
266 next INFO;
267 } # end if
268 if(!$info->{attribute}){
269 $table_doc{$current_xpath[0]}[0]->{$current_xpath[1]}[0]->{$current_xpath[2]}[0]->{content}.=$value;
270 next INFO;
271 }
272 }
273 if($table_node eq $info->{item_node}){
274 if($info->{attribute}){
275 $table_doc{$info->{attribute}}=$value;
276 next INFO;
277 }
278 if(!$info->{attribute}){
279 $table_doc{$current_xpath[1]}[0]->{content}.=$value;
280 next INFO;
281 }
282 }
283 } #if $path_cnt==3
284 ################################################
285  
286 #######################################################
287 if($path_cnt == 4){
288 if($table_node ne $info->{item_node}){
289 if($info->{attribute}){
290 $table_doc{$current_xpath[0]}[0]->{$current_xpath[1]}[0]->{$current_xpath[2]}[0]->{$info->{attribute}}=$value;
291 next INFO;
292 } # end if
293 if(!$info->{attribute}){
294 $table_doc{$current_xpath[0]}[0]->{$current_xpath[1]}[0]->{$current_xpath[2]}[0]->{$current_xpath[3]}[0]->{content}.=$value;
295 next INFO;
296 }
297 }
298  
299 } #if $path_cnt==4
300 ###################################################
301 if($path_cnt == 5){
302 if($table_node ne $info->{item_node}){
303 if($info->{attribute}){
304 $table_doc{$current_xpath[0]}[0]->{$current_xpath[1]}[0]->{$current_xpath[2]}[0]->{$current_xpath[3]}[0]->{$info->{attribute}}=$value;
305 next INFO;
306 } # end if
307 if(!$info->{attribute}){
308 $table_doc{$current_xpath[0]}[0]->{$current_xpath[1]}[0]->{$current_xpath[2]}[0]->{$current_xpath[3]}[0]->{$current_xpath[4]}[0]->{content}.=$value;
309 next INFO;
310 }
311 }
312  
313 } #if $path_cnt==5
314 #######################################################
315 if($path_cnt == 6){
316 if($table_node ne $info->{item_node}){
317 if($info->{attribute}){
318 $table_doc{$current_xpath[0]}[0]->{$current_xpath[1]}[0]->{$current_xpath[2]}[0]->{$current_xpath[3]}[0]->{$current_xpath[4]}[0]->{$info->{attribute}}=$value;
319 next INFO;
320 } # end if
321 if(!$info->{attribute}){
322 $table_doc{$current_xpath[0]}[0]->{$current_xpath[1]}[0]->{$current_xpath[2]}[0]->{$current_xpath[3]}[0]->{$current_xpath[4]}[0]->{$current_xpath[5]}[0]->{content}.=$value;
323 next INFO;
324 }
325 }
326  
327 } #if $path_cnt==6
328  
329 #######################################################
330  
331  
332 } # end if n$table_node ne doc_root
333  
334  
335  
336 ##################################################
337 ##################################################
338 ##################################################
339 ##################################################
340  
341 if($table_node eq $doc_root){
342 if($path_cnt == 1){
343 ## if scalar split [/], $info->{xpath} == 1
344 if($info->{attribute}){
345 $doc{$doc_root}[$rootcnt]->{$current_xpath[0]}[0]->{$info->{attribute}}=$value;
346 next INFO;
347 } # end if
348 if(!$info->{attribute}){
349 $doc{$doc_root}[$rootcnt]->{$current_xpath[0]}[0]->{content}.=$value;
350 next INFO;
351 }
352 } #if $path_cnt==1
353 ################################################
354  
355 #######################################################
356 if($path_cnt == 2){
357 if($info->{attribute}){
358 $doc{$doc_root}[$rootcnt]->{$current_xpath[0]}[0]->{$info->{attribute}}=$value;
359 next INFO;
360 } # end if
361 if(!$info->{attribute}){
362  
363 $doc{$doc_root}[$rootcnt]->{$current_xpath[0]}[0]->{$current_xpath[1]}[0]->{content}.=$value;
364 next INFO;
365 }
366 } #if $path_cnt==2
367 ################################################
368  
369  
370 #######################################################
371 if($path_cnt == 3){
372 if($info->{attribute}){
373 $doc{$doc_root}[$rootcnt]->{$current_xpath[0]}[0]->{$current_xpath[1]}[0]->{$info->{attribute}}=$value;
374 next INFO;
375 } # end if
376 if(!$info->{attribute}){
377 $doc{$doc_root}[$rootcnt]->{$current_xpath[0]}[0]->{$current_xpath[1]}[0]->{$current_xpath[2]}[0]->{content}.=$value;
378 next INFO;
379 }
380 } #if $path_cnt==3
381 ################################################
382  
383 } # end if $table_node eq doc_root
384  
385 } ## end INFO loop
386 ############ here we start to rconstruct the rest of our doc;
387 if(!%table_doc){next LOOPCNT;}
388 my $table_data=\%table_doc;
389  
390 if($table_pass{parent}->{hasone} eq "no"){
391 my @path=split m[/], $table_xpath;
392 my $path_cnt=scalar @path;
393 # we have no parent so lets just add the table our doc hash
394 my $depth=0;
395  
396 if($path_cnt == 1){
397  
398 if($doc{$the_root}[$rootcnt]->{$table_node}){$depth=scalar @{$doc{$the_root}[$rootcnt]->{$table_node}};}
399  
400 $doc{$doc_root}[$rootcnt]->{$table_node}[$depth]=$table_data;
401 next LOOPCNT;
402 }
403 if($path_cnt == 2){
404 if($doc{$the_root}[$rootcnt]->{$path[0]}[0]->{$table_node}){$depth=scalar @{$doc{$the_root}[$rootcnt]->{$path[0]}[0]->{$table_node}};}
405  
406 $doc{$doc_root}[$rootcnt]->{$path[0]}[0]->{$table_node}[$depth]=$table_data;
407 next LOOPCNT;
408 }
409  
410 if($path_cnt == 3){
411 if($doc{$the_root}[$rootcnt]->{$path[0]}[0]->{$path[1]}[0]->{$table_node}){
412 $depth=scalar @{$doc{$the_root}[$rootcnt]->{$path[0]}[0]->{$path[1]}[0]->{$table_node}};}
413 $doc{$doc_root}[$rootcnt]->{$path[0]}[0]->{$path[1]}[0]->{$table_node}[$depth]=$table_data;
414 next LOOPCNT;
415 }
416 if($path_cnt == 4){
417 if($doc{$the_root}[$rootcnt]->{$path[0]}[0]->{$path[1]}[0]->{$path[2]}[0]->{$table_node}){
418 $depth=scalar @{$doc{$the_root}[$rootcnt]->{$path[0]}[0]->{$path[1]}[0]->{$path[2]}[0]->{$table_node}};}
419  
420 $doc{$doc_root}[$rootcnt]->{$path[0]}[0]->{$path[1]}[0]->{$path[2]}[0]->{$table_node}[$lpcnt-1]=$table_data;
421 next LOOPCNT;
422 }
423 if($path_cnt == 5){
424 if($doc{$the_root}[$rootcnt]->{$path[0]}[0]->{$path[1]}[0]->{$path[2]}[0]->{$path[3]}[0]->{$table_node}){
425 $depth=scalar @{$doc{$the_root}[$rootcnt]->{$path[0]}[0]->{$path[1]}[0]->{$path[2]}[0]->{$path[3]}[0]->{$table_node}};}
426  
427 $doc{$doc_root}[$rootcnt]->{$path[0]}[0]->{$path[1]}[0]->{$path[2]}[0]->{$path[3]}[0]->{$table_node}[$lpcnt-1]=$table_data;
428 next LOOPCNT;
429 }
430 if($path_cnt == 6){
431 if($doc{$the_root}[$rootcnt]->{$path[0]}[0]->{$path[1]}[0]->{$path[2]}[0]->{$path[3]}[0]->{$path[4]}[0]->{$table_node}){
432 $depth=scalar @{$doc{$the_root}[$rootcnt]->{$path[0]}[0]->{$path[2]}[0]->{$path[1]}[0]->{$path[3]}[0]->{$path[4]}[0]->{$table_node}};}
433  
434 $doc{$doc_root}[$rootcnt]->{$path[0]}[0]->{$path[1]}[0]->{$path[2]}[0]->{$path[3]}[0]->{$path[4]}[0]->{$table_node}[$lpcnt-1]=$table_data;
435 next LOOPCNT;
436 }
437  
438  
439  
440 }
441  
442 ## below we try to find a xml segments parents
443 if($table_pass{parent}->{hasone} eq "yes"){
444  
445 my $xpath=$table_pass{parent}->{$lpcnt}->{xpath};
446 my $value=$table_pass{parent}->{$lpcnt}->{value};
447 my $node_type="content";
448 if($table_pass{parent}->{$lpcnt}->{attribute}){
449 $node_type=$table_pass{parent}->{$lpcnt}->{attribute};
450 }
451  
452  
453 my @xpath_array=split m[/], $xpath;
454 my $xpath_node=pop @xpath_array;
455 my $parent_node=unshift @xpath_array;
456 $parent_node=~s/parent:://;
457  
458 # here we check to see if this is a attribute or element content
459 my $element;
460 my $attribute;
461  
462 if($xpath_node !~ /\@/){$element=$xpath_node;}
463 if($xpath_node =~ /\@/){$attribute=$xpath_node;$attribute =~ s/\@//;}
464  
465 my @path=split m[/], $table_xpath;
466 my $table_node=pop @path;
467 my $path_cnt=scalar @path;
468  
469 my $p_node_location_cnt;
470 PNODE: for my $pnode (@path){
471 $p_node_location_cnt++;
472 if($pnode eq $parent_node){last PNODE;}
473 }
474  
475 if($path_cnt==1){
476  
477 if($doc{$the_root}[$rootcnt]->{$path[$path_cnt-1]}){
478 my $cnt;
479 # here we have a value so we loop through the nodes
480 for my $node (@{$doc{$the_root}[$rootcnt]->{$path[$path_cnt-1]}}){
481 my $depth=0;
482 if($doc{$the_root}[$rootcnt]->{$path[$path_cnt-1]}[$cnt-1]->{$tableroot}){
483 $depth=scalar @{$doc{$the_root}[$rootcnt]->{$path[$path_cnt-1]}[$cnt-1]->{$tableroot}};
484 }
485  
486 $cnt++;
487 my $node_type;
488 if($element){$node_type="content";}
489 if($attribute){$node_type=$attribute;}
490 if($node->{$node_type} eq $value){
491 #
492 # node found;
493 # $doc{$the_root}[$rootcnt]->{$path[$path_cnt-1]}[$cnt-1]
494 ## here we go ahead and add our table to this node
495 $doc{$the_root}[$rootcnt]->{$path[$path_cnt-1]}[$cnt-1]->{$tableroot}[$depth]=$table_data;
496 next LOOPCNT;
497 }
498
499 ## here we look ahead in the array for a value for the next item
500 if(!$doc{$the_root}[$rootcnt]->{$path[$path_cnt-1]}[$cnt]){
501 $doc{$the_root}[$rootcnt]->{$path[$path_cnt-1]}[$cnt]->{$node_type}=$value;
502 ## here we add the rest of the table stuff on
503 $doc{$the_root}[$rootcnt]->{$path[$path_cnt-1]}[$cnt]->{$tableroot}[0]=$table_data;
504 next LOOPCNT;
505  
506 }
507 }
508 }
509 if(!$doc{$the_root}[$rootcnt]->{$path[$path_cnt-1]}){
510 $doc{$the_root}[$rootcnt]->{$path[$path_cnt-1]}[0]->{$node_type}=$value;
511 $doc{$the_root}[$rootcnt]->{$path[$path_cnt-1]}[0]->{$tableroot}[0]=$table_data;
512 next LOOPCNT;
513 }
514 } # end if pacth_cnt == 1
515  
516 if($path_cnt == 2){
517 if(!$doc{$the_root}[$rootcnt]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}){
518 $doc{$the_root}[$rootcnt]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}[0]->{$node_type}=$value;
519 $doc{$the_root}[$rootcnt]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}[0]->{$tableroot}[0]=$table_data;
520 next LOOPCNT;
521 }
522 if($doc{$the_root}[$rootcnt]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}){
523  
524 my $cnt;
525 for my $node (@{$doc{$the_root}[$rootcnt]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}}){
526 $cnt++;
527 if($node->{$node_type} eq $value){
528 ## here we go ahead and add our table to this node
529 my $depth=0;
530 if($doc{$the_root}[$rootcnt]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}[$cnt-1]->{$tableroot}){
531 $depth=scalar @{$doc{$the_root}[$rootcnt]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}[$cnt-1]->{$tableroot}};
532 }
533  
534 $doc{$the_root}[$rootcnt]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}[$cnt-1]->{$tableroot}[$depth]=$table_data;
535 next LOOPCNT;
536 }
537 }
538  
539 if(!$doc{$the_root}[$rootcnt]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}[$cnt]){
540 $doc{$the_root}[$rootcnt]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}[$cnt]->{$node_type}=$value;
541 ## here we add the rest of the table stuff on
542 $doc{$the_root}[$rootcnt]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}[$cnt]->{$tableroot}[0]=$table_data;
543  
544 next LOOPCNT;
545 }
546  
547 }
548 } # end if ==2
549  
550 if($path_cnt == 3){
551 if(!$doc{$the_root}[$rootcnt]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}){
552 $doc{$the_root}[$rootcnt]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}[0]->{$node_type}=$value;
553 $doc{$the_root}[$rootcnt]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}[0]->{$tableroot}[0]=$table_data;
554 next LOOPCNT;
555 }
556 if($doc{$the_root}[$rootcnt]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}){
557 my $cnt;
558 for my $node (@{$doc{$the_root}[$rootcnt]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}}){
559 $cnt++;
560 if($node->{$node_type} eq $value){
561 my $depth=0;
562 if($doc{$the_root}[$rootcnt]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}[$cnt-1]->{$tableroot}){
563 $depth=scalar @{$doc{$the_root}[$rootcnt]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}[$cnt-1]->{$tableroot}};
564 }
565 $doc{$the_root}[$rootcnt]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}[$cnt-1]->{$tableroot}[$depth]=$table_data;
566 next LOOPCNT;
567 }
568 if(!$doc{$the_root}[$rootcnt]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}[$cnt]){
569 $doc{$the_root}[$rootcnt]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}[$cnt]->{$node_type}=$value;
570 ## here we add the rest of the table stuff on
571 $doc{$the_root}[$rootcnt]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}[$cnt]->{$tableroot}[0]=$table_data;
572 next LOOPCNT;
573 }
574 }
575 }
576 } # end if == 3
577  
578  
579 if($path_cnt == 4){
580 if(!$doc{$the_root}[$rootcnt]->{$path[$path_cnt-4]}[0]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}){
581 $doc{$the_root}[$rootcnt]->{$path[$path_cnt-4]}[0]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}[0]->{$node_type}=$value;
582 ## here we add the rest of the table stuff on
583 $doc{$the_root}[$rootcnt]->{$path[$path_cnt-4]}[0]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}[0]->{$tableroot}[0]=$table_data;
584 next LOOPCNT;
585 }
586  
587 if($doc{$the_root}[$rootcnt]->{$path[$path_cnt-4]}[0]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}){
588 my $cnt;
589 for my $node
590 (@{$doc{$the_root}[$rootcnt]->{$path[$path_cnt-4]}[0]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}}){
591 $cnt++;
592 if($node->{$node_type} eq $value){
593 my $depth=0;
594 if($doc{$the_root}[$rootcnt]->{$path[$path_cnt-4]}[0]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[$cnt-1]->{$tableroot}){
595 $depth=scalar @{$doc{$the_root}[$rootcnt]->{$path[$path_cnt-4]}[0]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[$cnt-1]->{$tableroot}};
596 }
597 $doc{$the_root}[$rootcnt]->{$path[$path_cnt-4]}[0]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[$cnt-1]->{$tableroot}[$depth]=$table_data;
598 next LOOPCNT;
599 }
600 if(!$doc{$the_root}[$rootcnt]->{$path[$path_cnt-4]}[0]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}[$cnt]){
601 $doc{$the_root}[$rootcnt]->{$path[$path_cnt-4]}[0]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}[$cnt]->{$node_type}=$value;
602 ## here we add the rest of the table stuff on
603 $doc{$the_root}[$rootcnt]->{$path[$path_cnt-4]}[0]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}[$cnt]->{$tableroot}[0]=$table_data;
604 next LOOPCNT;
605 }
606  
607 }
608 }
609 } # end if == 4
610  
611 if($path_cnt == 5){
612 if(!$doc{$the_root}[$rootcnt]->{$path[$path_cnt-5]}[0]->{$path[$path_cnt-4]}[0]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}){
613 $doc{$the_root}[$rootcnt]->{$path[$path_cnt-5]}[0]->{$path[$path_cnt-4]}[0]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}[0]->{$node_type}=$value;
614 ## here we add the rest of the table stuff on
615 $doc{$the_root}[$rootcnt]->{$path[$path_cnt-5]}[0]->{$path[$path_cnt-4]}[0]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}[0]->{$tableroot}[0]=$table_data;
616 next LOOPCNT;
617 }
618  
619  
620 if($doc{$the_root}[$rootcnt]->{$path[$path_cnt-5]}[0]->{$path[$path_cnt-4]}[0]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}){
621 my $cnt;
622 for my $node
623 (@{$doc{$the_root}[$rootcnt]->{$path[$path_cnt-5]}[0]->{$path[$path_cnt-4]}[0]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}}){
624 $cnt++;
625 if($node->{$node_type} eq $value){
626 my $depth=0;
627 if($doc{$the_root}[$rootcnt]->{$path[$path_cnt-5]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-1]}[$cnt-1]->{$tableroot}){
628 $depth=scalar
629 @{$doc{$the_root}[$rootcnt]->{$path[$path_cnt-5]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-1]}[$cnt-1]->{$tableroot}};
630 }
631 $doc{$the_root}[$rootcnt]->{$path[$path_cnt-5]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-1]}[$cnt-1]->{$tableroot}[$depth]=$table_data;
632 next LOOPCNT;
633 }
634 if(!$doc{$the_root}[$rootcnt]->{$path[$path_cnt-5]}[0]->{$path[$path_cnt-4]}[0]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}[$cnt]){
635 $doc{$the_root}[$rootcnt]->{$path[$path_cnt-5]}[0]->{$path[$path_cnt-4]}[0]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}[$cnt]->{$node_type}=$value;
636 ## here we add the rest of the table stuff on
637 $doc{$the_root}[$rootcnt]->{$path[$path_cnt-5]}[0]->{$path[$path_cnt-4]}[0]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}[$cnt]->{$tableroot}[0]=$table_data;
638 next LOOPCNT;
639 }
640  
641 }
642 }
643 } ## end if == 5
644  
645 if($path_cnt == 6){
646 if(!$doc{$the_root}[$rootcnt]->{$path[$path_cnt-6]}[0]->{$path[$path_cnt-5]}[0]->{$path[$path_cnt-4]}[0]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}){
647 $doc{$the_root}[$rootcnt]->{$path[$path_cnt-6]}[0]->{$path[$path_cnt-5]}[0]->{$path[$path_cnt-4]}[0]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}[0]->{$node_type}=$value;
648 ## here we add the rest of the table stuff on
649 $doc{$the_root}[$rootcnt]->{$path[$path_cnt-6]}[0]->{$path[$path_cnt-5]}[0]->{$path[$path_cnt-4]}[0]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}[0]->{$tableroot}[0]=$table_data;
650 next LOOPCNT;
651 }
652  
653 if($doc{$the_root}[$rootcnt]->{$path[$path_cnt-6]}[0]->{$path[$path_cnt-5]}[0]->{$path[$path_cnt-4]}[0]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}){
654 my $cnt;
655 # here we have a value so we loop through the nodes
656 for my $node
657 (@{$doc{$the_root}[$rootcnt]->{$path[$path_cnt-6]}[0]->{$path[$path_cnt-5]}[0]->{$path[$path_cnt-4]}[0]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}}){
658 $cnt++;
659 if($node->{$node_type} eq $value){
660 my $depth=0;
661 if($doc{$the_root}[$rootcnt]->{$path[$path_cnt-6]}[0]->{$path[$path_cnt-5]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-1]}[$cnt-1]->{$tableroot}){
662 $depth=scalar @{$doc{$the_root}[$rootcnt]->{$path[$path_cnt-6]}[0]->{$path[$path_cnt-5]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-1]}[$cnt-1]->{$tableroot}};
663 }
664 $doc{$the_root}[$rootcnt]->{$path[$path_cnt-6]}[0]->{$path[$path_cnt-5]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-1]}[$cnt-1]->{$tableroot}[$depth]=$table_data;
665 next LOOPCNT;
666 }
667 if(!$doc{$the_root}[$rootcnt]->{$path[$path_cnt-6]}[0]->{$path[$path_cnt-5]}[0]->{$path[$path_cnt-4]}[0]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}[$cnt]){
668 $doc{$the_root}[$rootcnt]->{$path[$path_cnt-6]}[0]->{$path[$path_cnt-5]}[0]->{$path[$path_cnt-4]}[0]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}[$cnt]->{$node_type}=$value;
669 ## here we add the rest of the table stuff on
670 $doc{$the_root}[$rootcnt]->{$path[$path_cnt-6]}[0]->{$path[$path_cnt-5]}[0]->{$path[$path_cnt-4]}[0]->{$path[$path_cnt-3]}[0]->{$path[$path_cnt-2]}[0]->{$path[$path_cnt-1]}[$cnt]->{$tableroot}[0]=$table_data;
671 next LOOPCNT;
672 }
673 }
674 }
675 } # end if ==6
676  
677 }
678 } # end lpcnt;
679 } # end if all_data
680 } # end keys (ie table level loop)
681  
682 my $thexml;
683 if($rootcnt <= 0){
684 my $xmldoc=\%doc;
685 $thexml=$parser->XMLout($xmldoc,
686 xmldecl=>qq[
687 <!-- document created using XMLWriter $VERSION at $date -->]);
688 }
689 if($rootcnt > 0){
690 my $xmldoc=\%doc;
691 my %predoc;
692 $predoc{MultiQueryDoc}->{content}="\n".$parser->XMLout($xmldoc);
693 $xmldoc=\%predoc;
694 $thexml=$parser->XMLout($xmldoc,
695 xmldecl=>qq[<?xml version='1.0' standalone='yes'?>\n
696 <!-- document created using XMLWriter $VERSION at $date -->]);
697 }
698  
699 return($thexml);
700  
701 #############
702 } # end sub makexml
703 ######################
704  
705 1;
706  
707 __END__