Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Don't create text node for self closing tags when `alwaysCreateTextNode: true`

Aperta
#708 5 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 4 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
48/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
javascript
Ambito
tooling

Direzione di ricerca

Non è indicato alcun file sorgente o test. Inizia riproducendo entrambi gli esempi di parser.parse con alwaysCreateTextNode abilitato, quindi segui la gestione dei tag autochiudenti dal punto di ingresso parser.parse. Il completamento deve essere confermato da test che coprano i tag autochiudenti con e senza attributi e il comportamento previsto dei nodi di testo.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

enhancement

Currently I can have the parser create a text node on tags without attributes by setting alwaysCreateTextNode: true. However, for self closing tags, I would like the parser to not create a text node. Right now it creates a text node set to an empty string.

I also noticed that if a self closing tags have any attributes, a text node is not created. It only seems like it's created when a self closing tags have no attributes.

// Given these settings:
const parser = new XMLParser({
	ignoreAttributes: false,
	allowBooleanAttributes: true,
	parseTagValue: false,
	alwaysCreateTextNode: true,
});

parser.parse("<workbookPr defaultThemeVersion="153222" />") 
// "workbookPr": {
//   "@_defaultThemeVersion": "153222"
// }

parser.parse("<workbookPr />") 
// "workbookPr": {
//   "#text": ""
// }

I expect that "#text" is always present, no matter if the self closing tag have attributes or not. But my primary expectation is to be able to have no text nodes at all for self closing tags while still allowing the parser to make text nodes for tags without any attributes.

Lingua principale
JavaScript
Stelle
3.1k
Fork
400
Merge medio
3g 9h
PR unite (30g)
1

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di NaturalIntelligence/fast-xml-parser

Tutte le issue di NaturalIntelligence/fast-xml-parser

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.