Skip to content

Documentation / @sw-file-lib/xml / xml-schema / SchemaParseOptions

Interface: SchemaParseOptions ​

ts
interface SchemaParseOptions {
  readonly unknownField?: UnknownFieldMode | UnknownFieldCallback;
  readonly allowNaN?: boolean;
  readonly duplicateChildElement?: DuplicateChildElementMode | DuplicateChildElementCallback;
}

Defined in: packages/xml/src/xml-schema/parseOptions.ts:109

Options controlling the behavior of schema parsing when the XML does not exactly match the schema.

Unless otherwise specified, parsing errors are reported rather than silently ignored.

Properties ​

PropertyModifierTypeDescription

unknownField?

readonly

| UnknownFieldMode | UnknownFieldCallback

Determines how attributes and child elements that are not defined by the schema are handled.

A callback can be provided to make the decision based on the location and contents of each unknown field.

Default

ts
"error"

allowNaN?

readonly

boolean

Determines whether a value that cannot be interpreted as a number is allowed to produce NaN when parsing a number schema.

By default, such values cause a parsing error. Set this to true to allow NaN to be returned.

Default

ts
false

Example

ts
const schema = x.object({
  value: x.number(),
});

schema.parse(
  '<root value="not-a-number"/>',
  "root",
  { allowNaN: true },
);
// { value: NaN }

duplicateChildElement?

readonly

| DuplicateChildElementMode | DuplicateChildElementCallback

Determines how duplicate child elements are handled when the schema expects a unique child element.

A callback can be provided to make the decision based on the location of each duplicate child element.

Default

ts
"error"