Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
Excelize
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Operations
Operations
Metrics
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Globars Forks
Excelize
Commits
13e7bce6
Unverified
Commit
13e7bce6
authored
Jul 20, 2020
by
xuri
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improvement compatibility for the XML ignorable namespace
parent
ca43c651
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
5 deletions
+24
-5
lib.go
lib.go
+16
-5
lib_test.go
lib_test.go
+8
-0
No files found.
lib.go
View file @
13e7bce6
...
...
@@ -379,14 +379,14 @@ func (f *File) replaceNameSpaceBytes(path string, contentMarshal []byte) []byte
func
(
f
*
File
)
addNameSpaces
(
path
string
,
ns
xml
.
Attr
)
{
exist
:=
false
mc
:=
false
ignore
:=
false
ignore
:=
-
1
if
attr
,
ok
:=
f
.
xmlAttr
[
path
];
ok
{
for
_
,
attribute
:=
range
attr
{
for
i
,
attribute
:=
range
attr
{
if
attribute
.
Name
.
Local
==
ns
.
Name
.
Local
&&
attribute
.
Name
.
Space
==
ns
.
Name
.
Space
{
exist
=
true
}
if
attribute
.
Name
.
Local
==
"Ignorable"
&&
attribute
.
Name
.
Space
==
"mc"
{
ignore
=
true
if
attribute
.
Name
.
Local
==
"Ignorable"
&&
getXMLNamespace
(
attribute
.
Name
.
Space
,
attr
)
==
"mc"
{
ignore
=
i
}
if
attribute
.
Name
.
Local
==
"mc"
&&
attribute
.
Name
.
Space
==
"xmlns"
{
mc
=
true
...
...
@@ -398,12 +398,23 @@ func (f *File) addNameSpaces(path string, ns xml.Attr) {
if
!
mc
{
f
.
xmlAttr
[
path
]
=
append
(
f
.
xmlAttr
[
path
],
SourceRelationshipCompatibility
)
}
if
!
ignore
{
if
ignore
==
-
1
{
f
.
xmlAttr
[
path
]
=
append
(
f
.
xmlAttr
[
path
],
xml
.
Attr
{
Name
:
xml
.
Name
{
Local
:
"Ignorable"
,
Space
:
"mc"
},
Value
:
ns
.
Name
.
Local
,
})
return
}
f
.
setIgnorableNameSpace
(
path
,
ignore
,
ns
)
}
}
// setIgnorableNameSpace provides a function to set XML namespace as ignorable by the given
// attribute.
func
(
f
*
File
)
setIgnorableNameSpace
(
path
string
,
index
int
,
ns
xml
.
Attr
)
{
ignorableNS
:=
[]
string
{
"c14"
,
"cdr14"
,
"a14"
,
"pic14"
,
"x14"
,
"xdr14"
,
"x14ac"
,
"dsp"
,
"mso14"
,
"dgm14"
,
"x15"
,
"x12ac"
,
"x15ac"
,
"xr"
,
"xr2"
,
"xr3"
,
"xr4"
,
"xr5"
,
"xr6"
,
"xr7"
,
"xr8"
,
"xr9"
,
"xr10"
,
"xr11"
,
"xr12"
,
"xr13"
,
"xr14"
,
"xr15"
,
"x15"
,
"x16"
,
"x16r2"
,
"mo"
,
"mx"
,
"mv"
,
"o"
,
"v"
}
if
inStrSlice
(
strings
.
Fields
(
f
.
xmlAttr
[
path
][
index
]
.
Value
),
ns
.
Name
.
Local
)
==
-
1
&&
inStrSlice
(
ignorableNS
,
ns
.
Name
.
Local
)
!=
-
1
{
f
.
xmlAttr
[
path
][
index
]
.
Value
=
strings
.
TrimSpace
(
fmt
.
Sprintf
(
"%s %s"
,
f
.
xmlAttr
[
path
][
index
]
.
Value
,
ns
.
Name
.
Local
))
}
}
...
...
lib_test.go
View file @
13e7bce6
package
excelize
import
(
"encoding/xml"
"fmt"
"strconv"
"strings"
...
...
@@ -215,6 +216,13 @@ func TestBytesReplace(t *testing.T) {
assert
.
EqualValues
(
t
,
s
,
bytesReplace
(
s
,
[]
byte
{},
[]
byte
{},
0
))
}
func
TestSetIgnorableNameSpace
(
t
*
testing
.
T
)
{
f
:=
NewFile
()
f
.
xmlAttr
[
"xml_path"
]
=
[]
xml
.
Attr
{{}}
f
.
setIgnorableNameSpace
(
"xml_path"
,
0
,
xml
.
Attr
{
Name
:
xml
.
Name
{
Local
:
"c14"
}})
assert
.
EqualValues
(
t
,
"c14"
,
f
.
xmlAttr
[
"xml_path"
][
0
]
.
Value
)
}
func
TestStack
(
t
*
testing
.
T
)
{
s
:=
NewStack
()
assert
.
Equal
(
t
,
s
.
Peek
(),
nil
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment