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