osdir.com
mailing list archive

Subject: Re: XML::XPath How save tree to file? - msg#00077

List: lang.perl.xml

Date: Prev Next Index Thread: Prev Next Index
Grant McLean <grant@xxxxxxxxxxxxx> wrote:

print $xmlTree->toString;

This produces the error:
Can't locate object method "toString" via package "XML::XPath"
at E:\Martin\Perl\spreadit.pl line 174.

This behaviour agrees with the docs for XPath as "toString" is
not part of the API.

I tried:
my $nodeSet = $xmlTree->find("/");
print(outFile $nodeSet->to_literal());

and
my $nodeSet = $xmlTree->find("/");
print(outFile $nodeSet->string_value());

but they both just write "unknown".

What I am looking for is something that writes something
similar to:
<metadata><idinfo><spdom><bounding><westbc>
unknown
</westbc></bounding></spdom></idinfo></metadata>

Many thanks for any help you can give. I have repeated my
original post below so you can see where "unknown" comes
from.

Regards,
Martin

Martin Leese <geomatics@xxxxxxxxxxxxx> wrote:
> Hi,
>
> I am using XPath to create an XML tree. Everything works
> except that I can't work out how I am supposed to save the
> thing to a file. I tried:
>
> print(outFile $xmlTree);
>
> but this writes "XML::XPath=HASH(0x1d413c4)" to the file.
> I want the file to contain the XML tags. What am I missing
> here?
>
> Also, while you are here, what is the difference between
> "use warnings;" and "use diagnostics;"?
>
> I am running perl, v5.8.2 built for MSWin32-x86-multi-thread,
> Binary build 808 provided by ActiveState Corp. under Windows
> NT. I have installed XML-XPath [1.12].
>
> Here is a test script to illustrate what I am trying to do:
>
> #! /usr/local/bin/perl
> #
> use XML::XPath;
> use XML::XPath::XMLParser;
> #
> use strict;
> use warnings;
> ###use diagnostics;
> #
> # Create empty XML tree
> my $xmlTree = XML::XPath->new(xml => "<metadata></metadata>");
> #
> # Load spreadsheet cells into XML tree
> my $path = "/metadata/idinfo/spdom/bounding/westbc";
> if ( ! $xmlTree->exists($path) )
> {
> $xmlTree->createNode($path);
> }
> $xmlTree->setNodeText($path, "unknown");
> #
> # Test tree (one good, one undefined)
> $path = "/metadata/idinfo/spdom/bounding/westbc";
> print "$path = \"", $xmlTree->getNodeText($path), "\"\n";
> $path = "/metadata/idinfo/spdom/bounding/eastbc";
> print "$path = \"", $xmlTree->getNodeText($path), "\"\n";
> #
> # Open XML output file or die
> my $outName = "test.xml";
> open(outFile, "> $outName") or die "Can't open $outName : $!";
> #
> # Write XML tree to file
> ################ What goes in here? ####################
> print(outFile $xmlTree);
> #
> # Close XML output file
> close(outFile);
> #
> exit(0);
>
> Many thanks for any help you can give.
>
> Regards,
> Martin



_______________________________________________
Perl-XML mailing list
Perl-XML@xxxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs



Was this page helpful?
Yes No
Thread at a glance:

Previous Message by Date: click to view message preview

RE: [perlxml] Re: Complex relational database output to XML

Matt, Haven't seen XML::Generator::DBI before and decided to give it a try. However: #!/usr/local/bin/perl use XML::Generator::DBI; use XML::SAX::Writer; use DBI; my $dbh = DBI->connect("dbi:ODBC:test", "Martin_Evans", "easysoft"); my $sth = $dbh->prepare("select * from bench_char"); my $generator = XML::Generator::DBI->new( Handler => XML::SAX::Writer->new(), ShowColumns=>1 ); $generator->execute($sth); Produces: [martin@brimer /tmp]$ ./x.pl Can't call method "type_info" on unblessed reference at /usr/local/lib/perl5/site_perl/5.8.0/XML/Generator/DBI.pm line 293. <database xmlns:dbi='http://axkit.org/NS/xml-generator-dbi'><select>[martin@brimer /tmp]$ perl -e 'use DBD::ODBC; print $DBD::ODBC::VERSION;' 1.05 perl -e 'use DBI;print $DBI::VERSION;' 1.40 perl --version This is perl, v5.8.0 built for i686-linux Any ideas? Martin -- Martin J. Evans Easysoft Ltd, UK Development On 22-Feb-2004 Matt Sergeant wrote: > ----- Original Message ----- > From: "Birgit Kellner" <birgit.kellner@xxxxxxxxxxxx> > > >> I am looking for ways to convert complex relational database output into >> XML files. For instance, bibliographical information may be stored in a >> bibliography database across several tables, so that retrieving a record >> for, say, an article in a proceedings volume might involve more than one >> query. >> >> I took a look at DBIx::XML_RDB, but this seems to work only with a >> single sql query. >> >> I suppose I would have to construct a data structure within perl and >> then write that to an XML file. But are there any modules that might >> make my life easier? Which ones would you recommend? I'm trying this >> with Oracle, by the way. > > You want XML::Generator::DBI. It does exactly what you want (and probably > more). > > Matt. > > _______________________________________________ > Perl-XML mailing list > Perl-XML@xxxxxxxxxxxxxxxxxxxxxxxx > To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs _______________________________________________ Perl-XML mailing list Perl-XML@xxxxxxxxxxxxxxxxxxxxxxxx To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Next Message by Date: click to view message preview

Re: XML::XPath How save tree to file?

Martin Leese wrote: This behaviour agrees with the docs for XPath as "toString" is not part of the API. I tried: my $nodeSet = $xmlTree->find("/"); print(outFile $nodeSet->to_literal()); and my $nodeSet = $xmlTree->find("/"); print(outFile $nodeSet->string_value()); Have you tried: my $nodeSet = $xmlTree->find("/"); print $nodeSet->get_node(1)->toString; ? Otherwise, all nodes also have a to_sax() method to which you could feed an XML::SAX::Writer object. -- Robin Berjon _______________________________________________ Perl-XML mailing list Perl-XML@xxxxxxxxxxxxxxxxxxxxxxxx To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Previous Message by Thread: click to view message preview

Complex relational database output to XML

Hello, I am looking for ways to convert complex relational database output into XML files. For instance, bibliographical information may be stored in a bibliography database across several tables, so that retrieving a record for, say, an article in a proceedings volume might involve more than one query. I took a look at DBIx::XML_RDB, but this seems to work only with a single sql query. I suppose I would have to construct a data structure within perl and then write that to an XML file. But are there any modules that might make my life easier? Which ones would you recommend? I'm trying this with Oracle, by the way. Thanks, Birgit Kellner _______________________________________________ Perl-XML mailing list Perl-XML@xxxxxxxxxxxxxxxxxxxxxxxx To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Next Message by Thread: click to view message preview

Re: XML::XPath How save tree to file?

Martin Leese wrote: This behaviour agrees with the docs for XPath as "toString" is not part of the API. I tried: my $nodeSet = $xmlTree->find("/"); print(outFile $nodeSet->to_literal()); and my $nodeSet = $xmlTree->find("/"); print(outFile $nodeSet->string_value()); Have you tried: my $nodeSet = $xmlTree->find("/"); print $nodeSet->get_node(1)->toString; ? Otherwise, all nodes also have a to_sax() method to which you could feed an XML::SAX::Writer object. -- Robin Berjon _______________________________________________ Perl-XML mailing list Perl-XML@xxxxxxxxxxxxxxxxxxxxxxxx To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Sign up for updates to this mailing list. email:
Loading Comments...
Home | News | Patents | Sitemap | FAQ | advertise

Advertising by