Implement text nodes / content escaping
This removes the support for re-indenting XML, but allows to faithfully parse / stringify a document. Beautification could be added again later on if desired.
This commit is contained in:
parent
08c0943149
commit
b3124cf4a7
4 changed files with 57 additions and 39 deletions
29
xmlx_test.go
29
xmlx_test.go
|
@ -137,7 +137,7 @@ func TestUnmarshal(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestString(t *testing.T) {
|
||||
func TestStringNamespaces(t *testing.T) {
|
||||
doc := New()
|
||||
err := doc.LoadFile("test3.xml", nil)
|
||||
|
||||
|
@ -147,11 +147,11 @@ func TestString(t *testing.T) {
|
|||
}
|
||||
|
||||
expected := `<root xmlns:foo="http:/example.org/foo">
|
||||
<child foo:bar="1">
|
||||
<grandchild xmlns:foo="">
|
||||
<great-grandchild bar="2" />
|
||||
</grandchild>
|
||||
</child>
|
||||
<child foo:bar="1">
|
||||
<grandchild xmlns:foo="">
|
||||
<great-grandchild bar="2">
 </great-grandchild>
|
||||
</grandchild>
|
||||
</child>
|
||||
</root>
|
||||
`
|
||||
|
||||
|
@ -159,3 +159,20 @@ func TestString(t *testing.T) {
|
|||
t.Fatalf("expected: %s\ngot: %s\n", expected, got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStringEscaping(t *testing.T) {
|
||||
doc := New()
|
||||
err := doc.LoadFile("test4.xml", nil)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("LoadFile(): %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
expected := `<body> <https://example.com/file/fm/SU0vRk0xLzIwMTMwOTEwLzA1MDA0MS5ybXdhdGVzdEByZXV0ZXJzLmNvbTEzNzg4NDU1OTk4OTA/Screen%20Shot%202013-09-10%20at%2021.33.54.png> File Attachment:-Screen Shot 2013-09-10 at 21.33.54.png </body>
|
||||
`
|
||||
|
||||
if got := doc.Root.String(); got != expected {
|
||||
t.Fatalf("expected: %s\ngot: %s\n", expected, got)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue