David Evans wrote:
Hi Mark
Thank you for that advice but what I am looking for is a file of all of
the coordinates so that I could do additional things with them outside
openoffice.
I am using this for architectural work as an alternative to autocad.
Clients love the colour coding it enables.
I've just put the appended perl script together. No pretenses about good
coding, and it makes probably unwarranted assumptions about the xml file
structure. It prints a list of the straight lines in a drawing as
x1 y1 x2 y2 text
tab separated.
No concessions to weird characters or xml quirks, but gives a flavour of
what a naive approach to xml parsing can do. May offer ideas at least.
(You may have trouble with line wrap; in particular the text starting
"$xml =~ " is supposed to be a single line). Oh, usual disclaimer -
supplied as-is, no warranty, check it yourself, use at own risk, don't
blame me if your computer blows up or the world comes to an end :-)
#!/usr/bin/perl -w
use Archive::Zip;
use Archive::Zip::MemberRead;
die "no file given\n" unless $ARGV[0];
# load the xml into one long string
$zip = Archive::Zip->new($ARGV[0]) or die "ooops!\n";
$fh = Archive::Zip::MemberRead->new($zip, "content.xml") or die "no
content.xml\n";
my $xml = '';
while (defined(my $line = $fh->getline())) {
$xml .= ' ' . $line;
}
$fh->close();
# parse out the lines and print the coordinate
while(1) {
$xml =~ m~<draw:line[^>]+?svg:x1="([^"]+?)" svg:y1="([^"]+?)"
svg:x2="([^"]+?)"
svg:y2="([^"]+?)"><text:p[^>]+>([^<]*?)</text:p></draw:line>(.*)$~ or last;
##<draw:line draw:style-name="gr1" draw:text-style-name="P2"
draw:layer="layout" svg:x1="7cm" svg:y1="18cm" svg:x2="16cm"
svg:y2="12.5cm"><text:p text:style-name="P1">Line two</text:p></draw:line>
print "$1\t$2\t$3\t$4\t$5\n";
$xml = $6;
}
--
Mike Scott mike <at> <removeme>.scottsonline.org.uk
Harlow Essex England
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]