1
0
mirror of https://github.com/fumiama/go-docx.git synced 2026-06-08 01:00:25 +08:00

add xmlns wp

This commit is contained in:
源文雨
2023-02-09 12:17:03 +08:00
parent ae07360d5e
commit 20d91d61a4
5 changed files with 14 additions and 8 deletions

View File

@@ -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",

View File

@@ -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
}

View File

@@ -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 {

View File

@@ -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

View File

@@ -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)