Skip to content

attributesGroupName writes null and undefined attribute values as text #35

Open

Description

@paulcyr

Summary

Version: 1.3.2
Context: I group attributes so that attribute keys don't need the @_ prefix and can't collide with child element names.

With attributesGroupName set, an attribute whose value is null or undefined is written as the text "null" or "undefined". Without a group name, the same values are left out.

Reproduction

import XMLBuilder from 'fast-xml-builder';

const perKey = new XMLBuilder({ ignoreAttributes: false });
console.log(perKey.build({ item: { '@_a': 'x', '@_b': null, '@_c': undefined } }));
// <item a="x"></item>

const grouped = new XMLBuilder({ ignoreAttributes: false, attributesGroupName: '$' });
console.log(grouped.build({ item: { $: { a: 'x', b: null, c: undefined } } }));
// <item a="x" b="null" c="undefined"></item>

Expected

Both print <item a="x"></item>.

Additional details

When building, the builder skips undefined and null values for individually keyed attributes (src/fxb.js#L170-L183), which came from NaturalIntelligence/fast-xml-parser#598 for NaturalIntelligence/fast-xml-parser#585. The attributesGroupName branch (src/fxb.js#L281-L288) passes every value in the group to buildAttrPairStr without that check. attributeValueProcessor can't drop an attribute, so no option works around it.

Activity

  1. Archanachaurasiya30 commented on Nov 20, 2026

    @Archanachaurasiya30

    Hi! I'd like to work on this issue. I can investigate the attributesGroupName handling in src/fxb.js, fix the null and undefined attribute values, and add regression tests. Is it okay if I work on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions