From 20d91d61a4e7dd8fdf86e7e3ec661099726a6542 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Thu, 9 Feb 2023 12:17:03 +0800 Subject: [PATCH] add xmlns wp --- empty.go | 5 +++-- structdoc.go | 6 ++++-- structdoc_test.go | 2 ++ structrun.go | 8 ++++---- unpack.go | 1 + 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/empty.go b/empty.go index d0f47c0..d4be923 100644 --- a/empty.go +++ b/empty.go @@ -8,8 +8,9 @@ func newEmptyFile() *Docx { XMLName: xml.Name{ Space: "w", }, - XMLW: XMLNS_W, - XMLR: XMLNS_R, + XMLW: XMLNS_W, + XMLR: XMLNS_R, + XMLWP: XMLNS_WP, Body: &Body{ XMLName: xml.Name{ Space: "w", diff --git a/structdoc.go b/structdoc.go index 5d71039..7bc3a38 100644 --- a/structdoc.go +++ b/structdoc.go @@ -3,8 +3,9 @@ package docxlib import "encoding/xml" const ( - XMLNS_W = `http://schemas.openxmlformats.org/wordprocessingml/2006/main` - XMLNS_R = `http://schemas.openxmlformats.org/officeDocument/2006/relationships` + XMLNS_W = `http://schemas.openxmlformats.org/wordprocessingml/2006/main` + XMLNS_R = `http://schemas.openxmlformats.org/officeDocument/2006/relationships` + XMLNS_WP = `http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing` ) type Body struct { @@ -16,5 +17,6 @@ type Document struct { XMLName xml.Name `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main document"` XMLW string `xml:"xmlns:w,attr"` XMLR string `xml:"xmlns:r,attr"` + XMLWP string `xml:"xmlns:wp,attr"` Body *Body } diff --git a/structdoc_test.go b/structdoc_test.go index 194b5a0..3cb1e68 100644 --- a/structdoc_test.go +++ b/structdoc_test.go @@ -12,6 +12,7 @@ func TestPlainStructure(t *testing.T) { doc := Document{ XMLW: XMLNS_W, XMLR: XMLNS_R, + XMLWP: XMLNS_WP, XMLName: xml.Name{Space: XMLNS_W, Local: "document"}} testCases := []struct { content string @@ -515,6 +516,7 @@ func TestDrawingStructure(t *testing.T) { doc := Document{ XMLW: XMLNS_W, XMLR: XMLNS_R, + XMLWP: XMLNS_WP, XMLName: xml.Name{Space: XMLNS_W, Local: "document"}} err := xml.Unmarshal(StringToBytes(drawing_doc), &doc) if err != nil { diff --git a/structrun.go b/structrun.go index ca10f40..5606b70 100644 --- a/structrun.go +++ b/structrun.go @@ -42,10 +42,10 @@ type Drawing struct { // WPInline wp:inline type WPInline struct { XMLName xml.Name `xml:"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing inline,omitempty"` - DistT string `xml:"wp:distT,attr"` - DistB string `xml:"wp:distB,attr"` - DistL string `xml:"wp:distL,attr"` - DistR string `xml:"wp:distR,attr"` + DistT string `xml:"distT,attr"` + DistB string `xml:"distB,attr"` + DistL string `xml:"distL,attr"` + DistR string `xml:"distR,attr"` } // RunProperties encapsulates visual properties of a run diff --git a/unpack.go b/unpack.go index 2616fae..de8493c 100644 --- a/unpack.go +++ b/unpack.go @@ -39,6 +39,7 @@ func processDoc(file *zip.File, doc *Document) error { doc.XMLW = XMLNS_W doc.XMLR = XMLNS_R + doc.XMLWP = XMLNS_WP doc.XMLName.Space = XMLNS_W doc.XMLName.Local = "document" err = xml.Unmarshal(filebytes, doc)