xmlvalidate

package
v0.0.0-...-bc4a9d8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 5, 2024 License: Apache-2.0 Imports: 7 Imported by: 3

README

xmlvalidate

Validates an XML file against an XSD schema using xmlint.

Requirements

This activity requires the xmllint command be installed on the system where the activity worker is running. This can be installed, in Ubuntu, by entering the following command:

apt-get install libxml2-utils

Registration

The Name constant is used as example, use a different name to register and execute the activity if that doesn't suit your needs. An example registration:

import (
    "go.temporal.io/sdk/activity"
    "go.temporal.io/sdk/worker"

    "github.com/artefactual-sdps/temporal-activities/xmlvalidate"
)

tw := worker.New(...)

tw.RegisterActivityWithOptions(
    xmlvalidate.New().Execute,
    activity.RegisterOptions{Name: xmlvalidate.Name},
)

Execution

An example execution:

import (
    "time"

    "go.temporal.io/sdk/temporal"
    "go.temporal.io/sdk/workflow"

    "github.com/artefactual-sdps/temporal-activities/xmlvalidate"
)

ctx = workflow.WithActivityOptions(ctx, workflow.ActivityOptions{
    ScheduleToCloseTimeout: 5 * time.Minute,
    RetryPolicy: &temporal.RetryPolicy{MaximumAttempts: 1},
})

var re xmlvalidate.Result
err := workflow.ExecuteActivity(
    ctx,
    xmlvalidate.Name,
    &xmlvalidate.Params{
        XMLFilePath: "/path/to/file.xml",
        XSDFilePath: "/path/to/file.xsd",
    },
).Get(ctx, &re)

err may contain any non validation error. re.Failures contains the xmllint validation output as []bytes.

Documentation

Index

Constants

View Source
const Name = "xml-validate"

Variables

This section is empty.

Functions

This section is empty.

Types

type Activity

type Activity struct {
	// contains filtered or unexported fields
}

func New

func New(validator XSDValidator) *Activity

func (*Activity) Execute

func (a *Activity) Execute(ctx context.Context, params *Params) (*Result, error)

Execute checks an XML file using the XSD file provided and returns error output.

type Params

type Params struct {
	// XMLPath is the path of the file to be validated.
	XMLPath string

	// XSDPath is the path of the XSD file to use for validation.
	XSDPath string
}

type Result

type Result struct {
	Failures []string
}

type XMLLintValidator

type XMLLintValidator struct{}

XMLLintValidator represents an XSDValidator implementation using the xmllint C library.

func NewXMLLintValidator

func NewXMLLintValidator() *XMLLintValidator

func (*XMLLintValidator) Validate

func (v *XMLLintValidator) Validate(ctx context.Context, xmlPath, xsdPath string) (string, error)

Validate validates the XML document at xmlPath against the XSD schema at xsdPath using xmllint. If xmllint fails to run due to an error, then an error is returned. If xmllint runs and finds validation errors the errors will be returned as a string and the error return will be nil.

type XSDValidator

type XSDValidator interface {
	Validate(ctx context.Context, xmlPath, xsdPath string) (string, error)
}

An XSDValidator validates the XML document at xmlPath against the XSD schema at xsdPath.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL