1
0
mirror of https://github.com/fumiama/go-docx.git synced 2026-06-12 11:40:28 +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{ XMLName: xml.Name{
Space: "w", Space: "w",
}, },
XMLW: XMLNS_W, XMLW: XMLNS_W,
XMLR: XMLNS_R, XMLR: XMLNS_R,
XMLWP: XMLNS_WP,
Body: &Body{ Body: &Body{
XMLName: xml.Name{ XMLName: xml.Name{
Space: "w", Space: "w",

View File

@@ -3,8 +3,9 @@ package docxlib
import "encoding/xml" import "encoding/xml"
const ( const (
XMLNS_W = `http://schemas.openxmlformats.org/wordprocessingml/2006/main` XMLNS_W = `http://schemas.openxmlformats.org/wordprocessingml/2006/main`
XMLNS_R = `http://schemas.openxmlformats.org/officeDocument/2006/relationships` XMLNS_R = `http://schemas.openxmlformats.org/officeDocument/2006/relationships`
XMLNS_WP = `http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing`
) )
type Body struct { type Body struct {
@@ -16,5 +17,6 @@ type Document struct {
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main document"` XMLName xml.Name `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main document"`
XMLW string `xml:"xmlns:w,attr"` XMLW string `xml:"xmlns:w,attr"`
XMLR string `xml:"xmlns:r,attr"` XMLR string `xml:"xmlns:r,attr"`
XMLWP string `xml:"xmlns:wp,attr"`
Body *Body Body *Body
} }

View File

@@ -12,6 +12,7 @@ func TestPlainStructure(t *testing.T) {
doc := Document{ doc := Document{
XMLW: XMLNS_W, XMLW: XMLNS_W,
XMLR: XMLNS_R, XMLR: XMLNS_R,
XMLWP: XMLNS_WP,
XMLName: xml.Name{Space: XMLNS_W, Local: "document"}} XMLName: xml.Name{Space: XMLNS_W, Local: "document"}}
testCases := []struct { testCases := []struct {
content string content string
@@ -515,6 +516,7 @@ func TestDrawingStructure(t *testing.T) {
doc := Document{ doc := Document{
XMLW: XMLNS_W, XMLW: XMLNS_W,
XMLR: XMLNS_R, XMLR: XMLNS_R,
XMLWP: XMLNS_WP,
XMLName: xml.Name{Space: XMLNS_W, Local: "document"}} XMLName: xml.Name{Space: XMLNS_W, Local: "document"}}
err := xml.Unmarshal(StringToBytes(drawing_doc), &doc) err := xml.Unmarshal(StringToBytes(drawing_doc), &doc)
if err != nil { if err != nil {

View File

@@ -42,10 +42,10 @@ type Drawing struct {
// WPInline wp:inline // WPInline wp:inline
type WPInline struct { type WPInline struct {
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing inline,omitempty"` XMLName xml.Name `xml:"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing inline,omitempty"`
DistT string `xml:"wp:distT,attr"` DistT string `xml:"distT,attr"`
DistB string `xml:"wp:distB,attr"` DistB string `xml:"distB,attr"`
DistL string `xml:"wp:distL,attr"` DistL string `xml:"distL,attr"`
DistR string `xml:"wp:distR,attr"` DistR string `xml:"distR,attr"`
} }
// RunProperties encapsulates visual properties of a run // 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.XMLW = XMLNS_W
doc.XMLR = XMLNS_R doc.XMLR = XMLNS_R
doc.XMLWP = XMLNS_WP
doc.XMLName.Space = XMLNS_W doc.XMLName.Space = XMLNS_W
doc.XMLName.Local = "document" doc.XMLName.Local = "document"
err = xml.Unmarshal(filebytes, doc) err = xml.Unmarshal(filebytes, doc)