Skip to content

Non empty string constraint does not work #5

@johanvandeweerd

Description

@johanvandeweerd

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.

Full code example:

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

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions