Difference between revisions of "Talk:ZIP Module: Word Documents"

From BaseX Documentation
Jump to navigation Jump to search
Line 6: Line 6:
  
  
declare namespace zip = "http://expath.org/ns/zip";
+
declare namespace zip ="http://expath.org/ns/zip";
  
declare namespace office =  
+
declare namespace office ="urn:oasis:names:tc:opendocument:xmlns:office:1.0";
"urn:oasis:names:tc:opendocument:xmlns:office:1.0";
 
  
declare namespace dc =
+
declare namespace dc ="http://purl.org/dc/elements/1.1/";
  "http://purl.org/dc/elements/1.1/";
+
declare namespace text ="urn:oasis:names:tc:opendocument:xmlns:text:1.0";
declare namespace text =
+
declare namespace table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" ;
  "urn:oasis:names:tc:opendocument:xmlns:text:1.0";
 
  declare namespace table=
 
  "urn:oasis:names:tc:opendocument:xmlns:table:1.0" ;
 
 
    
 
    
 
declare variable $input := "E:/pop.ods";
 
declare variable $input := "E:/pop.ods";
Line 24: Line 20:
 
let $modified:= copy $f:=zip:xml-entry($input, "content.xml")
 
let $modified:= copy $f:=zip:xml-entry($input, "content.xml")
 
   modify (for $d in $f
 
   modify (for $d in $f
for $t in $d//text:p[text()="Year"] return replace value of node $t with "ca roule") return $f
+
  for $t in $d//text:p[text()="Year"] return replace value of node $t with "ca roule")  
 +
  return $f
  
  

Revision as of 11:07, 5 August 2011

I have created an example to modify Libre Office documents the same way as Office 2007 documents. It's mainly working, still some problems appear:

- if "content.xml" is too big (for example 250 ko) baseX raises a java StackOverflow error...

- when you open your result document Test.ods, Libre Office tells you that the document is corruptes but it is able to repair it and you end up with the right document. Still it's not very elegant.


declare namespace zip ="http://expath.org/ns/zip";

declare namespace office ="urn:oasis:names:tc:opendocument:xmlns:office:1.0";

declare namespace dc ="http://purl.org/dc/elements/1.1/"; declare namespace text ="urn:oasis:names:tc:opendocument:xmlns:text:1.0"; declare namespace table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" ;

declare variable $input := "E:/pop.ods"; declare variable $output := "E:/Test.ods";


let $modified:= copy $f:=zip:xml-entry($input, "content.xml")

 modify (for $d in $f
 for $t in $d//text:p[text()="Year"] return replace value of node $t with "ca roule") 
 return $f


let $target :=

 copy $r := zip:entries($input)
 modify
   insert node $modified into $r//zip:entry[@name="content.xml"]
 return $r

return zip:update-entries($target, $output)