Documentation
¶
Overview ¶
Package xmltest provides utilities for XML testing.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Normalizer ¶
type Normalizer struct {
// OmitWhitespace instructs to ignore whitespace between element tags.
OmitWhitespace bool
// OmitComments instructs to ignore XML comments.
OmitComments bool
}
Normalizer normalizes XML.
func (*Normalizer) EqualXML ¶
func (n *Normalizer) EqualXML(a, b io.Reader) (bool, error)
EqualXML tests for equality of the normalized XML contents of a and b.
Example ¶
package main
import (
"fmt"
"strings"
"github.com/rsto/xmltest"
)
func main() {
var n xmltest.Normalizer
s1 := `<root xmlns="space"/>`
s2 := `<s:root xmlns:s="space"></s:root>`
fmt.Println(n.EqualXML(strings.NewReader(s1), strings.NewReader(s2)))
}
Output: true
func (*Normalizer) Normalize ¶
Normalize writes the normalized XML content of r to w. It applies the following rules
- Rename namespace prefixes according to an internal heuristic.
- Remove unnecessary namespace declarations.
- Sort attributes in XML start elements in lexical order of their fully qualified name.
- Remove XML directives and processing instructions.
- Remove CDATA between XML tags that only contains whitespace, if instructed to do so.
- Remove comments, if instructed to do so.
Note that the normalized XML content might differ from canonicalized XML as defined by W3C.
Click to show internal directories.
Click to hide internal directories.