XSDSQL

 view release on metacpan or  search on metacpan

lib/blx/xsdsql/xml/reader.pm  view on Meta::CPAN

	my $tag=delete $params{TAG};
	my $column=$self->{SCHEMA}->resolve_column_link($t1,$t2,%params);
	if ($self->{DEBUG}) {
		$self->_debug($tag,$column->get_full_name,' => '.$t2->get_sql_name);	
	}
	$column;
}

sub _get_prepared_insert {
	my ($self,$tag,%params)=@_;
	$tag=$tag->get_sql_name if ref($tag) =~/::table$/;
	affirm { ref($tag) eq '' } "not a string or table";
	$self->{PREPARED}->{$tag}->{INSERT};
}

sub _bind_node_attrs {
	my ($self,$prep,$attrs,%params)=@_;
	my $table=$prep->get_binding_table;
	my @keys=keys %$attrs;
	my @cols=$self->{SCHEMA}->resolve_attributes($table,$self->{NSPREFIXES},@keys);
	for my $i(0..scalar(@cols) - 1) {
		my $col=$cols[$i];
		if (defined $col) {
			$prep->bind_column($col,$attrs->{$keys[$i]},%params);
		}
		else { # is system attribute
			my $col=$table->get_sysattrs_column;
			my $v=$keys[$i].'="'.$attrs->{$keys[$i]}.'"';
			$prep->bind_column($col,$v,%params,APPEND => 1,SEP => ' ');			
		}
	}
	$self;
}

sub _find_namespace_from_abbr {
	my ($self,$ns,%params)=@_;
	affirm { defined $ns } "1^ param not set";
	my $uri=$self->{NSPREFIXES}->{$ns};
	$self->_debug(undef,"$ns: no such namespace (URI) from this namespace abbr") unless defined $uri;
	$uri;
}

sub new {
	my ($class,%params)=@_;
	affirm { defined $params{BINDING} } 'param BINDING not set';
	affirm { defined $params{SCHEMA} } 'param SCHEMA not set';
	affirm { defined $params{EXTRA_TABLES} } 'param EXTRA_TABLES not set';
	
	$params{PARSER}=XML::Parser->new unless defined $params{PARSER};
	$params{PARSER}->setHandlers(
									Start 			=> \&_start_node
									,End 			=> \&_end_node
									,Char 			=> \&_char_node
									,Doctype 		=> \&_doctype_node
									,Notation 		=> \&_notation_node
									,Entity			=> \&_entity_node
									,Element		=> \&_element_node
									,Attlist		=> \&_attlist_node
									,ExternEnt 		=> \&_externent_node
									,DoctypeFin		=> \&_doctypefin_node
#									,CDataStart		=> \&_cdatastart_node
									,XMLDecl 		=> \&_xmldecl_node 
	);
	$class->SUPER::_new(%params);
}

sub read {
	my ($self,%params)=@_;
	$self->{BINDING}->set_attrs_value(SEQUENCE_NAME => $self->{EXTRA_TABLES}->get_sequence_name)
		unless defined $self->{BINDING}->get_attrs_value(qw(SEQUENCE_NAME)); 
	$self->{STACK}=[];
	$self->{ID}=undef;
	$self->{_ROOT_ID}=$self->{BINDING}->get_next_sequence;
	my $fd=nvl($params{FD},*STDIN); 
	$self->{PARSER}->parse($fd,LOAD_INSTANCE => $self);
	$self->{BINDING}->finish(TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
	my $id=delete $self->{ID};
	affirm { defined $id } "returning id not set"; 
	affirm { $id == $self->{_ROOT_ID}} "returning id is not equal at initialization"; 
	delete $self->{_ROOT_ID};
	delete $self->{STACK};
	my $table=$self->{EXTRA_TABLES}->get_extra_table(qw(XML_ENCODING));
	my $n=$self->{BINDING}->insert_row_from_generic(
				$table
				,[$id,$self->{_XMLDECL}->[1]]
				,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__}
	);
	$self->{BINDING}->finish(TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});	
	affirm { defined $n && $n == 1 } "the rows inserted is not 1";
	$id;
}




1;



__END__

=head1  NAME

blx::xsdsql::xml::reader - internal class - read an xml file and put into a database

=cut


=head1 VERSION

0.10.0

=cut



=head1 BUGS

Please report any bugs or feature requests to https://rt.cpan.org/Public/Bug/Report.html?Queue=XSDSQL

=cut



( run in 2.375 seconds using v1.01-cache-2.11-cpan-995e09ba956 )