Beispiel #1
0
func newXMLParser(filename string) (parser.Interface, error) {
	bytes, err := ioutil.ReadFile(filename)
	if err != nil {
		return nil, fmt.Errorf("err <%v> reading file <%s>", err, filename)
	}
	x := xml.NewXMLParser()
	if err := x.Init(bytes); err != nil {
		return nil, fmt.Errorf("err <%v> parser.Init with bytes from filename <%s>", err, filename)
	}
	return x, nil
}
Beispiel #2
0
func testTranscode(t *testing.T, input interface{}) {
	inputData, err := xml.Marshal(input)
	if err != nil {
		panic(err)
	}
	t.Logf("testing transcoding: %s", string(inputData))
	p := xmlparser.NewXMLParser()
	if err := p.Init(inputData); err != nil {
		t.Fatal(err)
	}
	outputData, err := Encode(p)
	if err != nil {
		t.Fatal(err)
	}
	t.Logf("%s", outputData)
	if !reflect.DeepEqual(inputData, outputData) {
		t.Fatalf("expected equal, but got %s", string(outputData))
	}
}
Beispiel #3
0
func NewXMLParser() xml.XMLParser {
	return xml.NewXMLParser(xml.WithAttrPrefix("attr_"), xml.WithElemPrefix("elem_"), xml.WithTextPrefix("text_"))
}