示例#1
0
func _TestThrEntryToTestVisitor(t testThrEntry) xmlutils.TestVisitor {
	customError := xmlutils.NewErrorChecker(xmlutils.DisableAllError)

	customError.EnableErrorChecking("in-reply-to", atom.MissingAttribute)
	customError.EnableErrorChecking("in-reply-to", atom.AttributeDuplicated)
	customError.EnableErrorChecking("entry", atom.AttributeDuplicated)
	customError.EnableErrorChecking("link", LinkNotReplies)
	customError.EnableErrorChecking("link", NotInLinkElement)
	customError.EnableErrorChecking(xmlutils.AllError, atom.NotPositiveNumber)

	testVisitor := xmlutils.TestVisitor{
		XML:                t.XML,
		ExpectedError:      nil,
		ExpectedVisitor:    t.ExpectedThrEntry,
		VisitorConstructor: testThrEntryConstructor,
		Validator:          testThrEntryValidator,
		CustomError:        &customError,
	}

	if t.ExpectedError != nil {
		testVisitor.ExpectedError = t.ExpectedError
	}

	return testVisitor
}
示例#2
0
func ExampleParseOptions() {
	// the input feed is not compliant to spec
	f, err := os.Open("testdata/atom.xml")
	if err != nil {
		return
	}

	// the input feed should be 100% compliant to spec...
	flags := xmlutils.NewErrorChecker(xmlutils.EnableAllError)

	//... but it is OK if Atom entry does not have <updated> field
	flags.DisableErrorChecking("entry", atom.MissingDate)

	options := feed.ParseOptions{ExtensionManager: extension.Manager{},
		ErrorFlags: &flags}

	myfeed, err := feed.Parse(f, options)

	if err != nil {
		fmt.Printf("Cannot parse feed:\n%s\n", err)
		return
	}

	fmt.Printf("FEED '%s'\n", myfeed.Title)

	// Output:
	//Cannot parse feed:
	//in 'feed':
	//[MissingId]
	//	feed's id should exist
}
示例#3
0
文件: parse.go 项目: apognu/xml
func init() {
	errorFlags := xmlutils.NewErrorChecker(xmlutils.DisableAllError)
	DefaultOptions = ParseOptions{
		extension.Manager{},
		&errorFlags,
	}
}