-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Labels
bugSomething isn't workingSomething isn't working
Description
What happened?
Using the XSD below, the library doesn't report an error when trying to validate the following XML:
<name></name>
Online XML validators (like this one) report an error (cvc-minLength-valid: Value '' with length = '0' is not facet-valid with respect to minLength '3' for type '#AnonType_name'.) as I would expect.
package main
import (
"fmt"
"log"
xmlparser "github.com/moolekkari/validatexml-go"
)
func main() {
xsd := `
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="name">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:schema>
`
schema, err := xmlparser.ParseXSD([]byte(xsd))
if err != nil {
log.Fatal(err)
}
// Your XML document
xmlData := []byte(`<name></name>`)
// Parse and validate
document, err := xmlparser.Parse(xmlData)
if err != nil {
log.Fatal(err)
}
if err := schema.Validate(document); err != nil {
fmt.Printf("Validation failed: %v\n", err)
} else {
fmt.Println("✓ Valid!")
}
}Relevant XSD snippet
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="name">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:schema>Library version
v0.1.1
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working