Baruch Even a écrit :
* Adolfo Pachón <[EMAIL PROTECTED]> [010525 18:05]:
> hi all
>
> I'm looking for the manner of generate XML output from Lyx/Latex. I love Lyx,
> and i won't prescind it to write documents.

LyX cannot export to XML right now, it probably is possible to add such
support but none is currently being worked on.
 

Yes, there is no direct XML output available, but it is really easy to have XML from DocBook SGML.

With the attached file, you can have direct XML export format from lyx by adding the following in the preference file:

\format "xml" "xml" "XML" ""
...
\converter "docbook" "xml" "/(full path)/sgml2xml.pl $$i" ""

To use it, you must change the $system path to your XML DocBook DTD.

BG
 
  #!/usr/bin/perl eval 'exec /usr/bin/perl -S $0 ${1+"$@"}' if $running_under_some_shell; use File::Basename; # To fix: how to retrieve this information? $system = ' SYSTEM "file:///home/ben/share/archives/docbook/docbkx412/docbookx.dtd"'; sub parse_sgml { local($sgmlfile) = $_[0]; local($xmlfile) = $_[1]; local($noheader) = $_[2]; my $line = ""; my $file = ""; my $SGML = "f$sgmlfile"; my $XML = "f$xmlfile"; print "$sgmlfile -> $xmlfile\n"; if (-f $xmlfile) { print "***Warning: $xmlfile already exists\n"; system("mv $xmlfile $xmlfile~"); } open($SGML, "<$sgmlfile") || die "Cannot open $sgmlfile\n"; open($XML, ">$xmlfile") || die "Cannot open $xmlfile\n"; while (<$SGML>) { $line = $_; if ((/doctype/ || /DOCTYPE/) && $noheader == 0) { # Change the file header $line =~ s/doctype ([a-z]*) .*\"/DOCTYPE $1 $system/; $line =~ s/DOCTYPE ([a-z]*) .*\"/DOCTYPE $1 $system/; # Print first the XML head print $XML ''; print $XML "\n$line"; $noheader++; } else { $line =~ s/�/\à/g; $line =~ s/�/\é/g; $line =~ s/�/\ê/g; $line =~ s/�/\è/g; $line =~ s/�/\î/g; $line =~ s/�/\ô/g; $line =~ s/�/\ù/g; $line =~ s/�/\û/g; $line =~ s/�/\ü/g; $line =~ s/�/\ç/g; # Case of included files if (/ENTITY.*\.sgml/) { # Get the included file name ($file = $line) =~ s/.*\"(.*)\.sgml\".*\n/$1/; # Output follow the main output path $outfile = dirname($xmlfile) . "/$file"; # Now the included file is the XML one $line =~ s/(.*)\"(.*)\.sgml\"/$1\"$outfile.xml\"/; # Relative or absolute path? if (not($file =~ /^\//)) { $file = dirname($sgmlfile) . "/$file"; } # The included files need not header parse_sgml("$file.sgml", "$outfile.xml", 1); } print $XML $line; } } close($SGML); close($XML); } # # Script start # if (not(@ARGV)) { print "$0 input.sgml [output.xml]\n"; exit 1; } $sgmlfile = $ARGV[0]; $xmlfile = basename($sgmlfile, '.sgml'); $xmlfile = dirname($sgmlfile). "/$xmlfile.xml"; shift; if (@ARGV) { $xmlfile = $ARGV[0]; } parse_sgml($sgmlfile, $xmlfile, 0);

Reply via email to